Python SDK for the sference batch API
Project description
sference Python SDK
Installable package: sference-sdk (import: sference_sdk). Used by the sference CLI and your own automation.
Install
uv add sference-sdk
Fallback:
pip install sference-sdk
From a clone of this repo:
uv sync --package sference-sdk
Usage
Set SFERENCE_API_KEY, or pass api_key= to the client.
./workload.jsonl
Batch APIs take a JSONL file: one JSON object per line. OpenAI-compatible lines include custom_id, method, url, and body; content-only lines are {"content": "..."} (then pass model= on submit).
Example workload.jsonl:
{"custom_id":"example-1","method":"POST","url":"/v1/chat/completions","body":{"model":"Qwen/Qwen3.6-35B-A3B","messages":[{"role":"user","content":"Say hello in exactly one word."}]}}
{"custom_id":"example-2","method":"POST","url":"/v1/chat/completions","body":{"model":"Qwen/Qwen3.6-35B-A3B","messages":[{"role":"system","content":"You reply with one short sentence only."},{"role":"user","content":"What is 2+2?"}]}}
Batches (sync)
Best for a fixed JSONL workload: one submit, poll until terminal, then fetch structured results or download JSONL via the API.
from sference_sdk import SferenceClient
client = SferenceClient(api_key="sk_...")
batch = client.submit_batch(
input_file="./workload.jsonl",
model="Qwen/Qwen3.6-35B-A3B",
window="24h",
)
done = client.wait_for_completion(batch.id, poll_interval=2.0, timeout=3600.0)
results = client.get_results(done.id)
print(results.status, results.output_url)
Use a model supported by your sference deployment.
OpenAI-compatible responses (sync)
Standalone or stream-associated jobs via POST /v1/responses. Keys need responses:read and responses:write (default on newly issued keys).
from sference_sdk import SferenceClient
client = SferenceClient(api_key="sk_...")
created = client.create_response(
model="Qwen/Qwen3.6-35B-A3B",
input=[{"role": "user", "content": "Hello"}],
metadata={"completion_window": "24h"},
)
row = client.get_response(created.id)
For a stream, add stream_id inside metadata next to completion_window.
OpenAI Python SDK (openai package)
If you already use the official OpenAI client, point it at sference’s /v1 endpoint and the same API key (with responses:read and responses:write).
pip install openai
import asyncio
import os
from openai import AsyncOpenAI
async def main() -> None:
client = AsyncOpenAI(
base_url="https://api.sference.com/v1",
api_key=os.environ["SFERENCE_API_KEY"],
)
response = await client.responses.create(
model="Qwen/Qwen3.6-35B-A3B",
input=[{"role": "user", "content": "Hello, world!"}],
background=True,
)
# Poll GET /v1/responses/{id} until terminal; your openai version may expose
# something like await client.responses.retrieve(response.id), or use
# AsyncSferenceClient.get_response(response.id) with the same API key.
asyncio.run(main())
Metadata: to set completion_window or stream_id like the native SDK, pass them in the request body your openai version supports (for example metadata= on create, or extra_body={"metadata": {...}} if the helper does not list those fields yet).
Async client — batches
AsyncSferenceClient uses httpx.AsyncClient so batch polling can run alongside other async I/O without blocking threads.
Use case: You already know the full set of prompts (for example a JSONL file) and want one scheduled unit of work with a clear terminal state and bulk results.
Benefits: Simple lifecycle (submit → wait → fetch results), fits large static workloads and JSONL-heavy pipelines.
import asyncio
from sference_sdk import AsyncSferenceClient
async def main() -> None:
async with AsyncSferenceClient(api_key="sk_...") as client:
batch = await client.submit_batch(
input_file="./workload.jsonl",
model="Qwen/Qwen3.6-35B-A3B",
window="24h",
)
done = await client.wait_for_completion(batch.id, poll_interval=2.0, timeout=3600.0)
results = await client.get_results(done.id)
print(results.status, results.output_url)
asyncio.run(main())
Async client — streams
Stream-associated jobs use create_response(..., metadata={"stream_id": ..., "completion_window": "24h"}). Consume completions with list_responses_events / iter_responses_events (optional stream_id, wait_ms long-poll; optional checkpoints align with CLI sference responses tail).
Use case: Work arrives over time, or you want one id to group many responses and observe completions as they land.
Benefits: Independent submits with aggregated progress, stream-level status in the API/UI, and efficient event tailing.
import asyncio
from sference_sdk import AsyncSferenceClient
async def main() -> None:
async with AsyncSferenceClient(api_key="sk_...") as client:
stream = await client.create_stream(name="sdk-demo", window="24h")
await client.create_response(
model="Qwen/Qwen3.6-35B-A3B",
input=[{"role": "user", "content": "Hello"}],
metadata={"stream_id": stream.id, "completion_window": "24h"},
)
async for ev in client.iter_responses_events(stream_id=stream.id, checkpoint=False):
print(ev.completion_id, ev.status)
asyncio.run(main())
CLI
For sference batch … and sference stream … commands, see the CLI README.
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 sference_sdk-0.1.0.tar.gz.
File metadata
- Download URL: sference_sdk-0.1.0.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
788721a800af3ddb7050694969406811d0741eccbca37c7fa27c11aa1fe7bf43
|
|
| MD5 |
e1b4f85632f2bb2f046d11b5a6e13b8f
|
|
| BLAKE2b-256 |
792e4bf67b2ba8d0e9ea45b06d723a79981f0aab809e38f4c2202d8f6ccf0c00
|
Provenance
The following attestation bundles were made for sference_sdk-0.1.0.tar.gz:
Publisher:
publish-sdk.yml on s-ference/sference
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sference_sdk-0.1.0.tar.gz -
Subject digest:
788721a800af3ddb7050694969406811d0741eccbca37c7fa27c11aa1fe7bf43 - Sigstore transparency entry: 1708470735
- Sigstore integration time:
-
Permalink:
s-ference/sference@a70f84d431772282d10bccc1f4873aa8634117c2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/s-ference
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@a70f84d431772282d10bccc1f4873aa8634117c2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sference_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sference_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e75d2b5abf6a2f1a623815a25e2beea4560cb5c2bba2f3cc6d85c69704031874
|
|
| MD5 |
81f77e916aba310fe7f67366e40a20bf
|
|
| BLAKE2b-256 |
df1f1adceccb7625fd184713617382fb44cd855daa32b48f04f44029545e8247
|
Provenance
The following attestation bundles were made for sference_sdk-0.1.0-py3-none-any.whl:
Publisher:
publish-sdk.yml on s-ference/sference
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sference_sdk-0.1.0-py3-none-any.whl -
Subject digest:
e75d2b5abf6a2f1a623815a25e2beea4560cb5c2bba2f3cc6d85c69704031874 - Sigstore transparency entry: 1708470746
- Sigstore integration time:
-
Permalink:
s-ference/sference@a70f84d431772282d10bccc1f4873aa8634117c2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/s-ference
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk.yml@a70f84d431772282d10bccc1f4873aa8634117c2 -
Trigger Event:
push
-
Statement type: