sfwapi
Official Python client for the SFW API: NSFW and nudity detection for images, GIFs and videos. Provides both synchronous (SfwApi) and asynchronous (AsyncSfwApi) clients built on httpx, with Python 3.9+ type annotations.
Media is processed in memory and never stored. Every account includes 500 free credits a month, with no card required.
Install
pip install sfwapi
Get an API key at sfwapi.dev/console and store it in SFWAPI_API_KEY.
Quick start
import os
from sfwapi import SfwApi, SfwApiError
with SfwApi(api_key=os.environ["SFWAPI_API_KEY"]) as api:
# Analyse media at a public URL with a blocking policy
r = api.analyze_url(
"https://example.com/photo.jpg",
policy={"block_level": 2, "block_sex_objects": True, "art": "same_as_photos"},
)
print(r["nudity"]["level"]) # 0 | 1 | 2 | 3
print(r["nudity"]["scores"]) # {"revealing": ..., "implied_nudity": ..., "explicit": ...}
print(r["policy"]["blocked"]) # True | False
print(r["usage"]["balance"]) # credits remaining
# Upload a local image, GIF or video
g = api.analyze_file("clip.gif", max_frames=5, include_frames=True)
Async client
AsyncSfwApi exposes the same methods with await and works with FastAPI, Starlette and asyncio services:
import os
from sfwapi import AsyncSfwApi
async with AsyncSfwApi(api_key=os.environ["SFWAPI_API_KEY"]) as api:
r = await api.analyze_bytes(upload_bytes, policy={"block_level": 2})
if r["policy"]["blocked"]:
...
Content levels
Each score runs from 0 to 100 and counts above 50 (CUTOFF). nudity.level is the highest level that counts.
| Level | Name | Meaning |
|---|---|---|
0 |
Everyday | Normal photos, clothed people, landscapes, objects |
1 |
Revealing | Swimwear, lingerie, cleavage and other revealing clothing |
2 |
Implied nudity | Partial or covered nudity, suggestive poses without exposed genitalia |
3 |
Explicit | Exposed genitalia or explicit sexual acts |
Responses also include flags.art (drawings, anime, paintings, stylised 3D) and flags.sex_object (adult toys and objects). Policy options (art: same_as_photos, allow, block_from_1, block_from_2, block_from_3) let you handle illustrated content separately from photos.
Methods
| Method | Description |
|---|---|
analyze_url(url, ...) |
Analyse an image, GIF or video at a public http(s) URL |
analyze_bytes(data, ...) |
Upload raw bytes or bytearray as multipart |
analyze_file(path, ...) |
Read and upload a local file by path |
me() |
Account tier, rate limits and credit balance |
usage() |
Current month's request, credit and byte totals |
Analysis methods accept max_frames (1 to 32), include_frames and policy. A request costs 1 credit per image, or 1 per analysed frame for a GIF or video.
Errors and retries
Non-2xx responses raise SfwApiError with .status, .type, .code, .message, .request_id and .doc_url. Statuses 429, 503 and 504 are retried twice honouring Retry-After (uploads are not retried; pass max_retries=0 to disable). Failed requests are never charged.
Links
- Python SDK reference: sfwapi.dev/docs/sdks/python
- Content levels: sfwapi.dev/docs/levels
- Interactive playground: api.sfwapi.dev/playground
- OpenAPI reference: api.sfwapi.dev/reference
- Pricing: sfwapi.dev/pricing
- Other clients: TypeScript (
@sfwapi/sdk), .NET (SfwApi), MCP server (@sfwapi/mcp)
Metadata
Release files for sfwapi 0.1.1
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 |
|---|---|---|---|---|
| sfwapi-0.1.1.tar.gz | 6.3 kB | With provenance | Details for sfwapi-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sfwapi-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for sfwapi-0.1.1-py3-none-any.whl |
Total release size: 12.3 kB
Release files / sfwapi-0.1.1.tar.gz
| Download URL | sfwapi-0.1.1.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ee0a30eb701f6af8b1406b3fc123952de9175c01dc35df7ae9502fb39906431
|
|
BLAKE2b-256 checksum How to use checksums |
c95355439f16ef27cd2b1c301f1de8f391fb2c9f046a7345708f28473b7d96a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 28, 2026.
Transparency logRelease files / sfwapi-0.1.1-py3-none-any.whl
| Download URL | sfwapi-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e027696f95411e22916a5a4a5fef84c3edaa5c15514b6d06b8bbd1d253bd1f87
|
|
BLAKE2b-256 checksum How to use checksums |
09cefd436592cb36d3573ed112cc7a050fd4da9df086aeb0c1f168f231a9887e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 28, 2026.
Transparency logSecurity for sfwapi 0.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.
Attestation for sfwapi-0.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 Nov 28, 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.