maskflare
Official Python SDK for Maskflare - mask sensitive data before it reaches an AI model, unmask it when you get a result back.
Built on httpx, its only runtime dependency.
Install
pip install maskflare
Quickstart
Generate a Redaction-purpose API key from your Maskflare dashboard (Configure → API keys → Create key → Purpose: Redaction) and you're ready to go:
import os
from maskflare import MaskFlare
client = MaskFlare(
api_key=os.environ["MASKFLARE_API_KEY"],
# base_url defaults to https://api.maskflare.com - point it at your own deployment
# (e.g. http://localhost:8000 for local development) until that's live.
)
result = client.mask("Contact ada@example.com for details")
# result.output: "Contact mf_mask_170b8521c1b944b3beb9ca02b328efbe for details"
# result.tokens: [MaskedToken(token="170b8521c1b944b3beb9ca02b328efbe", rule_key="email")]
# ... send result.output to your LLM, store it, log it - the real value never leaves your key's reach ...
original = client.unmask([t.token for t in result.tokens])
# original: {"170b8521c1b944b3beb9ca02b328efbe": "ada@example.com"}
MaskFlare also works as a context manager, which releases its connection pool on exit:
with MaskFlare(api_key=os.environ["MASKFLARE_API_KEY"]) as client:
result = client.mask("Contact ada@example.com for details")
A Redaction key can only mask/unmask - it's rejected if used against Maskflare's AI-gateway forwarding routes, so a leaked SDK key can never be used to spend your AI-provider budget. Masking rules (what counts as sensitive, and whether request/response text is checked) are configured per environment on the dashboard's Rules page - the SDK just applies whatever your key's environment has configured.
Tokens resolve back to their original value for 30 days from creation, then expire.
API
MaskFlare(api_key, *, base_url=..., timeout=..., max_retries=..., http_client=...)
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str |
required | A Redaction-purpose API key. |
base_url |
str |
https://api.maskflare.com |
Override for a self-hosted deployment or local development. |
timeout |
float |
10.0 |
Per-request timeout, in seconds. |
max_retries |
int |
2 |
Automatic retries on 429/5xx, honoring Retry-After. 0 disables. |
http_client |
httpx.Client |
a new, internally-owned one | Bring your own httpx.Client (e.g. to share a connection pool or add custom transport/proxy settings). When supplied, MaskFlare never closes it for you. |
client.mask(input: str) -> MaskResult
@dataclass(frozen=True)
class MaskResult:
output: str # input, with each match replaced by an opaque token
tokens: tuple[MaskedToken, ...]
@dataclass(frozen=True)
class MaskedToken:
token: str
rule_key: str
client.unmask(tokens: Sequence[str]) -> dict[str, str]
Returns a map of token → original value, for every token that was found and belonged to the
calling key. A token you don't own, or one that's expired, is simply omitted - check
token in result for the ones you need.
Errors
MaskFlareError- the API rejected the request. Has.status,.code,.detail, and (for a429).retry_after_seconds.MaskFlareConnectionError- the request never reached the API (network failure or timeout).- A plain
TypeErrorfor invalid input caught client-side before any request is made (e.g. an empty string tomask).
from maskflare import MaskFlare, MaskFlareError
try:
client.mask(user_input)
except MaskFlareError as error:
if error.code == "rate_limited":
... # back off - or just let the SDK's built-in retry handle it (see max_retries)
raise
Development
uv sync
uv run pytest # tests
uv run ruff check . # lint
uv run pyright # typecheck
License
MIT
Metadata
Release files for maskflare 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| maskflare-0.1.0.tar.gz | 21.3 kB | With provenance | Details for maskflare-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| maskflare-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for maskflare-0.1.0-py3-none-any.whl |
Total release size: 29.0 kB
Release files / maskflare-0.1.0.tar.gz
| Download URL | maskflare-0.1.0.tar.gz |
|---|---|
| Size | 21.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4f0b1b927f0c6c0c498a84ab073044674d60bf8b91acc0e32331320e2e7f519
|
|
BLAKE2b-256 checksum How to use checksums |
34544e550dc2368ccaf977cdc9404448287d39245eab2d9cb9d03f596ba35524
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / maskflare-0.1.0-py3-none-any.whl
| Download URL | maskflare-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51d4ee5da6555c426f6a41ea4b326eea5cf2040ad139a55a120e23294e36052c
|
|
BLAKE2b-256 checksum How to use checksums |
12cdc4f3969deaa1d095931b231b2f9e42ec49762f418b07862297bf97aa90e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logSecurity for maskflare 0.1.0
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.
Attestation for maskflare-0.1.0.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 Sep 22, 2026.
Transparency logA 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.