Skip to main content

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:

  1. Every path/method combo becomes a Python module with four functions:
    1. sync: Blocking request that returns parsed data (if successful) or None
    2. sync_detailed: Blocking request that always returns a Response, with parsed set when successful
    3. asyncio: Like sync, but async
    4. asyncio_detailed: Like sync_detailed, but async
  2. All path/query params and request bodies become function arguments.
  3. If an endpoint has tags, the first tag is used as the API module name.
  4. 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

  1. Update the version in pyproject.toml.

  2. Commit and push the version change to main.

  3. 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
    
  4. The api-client-release.yml workflow 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sema4ai_api_client-3.0.0.tar.gz (83.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sema4ai_api_client-3.0.0-py3-none-any.whl (243.9 kB view details)

Uploaded Python 3

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

Hashes for sema4ai_api_client-3.0.0.tar.gz
Algorithm Hash digest
SHA256 de32d41a86e6e4a13c5c98fc1cd8409d4e9156346aa524e8b764dd451f0159dc
MD5 d6109b2d45a2757451475beffe84d847
BLAKE2b-256 fe6619f34a78b704100f5c1c8a8f99b9f2c791fb6d90010c9fbf239d36585902

See more details on using hashes here.

Provenance

The following attestation bundles were made for sema4ai_api_client-3.0.0.tar.gz:

Publisher: api-client-release.yml on Sema4AI/moonraker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sema4ai_api_client-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sema4ai_api_client-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b9d847f8e9e93c62cf45543d5909df1ce5161f2eb8e29ad02fb2ab7378800ed
MD5 3155137651231923cecbeab8235daaa8
BLAKE2b-256 ebd98927e9ba01964d847e55ff91fdb62e0fe12662111b6e240c9378006d387a

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page