• Stars
    star
    439
  • Rank 99,247 (Top 2 %)
  • Language
    Python
  • License
    Academic Free Lic...
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A PyPI mirror client according to PEP 381 http://www.python.org/dev/peps/pep-0381/

Code style: black Actions Status codecov.io Documentation Status Downloads


This is a PyPI mirror client according to PEP 381 + PEP 503 + PEP 691 http://www.python.org/dev/peps/pep-0381/.

  • bandersnatch >=6.0 implements PEP691
  • bandersnatch >=4.0 supports Linux, MacOSX + Windows
  • Documentation

bandersnatch maintainers are looking for more help! Please refer to our MAINTAINER documentation to see the roles and responsibilities. We would also ask you read our Mission Statement to ensure it aligns with your thoughts for this project.

  • If interested contact @cooperlees

Installation

The following instructions will place the bandersnatch executable in a virtualenv under bandersnatch/bin/bandersnatch.

  • bandersnatch requires >= Python 3.8.0

Docker

This will pull latest build. Please use a specific tag if desired.

  • Docker image includes /bandersnatch/src/runner.py to periodically run a bandersnatch mirror
    • Please /bandersnatch/src/runner.py --help for usage
  • With docker, we recommend bind mounting in a read only bandersnatch.conf
    • Defaults to /conf/bandersnatch.conf
docker pull pypa/bandersnatch
docker run pypa/bandersnatch bandersnatch --help

Docker Compose

Bandersnatch setup using docker-compose is available here

pip

This installs the latest stable, released version.

python3 -m venv bandersnatch
bandersnatch/bin/pip install bandersnatch
bandersnatch/bin/bandersnatch --help

Quickstart

  • Run bandersnatch mirror - it will create an empty configuration file for you in /etc/bandersnatch.conf.
  • Review /etc/bandersnatch.conf and adapt to your needs.
  • Run bandersnatch mirror again. It will populate your mirror with the current status of all PyPI packages. Current mirror package size can be seen here: https://pypi.org/stats/
  • A blocklist or allowlist can be created to cut down your mirror size. You might want to Analyze PyPI downloads to determine which packages to add to your list.
  • Run bandersnatch mirror regularly to update your mirror with any intermediate changes.

Webserver

Configure your webserver to serve the web/ sub-directory of the mirror. For PEP691 support we need to respect the format the client requests.

For an nginx example, please look at our banderx docker container and nginx.conf example configuration.

  • Note that it is a good idea to have your webserver publish the HTML index files correctly with UTF-8 as the charset. The index pages will work without it but if humans look at the pages the characters will end up looking funny.

  • Make sure that the webserver uses UTF-8 to look up unicode path names. nginx gets this right by default - not sure about others.

For more information visit out official documentation for instructions on how to use a NGINX example Docker Image.

If you are looking to an docker-compose example head over here

Cron jobs

You need to set up one cron job to run the mirror itself.

Here's a sample that you could place in /etc/cron.d/bandersnatch:

    LC_ALL=en_US.utf8
    */2 * * * * root bandersnatch mirror |& logger -t bandersnatch[mirror]

This assumes that you have a logger utility installed that will convert the output of the commands to syslog entries.

SystemD Timers are also another alternative in today's modern world.

Maintenance

bandersnatch does not keep much local state in addition to the mirrored data. In general you can just keep rerunning bandersnatch mirror to make it fix errors.

If you want to force bandersnatch to check everything against the master PyPI:

  • run bandersnatch mirror --force-check to move status files if they exist in your mirror directory in order get a full sync.

Be aware that full syncs likely take hours depending on PyPI's performance and your network latency and bandwidth.

Other Commands

  • bandersnatch delete --help - Allows you to specify package(s) to be removed from your mirror (dangerous)
  • bandersnatch verify --help - Crawls your repo and fixes any missed files + deletes any unowned files found (dangerous)

Operational notes

Case-sensitive filesystem needed

You need to run bandersnatch on a case-sensitive filesystem.

OS X natively does this OK even though the filesystem is not strictly case-sensitive and bandersnatch will work fine when running on OS X. However, tarring a bandersnatch data directory and moving it to, e.g. Linux with a case-sensitive filesystem will lead to inconsistencies. You can fix those by deleting the status files and have bandersnatch run a full check on your data.

Windows requires elevated prompt

Bandersnatch makes use of symbolic links. On Windows, this permission is turned off by default for non-admin users. In order to run bandersnatch on Windows either call it from an elevated command prompt (i.e. right-click, run-as Administrator) or give yourself symlink permissions in the group policy editor.

Many sub-directories needed

The PyPI has a quite extensive list of packages that we need to maintain in a flat directory. Filesystems with small limits on the number of sub-directories per directory can run into a problem like this:

    2013-07-09 16:11:33,331 ERROR: Error syncing package: zweb@802449
    OSError: [Errno 31] Too many links: '../pypi/web/simple/zweb'

Specifically we recommend to avoid using ext3. Ext4 and newer does not have the limitation of 32k sub-directories.

Client Compatibility

A bandersnatch static mirror is compatible only to the "static", cacheable parts of PyPI that are needed to support package installation. It does not support more dynamic APIs of PyPI that maybe be used by various clients for other purposes.

An example of an unsupported API is PyPI's XML-RPC interface, which is used when running pip search.

Bandersnatch Mission

The bandersnatch project strives to:

  • Mirror all static objects of the Python Package Index (https://pypi.org/)
  • bandersnatch's main goal is to support the main global index to local syncing only
  • This will allow organizations to have lower latency access to PyPI and save bandwidth on their WAN connections and more importantly the PyPI CDN
  • Custom features and requests may be accepted if they can be of a plugin form
    • e.g. refer to the blocklist and allowlist plugins

Contact

If you have questions or comments, please submit a bug report to https://github.com/pypa/bandersnatch/issues/new

Code of Conduct

Everyone interacting in the bandersnatch project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the PSF Code of Conduct.

Kudos

This client is based on the original pep381client by Martin v. Loewis.

Richard Jones was very patient answering questions at PyCon 2013 and made the protocol more reliable by implementing some PyPI enhancements.

Christian Theune for creating and maintaining bandersnatch for many years!

More Repositories

1

pipenv

Python Development Workflow for Humans.
Python
24,785
star
2

pipx

Install and Run Python Applications in Isolated Environments
Python
9,971
star
3

pip

The Python package installer
Python
9,448
star
4

hatch

Modern, extensible Python project management
Python
5,754
star
5

sampleproject

A sample project that exists for PyPUG's "Tutorial on Packaging and Distributing Projects"
Python
5,054
star
6

virtualenv

Virtual Python Environment builder
Python
4,770
star
7

pipfile

Python
3,232
star
8

setuptools

Official project repository for the Setuptools build system
Python
2,413
star
9

flit

Simplified packaging of Python modules
Python
2,143
star
10

cibuildwheel

🎡 Build Python wheels for all the platforms with minimal configuration.
Python
1,796
star
11

twine

Utilities for interacting with PyPI
Python
1,568
star
12

manylinux

Python wheels that work on any linux (almost)
Shell
1,410
star
13

packaging.python.org

Python Packaging User Guide
Python
1,394
star
14

pip-audit

Audits Python environments, requirements files and dependency trees for known security vulnerabilities, and can automatically fix them
Python
951
star
15

gh-action-pypi-publish

The blessed :octocat: GitHub Action, for publishing your 📦 distribution files to PyPI: https://github.com/marketplace/actions/pypi-publish
Python
878
star
16

setuptools_scm

the blessed package to manage your versions by scm tags
Python
839
star
17

get-pip

Helper scripts to install pip, in a Python installation that doesn't have it.
Python
723
star
18

build

A simple, correct Python build frontend
Python
710
star
19

packaging

Core utilities for Python packages
Python
602
star
20

wheel

The official binary distribution format for Python
Python
494
star
21

auditwheel

Auditing and relabeling cross-distribution Linux wheels.
Python
425
star
22

advisory-database

Advisory database for Python packages published on pypi.org
250
star
23

python-manylinux-demo

Demo project for building Python wheels for Linux with Travis-CI
C
222
star
24

sample-namespace-packages

Tests against namespace packages
Python
175
star
25

readme_renderer

Safely render long_description/README files in Warehouse
Python
158
star
26

packaging-problems

An issue tracker for the problems in packaging
143
star
27

trove-classifiers

Canonical source for classifiers on PyPI.
Python
134
star
28

pyproject-hooks

A low-level library for calling build-backends in `pyproject.toml`-based project
Python
120
star
29

installer

A low-level library for installing from a Python wheel distribution.
Python
118
star
30

gh-action-pip-audit

A GitHub Action for pip-audit
Python
66
star
31

scripttest

Utilities to help with testing command line scripts
Python
60
star
32

distlib

A low-level library which implements some Python packaging standards (PEPs) and which could be used by third-party packaging tools to achieve interoperability.
Python
48
star
33

distutils

distutils as found in cpython
Python
44
star
34

.github

Community health files for the Python Packaging Authority
34
star
35

pyproject-metadata

PEP 621 metadata parsing
Python
30
star
36

pypa.io

Source code for the pypa.io website
Python
24
star
37

interoperability-peps

Development repo for evolution of PyPA interoperability standards (released versions are published as PEPs on python.org)
Python
22
star
38

integration-test

ensure core packaging tools work well with each other
17
star
39

pkg_resources

Abandoned extraction of pkg_resources. Official version found at /pypa/setuptools.
Python
16
star
40

get-virtualenv

13
star
41

history

history generates history/changelog files for a project
Python
7
star
42

easy_install

Python
7
star
43

wheel-builders

Companion repo for the [email protected] mailing list
7
star
44

browntruck

Python
6
star
45

pypa-docs-theme

Common base Sphinx theme for PyPA projects
Python
6
star
46

docker-python

5
star
47

copr

Package files for building PyPA packages in copr
4
star
48

pypa-bot

Source code behind @pypa-bot (eventually)
4
star
49

pep470

Python
4
star
50

pip-test-package

Used in pip's test suite
Python
4
star
51

bootstrap

Assets for bootstrap.pypa.io
Dockerfile
4
star
52

pypi-camo

Dockerfile
3
star
53

bot-test

1
star
54

rootbeer

Bootstrapping Python build backends for source-only environments.
1
star