Official Python client for the Sonilo API
Project description
sonilo
Official Python client for the Sonilo API. Python ≥ 3.9. Sync and async clients included.
Installation
pip install sonilo
Quickstart
from sonilo import Sonilo
client = Sonilo() # reads SONILO_API_KEY
track = client.text_to_music.generate(
prompt="cinematic orchestral score",
duration=60,
)
track.save("output.mp3")
print(track.title)
Video to music
track = client.video_to_music.generate(video="my_video.mp4", prompt="upbeat")
# or bytes / an open binary file, or a hosted URL:
track = client.video_to_music.generate(video_url="https://example.com/clip.mp4")
Streaming
for event in client.text_to_music.stream(prompt="lofi", duration=30):
if event["type"] == "audio_chunk":
handle(event["data"]) # bytes, as they arrive
Async
from sonilo import AsyncSonilo
async with AsyncSonilo() as client:
track = await client.text_to_music.generate(prompt="lofi", duration=30)
async for event in client.text_to_music.stream(prompt="lofi", duration=30):
...
Segments
Shape the composition with start-only contiguous segments (each ends where the next begins):
client.text_to_music.generate(
prompt="epic trailer",
duration=60,
segments=[
{"start": 0, "prompt": "soft intro", "label": "intro"},
{"start": 20, "prompt": "building tension", "label": "verse"},
{"start": 40, "prompt": "full orchestra", "label": "chorus"},
],
)
Sound effects (async tasks)
SFX endpoints are asynchronous: submitting returns a task_id, and the result
is fetched by polling. generate() wraps submit + poll:
from sonilo import Sonilo
with Sonilo() as client:
result = client.text_to_sfx.generate(prompt="glass shattering", duration=5)
result.save("sfx.m4a")
Or control polling yourself:
task = client.video_to_sfx.submit(
video="clip.mp4",
segments=[{"start": 0, "end": 2.5, "prompt": "footsteps on gravel"}],
audio_format="wav",
)
result = client.tasks.wait(task.task_id, poll_interval=2.0, timeout=600.0)
result.save("audio.wav")
result.save("with_audio.mp4", which="video") # video-to-sfx also returns the muxed video
tasks.get(task_id) fetches state once and never raises on a failed task;
tasks.wait() / generate() raise TaskFailedError (with .code,
.refunded) on failure and TaskTimeoutError if the deadline passes — the
task keeps running server-side and can still be polled afterwards. Result URLs
are presigned and expire; download promptly or re-fetch via tasks.get.
Account
client.account.services()
client.account.usage(days=7)
Errors
All errors extend SoniloError: AuthenticationError (401),
PaymentRequiredError (402), RateLimitError (429, .retry_after),
BadRequestError (400/413/422, .detail), APIError (anything else),
GenerationError for failures mid-stream, TaskFailedError (.code,
.task_id, .refunded) for a failed SFX task, and TaskTimeoutError
(.task_id) when tasks.wait() / generate() hits its deadline.
Every APIError also carries .status_code, .body (the parsed response),
.code (the API's error code, e.g. "rate_limit_exceeded"), and .errors
(the validation detail list on a 422), in addition to any subclass-specific
attributes above.
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 sonilo-0.2.0.tar.gz.
File metadata
- Download URL: sonilo-0.2.0.tar.gz
- Upload date:
- Size: 20.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 |
d33be102ff281f6630dbe4a1e8a4f5928ae0d4a4a218b75dfef31d94cc241bdc
|
|
| MD5 |
6ad1afc0f54c80a930f300aae386c836
|
|
| BLAKE2b-256 |
8a182c298d3edcc9497d43b3eeccce1d46ad55bcd76ec15a0eb764decf532a88
|
Provenance
The following attestation bundles were made for sonilo-0.2.0.tar.gz:
Publisher:
publish.yml on sonilo-ai/sonilo-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sonilo-0.2.0.tar.gz -
Subject digest:
d33be102ff281f6630dbe4a1e8a4f5928ae0d4a4a218b75dfef31d94cc241bdc - Sigstore transparency entry: 2154315038
- Sigstore integration time:
-
Permalink:
sonilo-ai/sonilo-python@b669cac658ca776447522763be3fc28548abaa9a -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/sonilo-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b669cac658ca776447522763be3fc28548abaa9a -
Trigger Event:
push
-
Statement type:
File details
Details for the file sonilo-0.2.0-py3-none-any.whl.
File metadata
- Download URL: sonilo-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.8 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 |
9ed8984a3451c057a47a8fb3545e6c4e3cea6deb701861761466565f26b5b2db
|
|
| MD5 |
fa5ff98ffb8749b7ef256ab8da34098f
|
|
| BLAKE2b-256 |
3de9752c98426d0f7f1b0b2d2f857cea803dcb57448f19f48fdf442bfc4b259b
|
Provenance
The following attestation bundles were made for sonilo-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on sonilo-ai/sonilo-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sonilo-0.2.0-py3-none-any.whl -
Subject digest:
9ed8984a3451c057a47a8fb3545e6c4e3cea6deb701861761466565f26b5b2db - Sigstore transparency entry: 2154315059
- Sigstore integration time:
-
Permalink:
sonilo-ai/sonilo-python@b669cac658ca776447522763be3fc28548abaa9a -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/sonilo-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b669cac658ca776447522763be3fc28548abaa9a -
Trigger Event:
push
-
Statement type: