devpi-server

6.19.3 · active · verified Thu Apr 16

devpi-server is the backend component of the devpi system, providing a robust and flexible solution for hosting private Python package indexes and acting as an on-demand caching mirror for PyPI. It allows users to manage multiple indexes, upload packages and documentation, and configure index inheritance, making it ideal for enterprise environments and local development workflows. The current version is 6.19.3, with a regular release cadence as seen from recent changelog entries.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically start and stop a `devpi-server` instance using the `devpi-process` library. It sets up a temporary server directory and prints the server's URL. For full user and index management, typically the `devpi-client` command-line tool is used, or a more advanced programmatic interaction with the server's REST API.

import os
import shutil
from pathlib import Path
from devpi_process import Index, IndexServer

# Define a temporary directory for the server data
server_dir = Path("./devpi_temp_server_data")

# Ensure the directory is clean for a fresh start
if server_dir.exists():
    shutil.rmtree(server_dir)
server_dir.mkdir()

print(f"Starting devpi-server with data directory: {server_dir}")
with IndexServer(server_dir) as server:
    # The server starts with a 'root' user and a 'root/pypi' index by default.
    # 'root/pypi' proxies to the public PyPI.
    print(f"devpi-server running at: {server.url}")

    # Programmatically create a new user and an index
    print("Creating user 'myuser' and index 'dev'...")
    user_name = "myuser"
    index_name = "dev"
    # Note: devpi_process handles user/index creation via its API, typically abstracting client commands.
    # In a real scenario, you might interact via devpi-client or its programmatic equivalent
    # For simplicity, we'll demonstrate a basic server startup and assume external client interaction.

    # Example of how you might interact with the server after it's up
    # (This part would typically use devpi-client commands externally or a more complete devpi_process API)
    print("You can now interact with the server using devpi-client or pip:")
    print(f"  - Web interface: {server.url}")
    print(f"  - Pip index URL: {server.url}/root/pypi/+simple/")
    print("Run 'devpi quickstart' in another terminal for client setup examples.")

    # To keep the server running for a brief moment for demonstration
    # In a real application, the 'with' block would manage its lifecycle.
    print("Server will run for 10 seconds. Press Ctrl+C to stop sooner.")
    import time
    try:
        time.sleep(10)
    except KeyboardInterrupt:
        print("Stopping server.")

print("devpi-server stopped.")
if server_dir.exists():
    shutil.rmtree(server_dir)
    print(f"Cleaned up data directory: {server_dir}")

view raw JSON →