Skip to main content

Reserve and manage localhost ports; atomically update .env and config.json

Project description

PortKeeper

Reserve and manage localhost hosts/ports for starting servers. Transparently updates .env and config.json files and keeps a local registry so multiple processes and users can coordinate port reservations.

Features

  • Reserve a free port (optionally with preferred port or a search range)
  • Optionally hold the port by binding a dummy socket (prevents others from taking it)
  • Release reservation
  • Atomic updates to .env and config.json (with backup)
  • Simple file locking to avoid races
  • Context manager API and a tiny CLI (portkeeper)

Quickstart

pip install portkeeper

# Reserve preferred 8888 or a port in 8888-8988, hold it, and print JSON
portkeeper reserve --preferred 8888 --range 8888 8988 --hold --owner myapp

# From Python
from portkeeper import PortRegistry
with PortRegistry().reserve(preferred=8888, port_range=(8888, 8988), hold=True) as r:
    PortRegistry().write_env({'PORT': str(r.port)})

CLI

  • reserve [--preferred P] [--range START END] [--hold] [--owner OWNER] [--write-env KEY]
  • release PORT
  • status (list reserved ports in registry)
  • gc (garbage-collect stale registry entries)

License

MIT

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

portkeeper-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

portkeeper-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file portkeeper-0.1.0.tar.gz.

File metadata

  • Download URL: portkeeper-0.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for portkeeper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 21032c9c2ce933985c36efc87c25cd71997050b11db6bbd3adf32149329ffa7d
MD5 d4bdd689be6ee97e22142fa981cad210
BLAKE2b-256 d11048a98b3fa218bf13850d7192b830779a228611b5790bc377c58e9fa2eb6b

See more details on using hashes here.

File details

Details for the file portkeeper-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: portkeeper-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for portkeeper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8dc715f0e3d76d458adec59bf6b327f73f2f5ee6713e3bbef291248248b15af4
MD5 d13682b40dd96be27e45de9316e957f2
BLAKE2b-256 308bda0a9f8b2f8c72b466e50b49b2b1b5d1534ece247ed3e3e133e32e3fffad

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