Skip to main content

port-detective Python SDK

A lightweight subprocess client for the port-detective CLI. It provides synchronous and asyncio APIs for port diagnostics, project fingerprinting, and safe cleanup on Windows, macOS, and Linux.

Install

Install the published SDK:

python -m pip install port-detective

From a checkout:

python -m pip install ./python
go build -o port-detective .

The SDK looks for a matching CLI on PATH, in PORT_DETECTIVE_BIN, and in the checkout. If none is available, the first API call downloads the matching release archive from GitHub, verifies its SHA-256 checksum, and caches the binary in the user cache directory. This requires network access only once. Set PORT_DETECTIVE_AUTO_DOWNLOAD=0 for offline or locked-down environments, or set PORT_DETECTIVE_CACHE_DIR to choose the cache location. You can also download it explicitly with from port_detective import download_cli.

The package still requires Python 3.9 or newer. Source checkouts can build the CLI locally with Go, while unsupported platforms must provide a compatible CLI through PORT_DETECTIVE_BIN.

Quickstart

from port_detective import inspect_port, scan_ports, free_port, clean_project

diagnostic = inspect_port(8080)
occupied = scan_ports([3000, 5173, 8080])
preview = free_port(3000, dry_run=True)
project_listeners = clean_project(dry_run=True)

print(diagnostic.status, len(occupied), preview.message, len(project_listeners))

All calls accept an optional timeout in seconds. Process actions default to dry-run; set dry_run=False only after reviewing the target.

Async API

import asyncio
from port_detective import async_inspect_port, async_scan_ports

async def main():
    diagnostic, ports = await asyncio.gather(
        async_inspect_port(3000),
        async_scan_ports(),
    )
    print(diagnostic.status, len(ports))

asyncio.run(main())

Models

PortDiagnostic includes port, is_open, protocol, pid, process_name, cmdline, memory_mb, cpu_percent, status, and optional project metadata. ProjectInfo includes name, framework, path, and version.

See the API reference, platform support policy, and quality review for release constraints.

License

MIT.

Metadata

Release files for port-detective 1.1.1

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-detective 1.1.1
File Size Uploaded Provenance Actions
port_detective-1.1.1.tar.gz 14.5 kB With provenance Details for port_detective-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for port-detective 1.1.1
File Interpreter ABI Platform Actions
port_detective-1.1.1-py3-none-any.whl Python 3 none any Details for port_detective-1.1.1-py3-none-any.whl

Total release size: 25.0 kB

Release files / port_detective-1.1.1.tar.gz

Download URL port_detective-1.1.1.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
de66f4c9a12347021257a068e8e15fde674cb9c4d7f77ecd4a9e59f5f8361590
BLAKE2b-256 checksum
How to use checksums
4650c0dde7c06dbade8f547e68f4bac12673d4e9210cc93508da4f1a418cea85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / port_detective-1.1.1-py3-none-any.whl

Download URL port_detective-1.1.1-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48d00a127207a69bf2dcca7f17a9a30f9c045d4cc1664ad82e13e31b25fb4d24
BLAKE2b-256 checksum
How to use checksums
3b3deae8ef805a09ce1eae167acc088b130933dec22ba06da67f5dc0a810ba81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Security for port-detective 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for port_detective-1.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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