Sign inSign up

pypiserver/pypiserver

By pypiserver

Updated about 22 hours ago

Minimal PyPI server for uploading & downloading packages with pip/easy_install

Image
60

10M+

pypiserver/pypiserver repository overview

pypi server logo

pypiserver - minimal PyPI server for use with pip/easy_install

PyPi project badge Python Versions CI workflow Licenses Stable Docker Tag

Tip

Reach out in [**Discussions**](https://github.com/pypiserver/pypiserver/discussions), or chat with us on [**Zulip**](https://pypiserver.zulipchat.com)

pypiserver is a minimal PyPI compatible server for pip or easy_install. It is based on bottle and serves packages from regular directories. Wheels, bdists, eggs and accompanying PGP-signatures can be uploaded either with pip, setuptools, twine, pypi-uploader, or simply copied with scp.

Note

The official software powering [PyPI](https://pypi.org/) is [Warehouse](https://github.com/pypa/warehouse/). However, [Warehouse](https://github.com/pypa/warehouse/) is fairly specialized to be **pypi.org**'s own software, and should not be used in other contexts. In particular, it does not officially support being used as a custom package index by users wishing to serve their own packages.

pypiserver implements the same interfaces as PyPI, allowing standard Python packaging tooling such as pip and twine to interact with it as a package index just as they would with PyPI, while making it much easier to get a running index server.

pypiserver

Table of Contents

Quickstart Installation and Usage

Important

**pypiserver** works with Python 3.10+ and PyPy3.

Warning

Older Python versions may still work, but they are not tested.

For legacy Python versions, use pypiserver-1.x series.
Note that these are not officially supported, and will not receive bugfixes or new features.

Tip

The commands below work on a unix-like operating system with a posix shell.
The '~' character expands to user's home directory.

If you're using Windows, you'll have to use their "Windows counterparts".
The same is true for the rest of this documentation.

  1. Install pypiserver with this command

    pip install pypiserver                # Or: pypiserver[passlib,cache]
    mkdir ~/packages                      # Copy packages into this directory.
    

    Tip

    See also [Alternative Installation methods](#alternative-installation-methods)
  2. Copy some packages into your ~/packages folder and then get your pypiserver up and running

    pypi-server run -p 8080 ~/packages &      # Will listen to all IPs.
    
  3. From the client computer, type this

    # Download and install hosted packages.
    pip install --extra-index-url http://localhost:8080/simple/ ...
    
    # or
    pip install --extra-index-url http://localhost:8080 ...
    
    # Search hosted packages.
    pip search --index http://localhost:8080 ...
    
    # Note that pip search does not currently work with the /simple/ endpoint.
    

    Tip

    See also [Client-side configurations](#client-side-configurations) for avoiding tedious typing.
  4. Enter pypi-server -h in the cmd-line to print a detailed usage message

    usage: pypi-server [-h] [-v] [--log-file FILE] [--log-stream STREAM]
                       [--log-frmt FORMAT] [--hash-algo HASH_ALGO]
                       [--backend {auto,simple-dir,cached-dir}] [--version]
                       {run,update} ...
    
    start PyPI compatible package server serving packages from PACKAGES_DIRECTORY. If PACKAGES_DIRECTORY is not given on the command line, it uses the default ~/packages. pypiserver scans this directory recursively for packages. It skips packages and directories starting with a dot. Multiple package directories may be specified.
    
    positional arguments:
      {run,update}
        run                 Run pypiserver, serving packages from
                            PACKAGES_DIRECTORY
        update              Handle updates of packages managed by pypiserver. By
                            default, a pip command to update the packages is
                            printed to stdout for introspection or pipelining. See
                            the `-x` option for updating packages directly.
    
    options:
      -h, --help            show this help message and exit
      -v, --verbose         Enable verbose logging; repeat for more verbosity.
      --log-file FILE       Write logging info into this FILE, as well as to
                            stdout or stderr, if configured.
      --log-stream STREAM   Log messages to the specified STREAM. Valid values are
                            stdout, stderr, and none
      --log-frmt FORMAT     The logging format-string.  (see `logging.LogRecord`
                            class from standard python library)
      --hash-algo HASH_ALGO
                            Any `hashlib` available algorithm to use for
                            generating fragments on package links. Can be disabled
                            with one of (0, no, off, false).
      --backend {auto,simple-dir,cached-dir}
                            A backend implementation. Keep the default 'auto' to
                            automatically determine whether to activate caching or
                            not
      --version             show program's version number and exit
    
    Visit https://github.com/pypiserver/pypiserver for more information
    
More details about pypi server run

Enter pypi-server run -h in the cmd-line to print a detailed usage

usage: pypi-server run [-h] [-v] [--log-file FILE] [--log-stream STREAM]
                       [--log-frmt FORMAT] [--hash-algo HASH_ALGO]
                       [--backend {auto,simple-dir,cached-dir}] [--version]
                       [-p PORT] [-i HOST] [-a AUTHENTICATE]
                       [-P PASSWORD_FILE] [--disable-fallback]
                       [--fallback-url FALLBACK_URL]
                       [--health-endpoint HEALTH_ENDPOINT] [--server METHOD]
                       [-o] [--welcome HTML_FILE] [--cache-control AGE]
                       [--log-req-frmt FORMAT] [--log-res-frmt FORMAT]
                       [--log-err-frmt FORMAT]
                       [--server-base-url SERVER_BASE_URL]
                       [package_directory ...]

positional arguments:
  package_directory     The directory from which to serve packages.

options:
  -h, --help            show this help message and exit
  -v, --verbose         Enable verbose logging; repeat for more verbosity.
  --log-file FILE       Write logging info into this FILE, as well as to
                        stdout or stderr, if configured.
  --log-stream STREAM   Log messages to the specified STREAM. Valid values are
                        stdout, stderr, and none
  --log-frmt FORMAT     The logging format-string.  (see `logging.LogRecord`
                        class from standard python library)
  --hash-algo HASH_ALGO
                        Any `hashlib` available algorithm to use for
                        generating fragments on package links. Can be disabled
                        with one of (0, no, off, false).
  --backend {auto,simple-dir,cached-dir}
                        A backend implementation. Keep the default 'auto' to
                        automatically determine whether to activate caching or
                        not
  --version             show program's version number and exit
  -p PORT, --port PORT  Listen on port PORT (default: 8080)
  -i HOST, -H HOST, --interface HOST, --host HOST
                        Listen on interface INTERFACE (default: 0.0.0.0)
  -a AUTHENTICATE, --authenticate AUTHENTICATE
                        Comma-separated list of (case-insensitive) actions to
                        authenticate (options: download, list, update;
                        default: update).
                         
                         Any actions not specified are not authenticated, so
                         to authenticate downloads and updates, but allow
                         unauthenticated viewing of the package list, you would
                         use:
                         
                          pypi-server -a 'download, update' -P
                          ./my_passwords.htaccess
                         
                        To disable authentication, use:
                         
                          pypi-server -a . -P .
                         
                        See the `-P` option for configuring users and
                        passwords.
                         
                        Note that when uploads are not protected, the
                        `register` command is not necessary, but `~/.pypirc`
                        still needs username and password fields, even if
                        bogus.
  -P PASSWORD_FILE, --passwords PASSWORD_FILE
                        Use an apache htpasswd file PASSWORD_FILE to set
                        usernames and passwords for authentication.
                         
                        To allow unauthorized access, use:
                         
                          pypi-server -a . -P .
                         
  --disable-fallback    Disable the default redirect to PyPI for packages not
                        found in the local index.
  --fallback-url FALLBACK_URL
                        Redirect to FALLBACK_URL for packages not found in the
                        local index.
  --health-endpoint HEALTH_ENDPOINT
                        Configure a custom liveness endpoint. It always
                        returns 200 Ok if the service is up. Otherwise, it
                        means that the service is not responsive.
  --server METHOD       Use METHOD to run the server. Valid values include
                        paste, cherrypy, twisted, gunicorn, gevent, wsgiref,
                        and auto. The default is to use "auto", which chooses
                        one of paste, cherrypy, twisted, or wsgiref.
  -o, --overwrite       Allow overwriting existing package files during
                        upload.
  --welcome HTML_FILE   Use the contents of HTML_FILE as a custom welcome
                        message on the home page.
  --cache-control AGE   Add "Cache-Control: max-age=AGE" header to package
                        downloads. Pip 6+ requires this for caching. AGE is
                        specified in seconds.
  --log-req-frmt FORMAT
                        A format-string selecting Http-Request properties to
                        log; set to '%s' to see them all.
  --log-res-frmt FORMAT
                        A format-string selecting Http-Response properties to
                        log; set to '%s' to see them all.
  --log-err-frmt FORMAT
                        A format-string selecting Http-Error properties to
                        log; set to '%s' to see them all.
  --server-base-url SERVER_BASE_URL
                        Serve all routes under SERVER_BASE_URL prefix
                        (default: {DEFAULTS.SERVER_BASE_URL})
More details about pypi-server update

More details about pypi-server update

usage: pypi-server update [-h] [-v] [--log-file FILE] [--log-stream STREAM]
                          [--log-frmt FORMAT] [--hash-algo HASH_ALGO]
                          [--backend {auto,simple-dir,cached-dir}] [--version]
                          [-x] [-d DOWNLOAD_DIRECTORY] [-u]
                          [--blacklist-file IGNORELIST_FILE]
                          [package_directory ...]

positional arguments:
  package_directory     The directory from which to serve packages.

options:
  -h, --help            show this help message and exit
  -v, --verbose         Enable verbose logging; repeat for more verbosity.
  --log-file FILE       Write logging info into this FILE, as well as to
                        stdout or stderr, if configured.
  --log-stream STREAM   Log messages to the specified STREAM. Valid values are
                        stdout, stderr, and none
  --log-frmt FORMAT     The logging format-string. (see `logging.LogRecord`
                        class from standard python library)
  --hash-algo HASH_ALGO
                        Any `hashlib` available algorithm to use for
                        generating fragments on package links. Can be disabled
                        with one of (0, no, off, false).
  --backend {auto,simple-dir,cached-dir}
                        A backend implementation. Keep the default 'auto' to
                        automatically determine whether to activate caching or
                        not
  --version             show program's version number and exit
  -x, --execute         Execute the pip commands rather than printing to
                        stdout
  -d DOWNLOAD_DIRECTORY, --download-directory DOWNLOAD_DIRECTORY
                        Specify a directory where packages updates will be
                        downloaded. The default behavior is to use the
                        directory which contains the package being updated.
  -u, --allow-unstable  Allow updating to unstable versions (alpha, beta, rc,
                        dev, etc.)
  --blacklist-file IGNORELIST_FILE, --ignorelist-file IGNORELIST_FILE
                        Don't update packages listed in this file (one package
                        name per line, without versions, '#' comments
                        honored). This can be useful if you upload private
                        packages into pypiserver, but also keep a mirror of
                        public packages that you regularly update. Attempting
                        to pull an update of a private package from `pypi.org`
                        might pose a security risk - e.g. a malicious user
                        might publish a higher version of the private package,
                        containing arbitrary code.

Client-Side Configurations

Always specifying the pypi url on the command line is a bit cumbersome.

Tip

Since **pypiserver** redirects **pip/easy_install** to the **pypi.org** index if it doesn't have a requested package, it is a good idea to configure them to always use your local pypi index.
Configuring pip

For pip command this can be done by setting the environment variable PIP_EXTRA_INDEX_URL in your .bashr/.profile/.zshrc

export PIP_EXTRA_INDEX_URL=http://localhost:8080/simple/

or by adding the following lines to ~/.pip/pip.conf

[global]
extra-index-url = http://localhost:8080/simple/

Note

If you have installed pypiserver on a remote url without https you will receive an "untrusted" warning from pip, urging you to append the --trusted-host option. You can also include this option permanently in your configuration-files or environment variables.

Configuring easy_install

For easy_install command you may set the following configuration in ~/.pydistutils.cfg

[easy_install]
index_url = http://localhost:8080/simple/
Uploading Packages Remotely

Instead of copying packages directly to the server's folder (i.e. with scp), you may use python tools for the task, e.g. python setup.py upload.
In that case, pypiserver is responsible for authenticating the upload-requests.

Important

We strongly advise to password-protect your uploads!

It is possible to disable authentication for uploads (e.g. in intranets). To avoid lazy security decisions, read help for -P and -a options.

Apache Like Authentication (htpasswd)
  1. First make sure you have the passlib module installed (note that passlib>=1.6 is required), which is needed for parsing the Apache htpasswd file specified by the -P, --passwords option (see next steps)

    pip install passlib
    
  2. Create the Apache htpasswd file with at least one user/password pair with this command (you'll be prompted for a password)

    htpasswd -sc htpasswd.txt <some_username>
    

Tip

Read this SO question for running htpasswd cmd under Windows or if you have bogus passwords that you don't care because they are for an internal service (which is still "bad", from a security perspective...) you may use this public service

Tip

When accessing pypiserver via the api, alternate authentication methods are available via the auther config flag. Any callable returning a boolean can be passed through to the pypiserver config in order to provide custom authentication. For example, to configure pypiserver to authenticate using the python-pam

import pam
pypiserver.default_config(auther=pam.authenticate)

Please see Using Ad-hoc authentication providers for more information.

  1. You need to restart the server with the -P option only once (but user/password pairs can later be added or updated on the fly)

    ./pypi-server run -p 8080 -P htpasswd.txt ~/packages &
    
Upload with setuptools
  1. On client-side, edit or create a ~/.pypirc file with a similar content:

    [distutils]
    index-servers =
      pypi
      local
    
    [pypi]
    username:<your_pypi_username>
    password:<your_pypi_passwd>
    
    [local]
    repository: http://localhost:8080
    username: <some_username>
    password: <some_passwd>
    
  2. Then from within the directory of the python-project you wish to upload, issue this command:

    python setup.py sdist upload -r local
    
Upload with twine

To avoid storing you passwords on disk, in clear text, you may either:

  • use the register setuptools's command with the -r option, like that

    python setu
    

Tag summary

Content type

Image

Digest

sha256:6c4874820

Size

31.7 MB

Last updated

about 22 hours ago

docker pull pypiserver/pypiserver