port-for
Utility that helps with local TCP ports management. It can find an unused TCP localhost port and remember the association.
Decision gist · record as of 2026-08-14
Yes. port-for solves a real problem—persistent, safe port allocation—with no dependencies, active maintenance, MIT licensing, and no known vulnerabilities. It is well-suited for development stacks, testing frameworks, and deployment automation. The only caveat is that the command-line tool requires sudo to create new associations, which may limit its use in restricted environments.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- The command-line tool requires read/write access to /etc/port-for.conf; regular users can read but sudo is needed to create new port associations.
- Low install friction with no runtime dependencies.
- Actively maintained with recent commits and support for current Python versions (3.10 through 3.14).
License · maintenance · safety
permissive license (permissive) — MIT license permits unrestricted use, modification, and distribution with minimal restrictions—suitable for most commercial and open-source projects.
last release 2025-09-30 (318 days) · last repo commit 2026-08-14 · 32 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 7,385,441 downloads/mo, #1,746 on PyPI
Alternatives
Verify before relying
pip install port-for
import port_for
port = port_for.select_random()
print(port) # e.g., 37774
# Or use the command-line tool:
# $ port-for myservice
# 37987- Whether the IANA unassigned ports list is kept current and how often it is updated.
- Behavior and reliability of port selection across different operating systems beyond POSIX and Windows.
- How port-for handles concurrent requests for port allocation in high-concurrency scenarios.
What it is and what it does
port-for is a command-line utility and Python library that selects and persists unused TCP localhost ports. Unlike socket.bind((host, 0)), which returns temporary OS-assigned ports, port-for finds ports that are less likely to be claimed by the operating system or other services, making it suitable for durable service configurations across restarts.
The library applies several heuristics: it verifies ports are unused by attempting to connect and bind, excludes IANA-assigned and well-known ports, avoids ephemeral port ranges (which the OS may reclaim), and prefers ports from larger ranges away from well-known services. It can store port-to-name associations in a configuration file, allowing subsequent calls to return the same port for a given service name.
Use it for
- Allocate persistent ports for multiple services in a local development stack without manual port assignment.
- Ensure service restarts use the same port by querying the stored association via the command-line tool.
- Programmatically select safe ports in test suites or deployment scripts that need to avoid OS-assigned ephemeral ranges.
- Configure multi-tenant or multi-site setups on a single server by naming ports with conventions (e.g., 'example.com/apache').
- Build port management into installation scripts that need to find available ports without manual intervention.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
port-for solves a real problem—persistent, safe port allocation—with no dependencies, active maintenance, MIT licensing, and no known vulnerabilities. It is well-suited for development stacks, testing frameworks, and deployment automation. The only caveat is that the command-line tool requires sudo to create new associations, which may limit its use in restricted environments.
Install
port-for on PyPI
Before you install
Low install friction with no runtime dependencies. Actively maintained with recent commits and support for current Python versions (3.10 through 3.14).
The command-line tool requires read/write access to /etc/port-for.conf; regular users can read but sudo is needed to create new port associations.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal restrictions—suitable for most commercial and open-source projects.
Quickstart
pip install port-for
import port_for
port = port_for.select_random()
print(port) # e.g., 37774
# Or use the command-line tool:
# $ port-for myservice
# 37987
Verify before relying
- Whether the IANA unassigned ports list is kept current and how often it is updated.
- Behavior and reliability of port selection across different operating systems beyond POSIX and Windows.
- How port-for handles concurrent requests for port allocation in high-concurrency scenarios.
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 318 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 7,385,441 / month, #1,746 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Internet :: WWW/HTTP :: Site ManagementTopic :: System :: Installation/SetupTopic :: System :: Systems Administration |
Evidence: port_for-1.0.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “find unused tcp port”
- port-forport-for finds and remembers unused TCP localhost ports, useful for…
- portendPortend monitors TCP ports to check whether they are bound (occupied)…
- portpickerFinds and returns an unused network port on the local host, available…
Give your agent the search over MCP, or paste the wish link into any chat.
More Systems Administration packages
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
Reads key-value pairs from a .env file and sets them as environment variables, supporting variable expansion and multiple configuration patterns for 12-factor applications.
Install it if your application reads configuration from environment variables.
psutil retrieves real-time information about running processes and system resources (CPU, memory, disks, network, sensors) across multiple operating systems, enabling system monitoring, process profiling, and resource management.
Invoke is a Python library for defining and running shell commands and executable Python code as CLI-invokable tasks, with subprocess management and task organization.
Install it if you need to organize shell commands and Python code into CLI tasks without the overhead of larger frameworks or shell scripting.
Formats and parses numbers, file sizes, timespans, and other values into human-readable text; provides terminal interaction utilities including ANSI text styling and user prompts.
Validates fully-qualified domain names (FQDNs) against RFC 1123 standards, checking whether a string would be acceptable as a public Internet hostname, with configurable relaxations for short names or underscores.
See also ephemeral-port-reserve · portpicker · portend · python3-nmap · pyModbusTCP · pmd-pytcp · netaddr · ipwhois · isc-dhcp-leases · agent-framework-redis