Metadata-Version: 2.4
Name: port-detective
Version: 1.1.0
Summary: Lightweight Python SDK for port-detective: inspect ports, detect framework fingerprints, and clean project-scoped listeners.
Author: port-detective Maintainers
License-Expression: MIT
Project-URL: Homepage, https://github.com/EquityQ/port-detective
Project-URL: Repository, https://github.com/EquityQ/port-detective
Project-URL: Documentation, https://github.com/EquityQ/port-detective/tree/main/python
Keywords: networking,ports,developer-tools,process,framework-detection,mcp
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: System :: Networking
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"

# 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

After a release:

```bash
python -m pip install port-detective
```

From a checkout:

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

The package does not bundle the Go executable. Put a matching CLI on `PATH`, set
`PORT_DETECTIVE_BIN`, or pass `binary_path` to an API call. Keep SDK and CLI versions
aligned because the SDK consumes the CLI JSON contract.

## Quickstart

```python
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

```python
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](../docs/project/API_REFERENCE.md), [platform support policy](../docs/operations/PLATFORM_SUPPORT.md),
and [quality review](../docs/project/QUALITY_REVIEW.md) for release constraints.

## License

MIT.
