# Redact PII with Python

> Call the Redactly redaction API from Python with requests. One function, exact character offsets, no SDK install required.

Canonical: https://bitbanger.in/integrations/python
Last updated: 2026-10-27

There is no SDK to install: the API is a single POST endpoint that returns JSON. The snippet below wraps it in a function you can drop into an ingestion job.

## Code

```
import requests

def redact(text: str, style: str = "replace") -> dict:
    r = requests.post(
        "https://api.bitbanger.in/v1/redact",
        headers={"X-API-Key": "rdct_your_key_here"},
        json={"text": text, "style": style},
        timeout=30,
    )
    r.raise_for_status()
    return r.json()

result = redact("Invoice for Jane Doe, jane.doe@example.com, card 4242 4242 4242 4242")
print(result["redacted"])
for hit in result["entities"]:
    print(hit["entity"], hit["start"], hit["end"])
```

## Notes

- Use httpx if your codebase already depends on it; the request shape is identical.
- Set a timeout. Inference is fast but the first request after a deploy waits for the model to load.
- The response is JSON, so no parsing layer is needed beyond r.json().

## Related

- [API reference](https://bitbanger.in/docs)
- [Playground](https://bitbanger.in/redact)
- [All 40 entity types](https://bitbanger.in/entities/)
