Generated Python client for the Sema4.ai API
Project description
sema4ai_api_client
A client library for accessing the Sema4.ai API.
Usage
First, create a client:
from sema4ai_api_client import Client
client = Client(base_url="https://api.example.com")
If the endpoints you're going to hit require authentication, use AuthenticatedClient instead:
from sema4ai_api_client import AuthenticatedClient
client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
Now call your endpoint and use your models:
from sema4ai_api_client.models.my_data_model import MyDataModel
from sema4ai_api_client.api.my_tag import get_my_data_model
from sema4ai_api_client.types import Response
with client as client:
my_data: MyDataModel | None = get_my_data_model.sync(client=client)
# or if you need more info (e.g. status_code)
response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
Or do the same thing with an async version:
from sema4ai_api_client.models.my_data_model import MyDataModel
from sema4ai_api_client.api.my_tag import get_my_data_model
from sema4ai_api_client.types import Response
async with client as client:
my_data: MyDataModel | None = await get_my_data_model.asyncio(client=client)
response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
By default, HTTPS calls verify TLS certificates. You can provide a custom certificate bundle:
client = AuthenticatedClient(
base_url="https://internal_api.example.com",
token="SuperSecretToken",
verify_ssl="/path/to/certificate_bundle.pem",
)
You can also disable certificate validation, but this is a security risk:
client = AuthenticatedClient(
base_url="https://internal_api.example.com",
token="SuperSecretToken",
verify_ssl=False,
)
Things to know:
- Every path/method combo becomes a Python module with four functions:
sync: Blocking request that returns parsed data (if successful) orNonesync_detailed: Blocking request that always returns aResponse, withparsedset when successfulasyncio: Likesync, but asyncasyncio_detailed: Likesync_detailed, but async
- All path/query params and request bodies become function arguments.
- If an endpoint has tags, the first tag is used as the API module name.
- Endpoints without tags are available under
sema4ai_api_client.api.default.
Advanced customizations
You can customize the underlying httpx.Client / httpx.AsyncClient with httpx_args:
from sema4ai_api_client import Client
def log_request(request):
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
def log_response(response):
request = response.request
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
client = Client(
base_url="https://api.example.com",
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)
Or set an httpx client directly (this overrides shared settings like base_url unless you set them again):
import httpx
from sema4ai_api_client import Client
client = Client(base_url="https://api.example.com")
client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxy="http://localhost:8030"))
Regenerate client
From the repo root:
make update-api-client
Or manually from packages/api-client:
uvx openapi-python-client generate \
--path "../../workroom/packages/agent-server-interface/public.openapi.json" \
--config "openapi-client-config.yaml" \
--meta none \
--output-path "sema4ai_api_client"
Build
uv build
Install locally into another project:
uv pip install dist/sema4ai_api_client-*.whl
Release
Releases are published to PyPI automatically via GitHub Actions using trusted publishers (OIDC). No API tokens are needed.
Steps
-
Update the version in
pyproject.toml. -
Commit and push the version change to
main. -
Create and push a tag matching the pattern
sema4ai-api-client-<version>:# Or use the invoke task which validates the branch and version: pip install invoke && invoke make-release
Alternatively, tag manually:
git tag -a sema4ai-api-client-3.0.0 -m "Release 3.0.0" git push origin sema4ai-api-client-3.0.0
-
The
api-client-release.ymlworkflow picks up the tag, builds the package, and publishes it to PyPI.
Prerequisites
A trusted publisher must be configured on PyPI for the sema4ai-api-client project:
- Owner:
Sema4AI - Repository:
moonraker - Workflow:
api-client-release.yml - Environment: (leave blank)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sema4ai_api_client-3.0.0.tar.gz.
File metadata
- Download URL: sema4ai_api_client-3.0.0.tar.gz
- Upload date:
- Size: 83.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de32d41a86e6e4a13c5c98fc1cd8409d4e9156346aa524e8b764dd451f0159dc
|
|
| MD5 |
d6109b2d45a2757451475beffe84d847
|
|
| BLAKE2b-256 |
fe6619f34a78b704100f5c1c8a8f99b9f2c791fb6d90010c9fbf239d36585902
|
Provenance
The following attestation bundles were made for sema4ai_api_client-3.0.0.tar.gz:
Publisher:
api-client-release.yml on Sema4AI/moonraker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sema4ai_api_client-3.0.0.tar.gz -
Subject digest:
de32d41a86e6e4a13c5c98fc1cd8409d4e9156346aa524e8b764dd451f0159dc - Sigstore transparency entry: 1203517337
- Sigstore integration time:
-
Permalink:
Sema4AI/moonraker@ce828ddc5f389b0efe8d1dd11e601bd3576f7925 -
Branch / Tag:
refs/tags/sema4ai-api-client-3.0.0 - Owner: https://github.com/Sema4AI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
api-client-release.yml@ce828ddc5f389b0efe8d1dd11e601bd3576f7925 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sema4ai_api_client-3.0.0-py3-none-any.whl.
File metadata
- Download URL: sema4ai_api_client-3.0.0-py3-none-any.whl
- Upload date:
- Size: 243.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b9d847f8e9e93c62cf45543d5909df1ce5161f2eb8e29ad02fb2ab7378800ed
|
|
| MD5 |
3155137651231923cecbeab8235daaa8
|
|
| BLAKE2b-256 |
ebd98927e9ba01964d847e55ff91fdb62e0fe12662111b6e240c9378006d387a
|
Provenance
The following attestation bundles were made for sema4ai_api_client-3.0.0-py3-none-any.whl:
Publisher:
api-client-release.yml on Sema4AI/moonraker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sema4ai_api_client-3.0.0-py3-none-any.whl -
Subject digest:
1b9d847f8e9e93c62cf45543d5909df1ce5161f2eb8e29ad02fb2ab7378800ed - Sigstore transparency entry: 1203517338
- Sigstore integration time:
-
Permalink:
Sema4AI/moonraker@ce828ddc5f389b0efe8d1dd11e601bd3576f7925 -
Branch / Tag:
refs/tags/sema4ai-api-client-3.0.0 - Owner: https://github.com/Sema4AI
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
api-client-release.yml@ce828ddc5f389b0efe8d1dd11e601bd3576f7925 -
Trigger Event:
push
-
Statement type: