Skip to main content

Local PyPI Server with caching and upload support

Project description

PyPihub - Local PyPI Server

PyPihub is a simple local PyPI server with caching and package upload capabilities. This server allows you to host your Python packages locally, cache packages from the official PyPI, and supports package uploads via twine.

Key Features

  • Local Package Hosting: Host your own Python packages locally
  • PyPI Caching: Automatic caching of packages from official PyPI for faster access
  • Twine Support: Upload packages using twine with authentication
  • Web Interface: Simple web interface for browsing packages
  • Flexible Configuration: Configuration via INI files, environment variables, or command arguments

Installation

Requirements

pip install flask beautifulsoup4 requests pydebugger configset rich rich-argparse pathlib

Download and Setup

git clone <repository-url>
cd pypihub

or you can install with pip:

$ pip install pypihub[flask]

Configuration

1. Configuration File (pypihub.ini)

Create a pypihub.ini as an alternative config file or it will be created automatically in the same directory as pypihub.py:

[dirs]
base = /path/to/base/directory
local_pkg = /path/to/local/packages
cache = /path/to/cache

[urls]
pypi_simple = https://pypi.org/simple

[server]
host = 0.0.0.0
port = 5000

[auths]
users = pypihub,pypihub;user2,pass2

2. Settings File (settings.py)

Alternatively, create a settings.py file (see example below):

BASE_DIR = "/path/to/base"
LOCAL_PKG_DIR = "/path/to/packages"
CACHE_DIR = "/path/to/cache"
PYPI_SIMPLE_URL = "https://pypi.org/simple"
HOST = "0.0.0.0"
PORT = 5000
AUTHS = [("pypihub", "pypihub"), ("user2", "pass2")]
CONFIGFILE = "pypihub.ini"

3. Environment Variables

export BASE_DIR="/path/to/base"
export LOCAL_PKG_DIR="/path/to/packages"
export CACHE_DIR="/path/to/cache"
export PYPI_SIMPLE_URL="https://pypi.org/simple"
export HOST="0.0.0.0"
export PORT="5000"
export CONFIGFILE="pypihub.ini"

Usage

Running the Server

# Using default settings
python pypihub.py

# With custom configuration
# Option: '-c /path/to/config.ini'
python pypihub.py -c /path/to/config.ini -H 127.0.0.1 -P 8080

# Verbose mode
python pypihub.py -v

# Show help
python pypihub.py -h

Command Line Arguments

-c, --config          Path to configuration file
-b, --base-dir        Base directory for server
-l, --local-pkg-dir   Directory for local packages
-C, --cache-dir       Directory for cached packages
-p, --pypi-simple-url PyPI simple index URL
-H, --host            Host to run server on
-P, --port            Port to run server on
-V, --version         Show PyPihub version
-v, --verbose         Enable verbose output

Package Upload

Using Twine

  1. Configure ~/.pypirc:
[distutils]
index-servers = pypihub

[pypihub]
repository = http://localhost:5000/
username = pypihub
password = pypihub
  1. Upload package:
# Build package first
python setup.py sdist bdist_wheel

# Upload to pypihub
twine upload --repository pypihub dist/*

Manual Upload via HTTP

curl -X POST \
  -u pypihub:pypihub \
  -F "file=@package-1.0.0-py3-none-any.whl" \
  http://localhost:5000/upload/package-name/

Installing Packages from PyPihub

Configure pip

Add to ~/.pip/pip.conf (Linux/Mac) or %APPDATA%\pip\pip.ini (Windows):

[global]
extra-index-url = http://localhost:5000/simple/
trusted-host = localhost

Install Package

# Install from pypihub (with fallback to PyPI)
pip install package-name

# Install only from pypihub
pip install --index-url http://localhost:5000/simple/ package-name

# Install with extra index
pip install --extra-index-url http://localhost:5000/simple/ package-name

API Endpoints

Web Interface

  • GET / - Main page with list of local packages

Package Management

  • POST /upload/<package>/ - Upload package (with auth)
  • POST /upload/ - Upload package via twine (with auth)
  • GET /packages/<package>/<filename> - Serve local package files
  • GET /cache/<package>/<filename> - Serve cached package files

Package Index

  • GET /simple/<package>/ - Simple index for specific package

Directory Structure

pypihub/
├── pypihub.py              # Main application
├── pypihub.ini             # Configuration file (optional)
├── settings.py           # Settings file (optional)
├── packages/             # Local packages directory
│   └── package-name/
│       ├── package-1.0.0.tar.gz
│       └── package-1.0.0-py3-none-any.whl
├── cache/                # Cached packages from PyPI
│   └── requests/
│       └── requests-2.28.1-py3-none-any.whl
└── logs/                 # Log files (if configured)

Authentication

Default credentials:

  • Username: pypihub
  • Password: pypihub

Change the default credentials before using in production.

To change credentials, edit configuration in settings.py, pypihub.ini, or environment variables.

Logging

PyPihub uses custom logging with levels:

  • EMERGENCY
  • CRITICAL
  • ERROR
  • WARNING
  • NOTICE
  • INFO
  • DEBUG

Set verbose mode with -v for debug logging.

Troubleshooting

Package not found

  • Ensure package exists in local directory or is available on PyPI
  • Check PYPI_SIMPLE_URL configuration

Upload failed

  • Check authentication credentials
  • Ensure LOCAL_PKG_DIR directory is writable
  • Check if file already exists (409 error)

Cache not working

  • Ensure CACHE_DIR directory is writable
  • Check internet connection for downloading from PyPI

Port already in use

  • Change port with -P parameter or configuration
  • Check processes using port: lsof -i :5000

Development

Dependencies

  • Flask - Web framework
  • BeautifulSoup4 - HTML parsing
  • Requests - HTTP client
  • Rich - Console output formatting
  • ConfigSet - Configuration management
  • PyDebugger - Debug utilities

Contributing

  1. Fork repository
  2. Create feature branch
  3. Commit changes
  4. Push to branch
  5. Create Pull Request
  6. Describe your changes in the Pull Request.

License

PyPihub is released under the GNU Lesser General Public License v3.0 (LGPL-3.0).

You should have received a copy of the GNU Lesser General Public License along with this program.
If not, see https://www.gnu.org/licenses/.

For commercial licensing options, please contact: cumulus13@gmail.com

Support

For issues and questions, please create/open an issue in the repository or contact cumulus13@gmail.com.


PyPihub - Simplifying local Python package management Warning: Do not expose this server to the public internet without proper authentication and security measures.

author

Hadi Cahyadi

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypihub-0.16.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypihub-0.16-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file pypihub-0.16.tar.gz.

File metadata

  • Download URL: pypihub-0.16.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pypihub-0.16.tar.gz
Algorithm Hash digest
SHA256 e9eb05341cbf6acc2f2e702c6dcde724bef11ae764eabe9585c4e7cf71b6206c
MD5 6b0c3be4e11ce30a66af70b7dbf4122a
BLAKE2b-256 528d3f6d34a1fb1882b6d8376955f08831b5c392e1fff8fb0c007c3f66436069

See more details on using hashes here.

File details

Details for the file pypihub-0.16-py3-none-any.whl.

File metadata

  • Download URL: pypihub-0.16-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pypihub-0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 29876ee0da5d3d385d7fbe5d64e2d17dae0f49e881714af89ad4e30ac27a9c3f
MD5 0e7a819da5699f30109d5e64237bef7e
BLAKE2b-256 565f1c29d696fd6a503106ac1baf0925ecf0e1972bf12e197189e3ddd1bc3888

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page