PYTHON SDK
Typed Python SDK
Call every Latentface endpoint from Python with a matched sync + async surface. Ships wheels for CPython 3.9 – 3.13. Exhaustive type stubs for strict mypy.
Install
pip install latentfaceSynchronous client
from latentface import Client
client = Client() # reads LATENTFACE_API_KEY
result = client.swap(
source="./source.jpg",
target="./target.jpg",
)
print(result.output_url)
# → https://cdn.latentface.net/out/abc123.pngThe client reads your API key from LATENTFACE_API_KEY automatically, or pass api_key="lf_..." explicitly.
Async client
import asyncio
from latentface import AsyncClient
async def main():
async with AsyncClient() as client:
vec = await client.embed(image="./face.jpg")
print(len(vec.embedding)) # 512
asyncio.run(main())Built on httpx with automatic connection pooling and retries. Use inside FastAPI, asyncio workers, or any async runtime.
Typed responses
result: SwapResult = client.swap(...)
# ^^^ full IDE autocomplete
print(result.latency_ms) # int
print(result.output_url) # str
print(result.request_id) # str
# Every field is typed — no dict lookups.Error handling & retries
from latentface import Client, RateLimitError, QuotaError
try:
client.swap(source=..., target=...)
except RateLimitError as e:
print(f"Retry after {e.retry_after}s")
except QuotaError:
print("Out of monthly quota — upgrade at /pricing")Default: 3 retries with exponential backoff on 5xx and 429. Override with Client(max_retries=0) for explicit control. See rate limits & errors.
Source on GitHub
Open source, Apache 2.0. Issues and PRs welcome.