Sdks
Python SDK
The sfwapi package, sync and async, on httpx.
pip install sfwapifrom sfwapi import SfwApi, SfwApiError
api = SfwApi(api_key=os.environ["SFWAPI_KEY"])
try:
r = api.analyze_url("https://example.com/photo.jpg", policy={"block_level": 2})
print(r["nudity"]["level"], r["policy"]["blocked"])
except SfwApiError as e:
print(e.status, e.code, e.message, e.request_id)
with open("clip.gif", "rb") as f:
g = api.analyze_bytes(f.read(), max_frames=5, include_frames=True)AsyncSfwApi has the same methods with await. Methods: analyze_url, analyze_bytes, analyze_file, me, usage. 429/503/504 are retried twice honouring Retry-After (not uploads).