Skip to main content

Port Allocator (port-alloc / port-status)

Universal Dynamic Port Allocator and Service Registry for Multi-Product & Multi-Agent Workspaces.


🚀 Overview

When building multiple microservices, Next.js applications, FastAPI backends, and AI agent orchestrators on the same machine, hardcoding port numbers leads to constant EADDRINUSE port collision errors.

Port Allocator provides a unified global registry across all projects:

  1. Dynamic Port Discovery & Reservation: Checks if preferred ports (e.g. 3000, 8000) are free. If occupied, it automatically reserves and leases the next available open port.
  2. Automatic Stale PID Harvesting: Whenever a service terminates or crashes, its port lease is immediately reclaimed.
  3. Cross-Language Support: Standalone CLI (Python 3 standard library with zero third-party dependencies) + TypeScript/Node.js client bindings.
  4. Shared State: Atomic persistent registry stored at ~/.local/share/port-registry/ports.json.

📦 Installation

To install globally into ~/.local/bin:

bash tools/port-allocator/install.sh

Or install in editable Python mode:

pip install -e tools/port-allocator

🛠 CLI Usage

1. Allocate a Port

# Allocate preferred port 3000, or next free port
PORT=$(port-alloc allocate --service my-app --preferred 3000)

# Allocate within a specific port range
PORT=$(port-alloc allocate --service worker --preferred 8000 --range 8000-8050)

2. View Active Port Dashboard

port-status
# or
port-alloc list

Output:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🌐 GLOBAL PORT REGISTRY DASHBOARD
📁 Registry File: ~/.local/share/port-registry/ports.json
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
SERVICE                PORT     PID      STATUS       URL
───────────────────────────────────────────────────────────────────────────
kubes-web              3000     10801    🟢 Active     http://127.0.0.1:3000
kubes-agent-core       8000     10802    🟢 Active     http://127.0.0.1:8000
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

3. Query Service Info

port-alloc get kubes-web --field port
port-alloc get kubes-web --field url
port-alloc get kubes-web --field all

4. Release a Port

port-alloc release my-app

5. Check If Port is Free

port-alloc check 3000

💻 TypeScript / Node.js SDK

import { allocatePort, getService, releasePort } from "./tools/port-allocator/ts/client";

// Allocate dynamic port
const port = allocatePort({
  service: "my-node-service",
  preferred: 3000,
});

console.log(`Starting service on port ${port}`);

// Query service info
const info = getService("my-node-service");

// Release port on shutdown
process.on("SIGTERM", () => {
  releasePort("my-node-service");
});

🐍 Python SDK

import port_alloc

port = port_alloc.allocate_port("my-fastapi-service", preferred=8000)
print(f"Allocated port: {port}")

services = port_alloc.list_services()
port_alloc.release_port("my-fastapi-service")

🧪 Testing

# Run Python tests
cd tools/port-allocator && uv run --with pytest pytest tests/

# Run TypeScript tests
node --experimental-strip-types --test tools/port-allocator/tests/test_ts_client.test.ts

Metadata

Release files for port-allocator 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for port-allocator 0.1.0
File Size Uploaded
port_allocator-0.1.0.tar.gz 40.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for port-allocator 0.1.0
File Interpreter ABI Platform
port_allocator-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.9 kB

Release files / port_allocator-0.1.0.tar.gz

Download URL port_allocator-0.1.0.tar.gz
Size 40.6 kB
Tags Source
SHA-256 checksum
How to use checksums
77f4ef3f8444d24822231026cc9b583b8cc43bfe7afe6a1b894e106fc5a047f4
BLAKE2b-256 checksum
How to use checksums
c49bbd98861ed5de361bf8cc445fb6898b24da78ccd30ecc6701ddba09a69a45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.8

Release files / port_allocator-0.1.0-py3-none-any.whl

Download URL port_allocator-0.1.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4dda502e86668751cf465bf6825d49023961ae77aa330a0f7927883b51d9666a
BLAKE2b-256 checksum
How to use checksums
b16c4607d73c844eca7c59146720a2e7d182c13c919ee11db206930e725b2aaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page