# Python and TypeScript SDKs

Two small clients for the REST API that `spiderfootplus serve` exposes, so you
can drive scans from your own code: start a scan, follow it live, wait for it,
and read the grade, findings and events.

| | Python | TypeScript |
| --- | --- | --- |
| Folder | [`sdks/python`](https://github.com/osintambition/spiderfootplus/blob/main/sdks/python) | [`sdks/typescript`](https://github.com/osintambition/spiderfootplus/blob/main/sdks/typescript) |
| Package | `spiderfootplus-client` | `spiderfootplus-client` |
| Runtime | Python 3.9+, standard library only | Node 18+, Bun or Deno; no dependencies |

Neither is on PyPI or npm yet; install from a checkout of the repository:

```sh
pip install ./sdks/python

cd sdks/typescript && npm install && npm run build
npm install /path/to/spiderfootplus/sdks/typescript   # in your project
```

## Connecting

Start the server; it prints an API token:

```sh
spiderfootplus serve                 # http://127.0.0.1:5001
```

Both clients read `SPIDERFOOTPLUS_URL` (default `http://127.0.0.1:5001`) and
`SPIDERFOOTPLUS_API_TOKEN`, or take them as arguments. For a server run with
`--no-auth`, leave the token unset.

## Example

```python
from spiderfootplus_client import Client

sfp = Client()
scan = sfp.start_scan("example.com", use_case="passive")
for event in sfp.stream(scan["id"]):
    print(event["event_type"], event["data"])
sfp.wait(scan["id"])
print(sfp.grade(scan["id"]))
```

```ts
import { Client } from "spiderfootplus-client";

const sfp = new Client();
const scan = await sfp.startScan({ target: "example.com", use_case: "passive" });
for await (const event of sfp.stream(scan.id)) console.log(event.event_type, event.data);
await sfp.wait(scan.id);
console.log(await sfp.grade(scan.id));
```

## What they cover

Every route in the [OpenAPI document](https://github.com/osintambition/spiderfootplus/blob/main/crates/spiderfootplus-api/static/openapi.yaml)
has a method, with the same names in both (snake_case in Python, camelCase in
TypeScript): scans and their control, events, findings, grade, diff, export,
logs, API keys, monitors, data-source health and Cloud push. On top of that:

- `wait` blocks until a scan is finished, aborted or failed;
- `iter_events` / `iterEvents` pages through every event of a scan;
- `stream` yields events live while a scan runs; if the client falls behind,
  it reads the missed ones back from the stored events, so each comes once.

Errors come back as `ApiError` with the HTTP status and the server's message.

## Keeping them in step

`python sdks/check_routes.py` fails if a route in `openapi.yaml` has no method
in either SDK, and CI runs it with both test suites. When you add or change a
route, update both SDKs in the same change.
