proxpi


Nameproxpi JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/EpicWink/proxpi
SummaryPyPI caching mirror
upload_time2023-05-25 14:48:54
maintainer
docs_urlNone
authorLaurie O
requires_python~=3.6
licenseMIT
keywords pypi index mirror cache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # proxpi
[![Build status](
https://github.com/EpicWink/proxpi/workflows/test/badge.svg?branch=master)](
https://github.com/EpicWink/proxpi/actions?query=branch%3Amaster+workflow%3Atest)
[![codecov](https://codecov.io/gh/EpicWink/proxpi/branch/master/graph/badge.svg)](
https://codecov.io/gh/EpicWink/proxpi)

PyPI caching mirror

* Host a proxy PyPI mirror server with caching
  * Cache the index (project list and projects' file list)
  * Cache the project files
* Support multiple indices
* Set index cache times-to-live (individually for each index)
* Set files cache max-size on disk
* Manually invalidate index cache

## Installation
If not using Docker
```bash
pip install proxpi
```

Install `coloredlogs` as well to get coloured logging

## Usage
### Start server
#### Docker
Uses a [Gunicorn](https://gunicorn.org/) WSGI server
```bash
docker run -p 5000:5000 epicwink/proxpi
```

Without arguments, runs with 2 threads. If passing arguments, make sure to bind to an
exported address (or all with `0.0.0.0`) on port 5000 (ie `--bind 0.0.0.0:5000`).

##### Compose
Alternatively, use [Docker Compose](https://docs.docker.com/compose/)
```bash
docker compose up
```

#### Local
```bash
FLASK_APP=proxpi.server flask run
```

See `flask run --help` for more information on address and port binding, and certificate
specification to use HTTPS. Alternatively, bring your own WSGI server.

### Use proxy
Use PIP's index-URL flag to install packages via the proxy

```bash
pip install --index-url http://127.0.0.1:5000/index/ simplejson
```

### Cache invalidation
Either head to http://127.0.0.1:5000/ in the browser, or run:
```bash
curl -X DELETE http://127.0.0.1:5000/cache/simplejson
curl -X DELETE http://127.0.0.1:5000/cache/list
```

If you need to invalidate a locally cached file, restart the server: files should never
change in a package index.

### Environment variables
* `PROXPI_INDEX_URL`: index URL, default: https://pypi.org/simple/
* `PROXPI_INDEX_TTL`: index cache time-to-live in seconds,
   default: 30 minutes. Disable index-cache by setting this to 0
* `PROXPI_EXTRA_INDEX_URLS`: extra index URLs (comma-separated)
* `PROXPI_EXTRA_INDEX_TTLS`: corresponding extra index cache times-to-live in seconds
   (comma-separated), default: 3 minutes, cache disabled when 0
* `PROXPI_CACHE_SIZE`: size of downloaded project files cache (bytes), default 5GB.
  Disable files-cache by setting this to 0
* `PROXPI_CACHE_DIR`: downloaded project files cache directory path, default: a new
  temporary directory
* `PROXPI_BINARY_FILE_MIME_TYPE=1`: force file-response content-type to
  `"application/octet-stream"` instead of letting Flask guess it. This may be needed
  if your package installer (eg Poetry) mishandles responses with declared encoding.

### Considerations with CI
`proxpi` was designed with three goals (particularly for continuous integration (CI)):
* to reduce load on PyPI package serving
* to reduce `pip install` times
* not require modification to the current workflow

Specifically, `proxpi` was designed to run for CI services such as
[Travis](https://travis-ci.org/),
[Jenkins](https://jenkins.io/),
[GitLab CI](https://docs.gitlab.com/ee/ci/),
[Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/)
and [GitHub Actions](https://github.com/features/actions).

`proxpi` works by caching index requests (ie which versions, wheel-types, etc are
available for a given project, the index cache) and the project files themselves (to a
local directory, the package cache). This means they will cache identical requests after
the first request, and will be useless for just one `pip install`.

#### Cache persistence
As a basic end-user of these services, for at least most of these services you won't be
able to keep a `proxpi` server running between multiple invocations of your project(s)
CI pipeline: CI invocations are designed to be independent. This means the best that you
can do is start the cache for just the current job.

A more advanced user of these CI services can bring their own runner (personally, my
needs are for running GitLab CI). This means you can run `proxpi` on a fully-controlled
server (eg [EC2](https://aws.amazon.com/ec2/) instance), and proxy PyPI requests (during
a `pip` command) through the local cache. See the instructions
[below](#gitlab-ci-instructions).

Hopefully, in the future these CI services will all implement their own transparent
caching for PyPI. For example, Azure already has
[Azure Artifacts](https://azure.microsoft.com/en-au/services/devops/artifacts/) which
provides much more functionality than `proxpi`, but won't reduce `pip install` times for
CI services not using Azure.

#### GitLab CI instructions
This implementation leverages the index URL configurable of `pip` and Docker networks.
This is to be run on a server you have console access to.

1. Create a Docker bridge network
   ```shell
   docker network create gitlab-runner-network
   ```

1. Start a GitLab CI Docker runner using
   [their documentation](https://docs.gitlab.com/runner/install/docker.html)

2. Run the `proxpi` Docker container
   ```bash
   docker run \
     --detach \
     --network gitlab-runner-network \
     --volume proxpi-cache:/var/cache/proxpi \
     --env PROXPI_CACHE_DIR=/var/cache/proxpi \
     --name proxpi epicwink/proxpi:latest
   ```
   You don't need to expose a port (the `-p` flag) as we'll be using an internal
   Docker network.

4. Set `pip`'s index URL to the `proxpi` server by setting it in the runner environment.
   Set `runners[0].docker.network_mode` to `gitlab-runner-network`.
   Add `PIP_INDEX_URL=http://proxpi:5000/index/` and `PIP_TRUSTED_HOST=proxpi`
   to `runners.environment` in the GitLab CI runner configuration TOML. For example, you
   may end up with the following configuration:
   ```toml
   [[runners]]
     name = "awesome-ci-01"
     url = "https://gitlab.com/"
     token = "SECRET"
     executor = "docker"
     environment = [
       "DOCKER_TLS_CERTDIR=/certs",
       "PIP_INDEX_URL=http://proxpi:5000/index/",
       "PIP_TRUSTED_HOST=proxpi",
     ]
   
   [[runners.docker]]
     network_mode = "gitlab-runner-network"
     ...
   ```

This is designed to not require any changes to the GitLab CI project configuration (ie
`gitlab-ci.yml`), unless it already sets the index URL for some reason (if that's the
case, you're probably already using a cache).

Another option is to set up a proxy, but that's more effort than the above method.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/EpicWink/proxpi",
    "name": "proxpi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "~=3.6",
    "maintainer_email": "",
    "keywords": "pypi,index,mirror,cache",
    "author": "Laurie O",
    "author_email": "laurie_opperman@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e4/94/133452e69bed41df0877a222b07ed28dff3373e3f5a60e99ddce31793ae4/proxpi-1.1.0.tar.gz",
    "platform": null,
    "description": "# proxpi\n[![Build status](\nhttps://github.com/EpicWink/proxpi/workflows/test/badge.svg?branch=master)](\nhttps://github.com/EpicWink/proxpi/actions?query=branch%3Amaster+workflow%3Atest)\n[![codecov](https://codecov.io/gh/EpicWink/proxpi/branch/master/graph/badge.svg)](\nhttps://codecov.io/gh/EpicWink/proxpi)\n\nPyPI caching mirror\n\n* Host a proxy PyPI mirror server with caching\n  * Cache the index (project list and projects' file list)\n  * Cache the project files\n* Support multiple indices\n* Set index cache times-to-live (individually for each index)\n* Set files cache max-size on disk\n* Manually invalidate index cache\n\n## Installation\nIf not using Docker\n```bash\npip install proxpi\n```\n\nInstall `coloredlogs` as well to get coloured logging\n\n## Usage\n### Start server\n#### Docker\nUses a [Gunicorn](https://gunicorn.org/) WSGI server\n```bash\ndocker run -p 5000:5000 epicwink/proxpi\n```\n\nWithout arguments, runs with 2 threads. If passing arguments, make sure to bind to an\nexported address (or all with `0.0.0.0`) on port 5000 (ie `--bind 0.0.0.0:5000`).\n\n##### Compose\nAlternatively, use [Docker Compose](https://docs.docker.com/compose/)\n```bash\ndocker compose up\n```\n\n#### Local\n```bash\nFLASK_APP=proxpi.server flask run\n```\n\nSee `flask run --help` for more information on address and port binding, and certificate\nspecification to use HTTPS. Alternatively, bring your own WSGI server.\n\n### Use proxy\nUse PIP's index-URL flag to install packages via the proxy\n\n```bash\npip install --index-url http://127.0.0.1:5000/index/ simplejson\n```\n\n### Cache invalidation\nEither head to http://127.0.0.1:5000/ in the browser, or run:\n```bash\ncurl -X DELETE http://127.0.0.1:5000/cache/simplejson\ncurl -X DELETE http://127.0.0.1:5000/cache/list\n```\n\nIf you need to invalidate a locally cached file, restart the server: files should never\nchange in a package index.\n\n### Environment variables\n* `PROXPI_INDEX_URL`: index URL, default: https://pypi.org/simple/\n* `PROXPI_INDEX_TTL`: index cache time-to-live in seconds,\n   default: 30 minutes. Disable index-cache by setting this to 0\n* `PROXPI_EXTRA_INDEX_URLS`: extra index URLs (comma-separated)\n* `PROXPI_EXTRA_INDEX_TTLS`: corresponding extra index cache times-to-live in seconds\n   (comma-separated), default: 3 minutes, cache disabled when 0\n* `PROXPI_CACHE_SIZE`: size of downloaded project files cache (bytes), default 5GB.\n  Disable files-cache by setting this to 0\n* `PROXPI_CACHE_DIR`: downloaded project files cache directory path, default: a new\n  temporary directory\n* `PROXPI_BINARY_FILE_MIME_TYPE=1`: force file-response content-type to\n  `\"application/octet-stream\"` instead of letting Flask guess it. This may be needed\n  if your package installer (eg Poetry) mishandles responses with declared encoding.\n\n### Considerations with CI\n`proxpi` was designed with three goals (particularly for continuous integration (CI)):\n* to reduce load on PyPI package serving\n* to reduce `pip install` times\n* not require modification to the current workflow\n\nSpecifically, `proxpi` was designed to run for CI services such as\n[Travis](https://travis-ci.org/),\n[Jenkins](https://jenkins.io/),\n[GitLab CI](https://docs.gitlab.com/ee/ci/),\n[Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/)\nand [GitHub Actions](https://github.com/features/actions).\n\n`proxpi` works by caching index requests (ie which versions, wheel-types, etc are\navailable for a given project, the index cache) and the project files themselves (to a\nlocal directory, the package cache). This means they will cache identical requests after\nthe first request, and will be useless for just one `pip install`.\n\n#### Cache persistence\nAs a basic end-user of these services, for at least most of these services you won't be\nable to keep a `proxpi` server running between multiple invocations of your project(s)\nCI pipeline: CI invocations are designed to be independent. This means the best that you\ncan do is start the cache for just the current job.\n\nA more advanced user of these CI services can bring their own runner (personally, my\nneeds are for running GitLab CI). This means you can run `proxpi` on a fully-controlled\nserver (eg [EC2](https://aws.amazon.com/ec2/) instance), and proxy PyPI requests (during\na `pip` command) through the local cache. See the instructions\n[below](#gitlab-ci-instructions).\n\nHopefully, in the future these CI services will all implement their own transparent\ncaching for PyPI. For example, Azure already has\n[Azure Artifacts](https://azure.microsoft.com/en-au/services/devops/artifacts/) which\nprovides much more functionality than `proxpi`, but won't reduce `pip install` times for\nCI services not using Azure.\n\n#### GitLab CI instructions\nThis implementation leverages the index URL configurable of `pip` and Docker networks.\nThis is to be run on a server you have console access to.\n\n1. Create a Docker bridge network\n   ```shell\n   docker network create gitlab-runner-network\n   ```\n\n1. Start a GitLab CI Docker runner using\n   [their documentation](https://docs.gitlab.com/runner/install/docker.html)\n\n2. Run the `proxpi` Docker container\n   ```bash\n   docker run \\\n     --detach \\\n     --network gitlab-runner-network \\\n     --volume proxpi-cache:/var/cache/proxpi \\\n     --env PROXPI_CACHE_DIR=/var/cache/proxpi \\\n     --name proxpi epicwink/proxpi:latest\n   ```\n   You don't need to expose a port (the `-p` flag) as we'll be using an internal\n   Docker network.\n\n4. Set `pip`'s index URL to the `proxpi` server by setting it in the runner environment.\n   Set `runners[0].docker.network_mode` to `gitlab-runner-network`.\n   Add `PIP_INDEX_URL=http://proxpi:5000/index/` and `PIP_TRUSTED_HOST=proxpi`\n   to `runners.environment` in the GitLab CI runner configuration TOML. For example, you\n   may end up with the following configuration:\n   ```toml\n   [[runners]]\n     name = \"awesome-ci-01\"\n     url = \"https://gitlab.com/\"\n     token = \"SECRET\"\n     executor = \"docker\"\n     environment = [\n       \"DOCKER_TLS_CERTDIR=/certs\",\n       \"PIP_INDEX_URL=http://proxpi:5000/index/\",\n       \"PIP_TRUSTED_HOST=proxpi\",\n     ]\n   \n   [[runners.docker]]\n     network_mode = \"gitlab-runner-network\"\n     ...\n   ```\n\nThis is designed to not require any changes to the GitLab CI project configuration (ie\n`gitlab-ci.yml`), unless it already sets the index URL for some reason (if that's the\ncase, you're probably already using a cache).\n\nAnother option is to set up a proxy, but that's more effort than the above method.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PyPI caching mirror",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/EpicWink/proxpi"
    },
    "split_keywords": [
        "pypi",
        "index",
        "mirror",
        "cache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "073ae77c3fa426d9748782258aef32e99a421a8f6262db94bd15ecc8f4d7ab8e",
                "md5": "96a629211dae743d5427c075c0d71f13",
                "sha256": "15ac7fe0882ced0a97e28bbb410f44c339cb0070a71684a551d9f08bcdd7a0b3"
            },
            "downloads": -1,
            "filename": "proxpi-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "96a629211dae743d5427c075c0d71f13",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "~=3.6",
            "size": 15900,
            "upload_time": "2023-05-25T14:48:52",
            "upload_time_iso_8601": "2023-05-25T14:48:52.552020Z",
            "url": "https://files.pythonhosted.org/packages/07/3a/e77c3fa426d9748782258aef32e99a421a8f6262db94bd15ecc8f4d7ab8e/proxpi-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e494133452e69bed41df0877a222b07ed28dff3373e3f5a60e99ddce31793ae4",
                "md5": "bf2a5354e3ae3061ef0af82e8dc2d5ac",
                "sha256": "82e6dd197c1fb6716c8c8674a496d112261d299c3ec86a3e564d62b293609e1a"
            },
            "downloads": -1,
            "filename": "proxpi-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bf2a5354e3ae3061ef0af82e8dc2d5ac",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "~=3.6",
            "size": 34604,
            "upload_time": "2023-05-25T14:48:54",
            "upload_time_iso_8601": "2023-05-25T14:48:54.727030Z",
            "url": "https://files.pythonhosted.org/packages/e4/94/133452e69bed41df0877a222b07ed28dff3373e3f5a60e99ddce31793ae4/proxpi-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-25 14:48:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "EpicWink",
    "github_project": "proxpi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "proxpi"
}
        
Elapsed time: 0.25935s