OfSpectrum Audio Watermarking SDK
Project description
OfSpectrum Python SDK
Official Python SDK for the OfSpectrum Audio Watermarking API.
Installation
pip install ofspectrum
Or install from source:
pip install -e /path/to/neo/sdk
Quick Start
from ofspectrum import OfSpectrum
# Initialize client with your API key
client = OfSpectrum(api_key="your_api_key")
# Create a watermark token (simple - uses "standard" type by default)
token = client.tokens.create(name="Production Token")
print(f"Created token: {token.id}")
# Or specify a type (creator/enterprise require public_key)
# token = client.tokens.create(
# name="Creator Token",
# token_type="creator",
# public_key=12345
# )
# Encode watermark into audio
result = client.audio.encode(
audio="input.mp3",
token_id=token.id,
output_path="watermarked.mp3"
)
print(f"Encoded {result.audio_duration}s of audio")
# Decode (detect) watermark from audio
decode = client.audio.decode("suspect.mp3")
if decode.watermarked:
print(f"Watermark detected! Token ID: {decode.token_id}")
else:
print("No watermark detected")
# Check your quota
quota = client.quotas.get_encode_quota()
print(f"Remaining encode quota: {quota.remaining}/{quota.quota_limit} seconds")
Features
Token Management
# List all tokens
tokens = client.tokens.list()
# Get a specific token
token = client.tokens.get("token-uuid")
# Update a token
token = client.tokens.update(
token_id="token-uuid",
name="New Name"
)
# Note: Token deletion is not available via API.
# Tokens are consumable resources.
Audio Watermarking
# Encode with custom settings
result = client.audio.encode(
audio="input.mp3",
token_id=token.id,
strength=1.0, # 0.1-2.0
normalize=True, # Smooth audio to reduce artifacts
check_watermark=True, # Check for existing watermark first
output_path="output.mp3"
)
# Decode watermark from audio file
decode = client.audio.decode("suspect.mp3")
if decode.watermarked:
print(f"Token: {decode.token_id}")
Notebook (Notes) Management
# Create a public notebook for a token
notebook = client.notebooks.create(
token_id=token.id,
note_name="Release Notes",
text_content="## Version 1.0\n\nInitial release.",
is_public=True
)
# Create a private notebook (default password: "123")
private_nb = client.notebooks.create(
token_id=token.id,
note_name="Private Notes",
text_content="Confidential content",
is_public=False,
credential_val="123" # Optional, defaults to "123"
)
# Upload media to notebook
client.notebooks.upload_media(
note_id=notebook.id,
file="cover.jpg"
)
# List notebooks for a token
notebooks = client.notebooks.list(token_id=token.id)
Quota Checking
# Get all quotas
quotas = client.quotas.get_all()
for quota in quotas:
print(f"{quota.service_name}: {quota.remaining}/{quota.quota_limit}")
# Check if encoding is available
if client.quotas.check_encode_available(duration_seconds=300):
# Proceed with encoding
pass
Error Handling
from ofspectrum import (
OfSpectrumError,
AuthenticationError,
RateLimitError,
QuotaExceededError,
WatermarkExistsError,
ResourceNotFoundError,
)
try:
result = client.audio.encode(audio="input.mp3", token_id="...")
except RateLimitError as e:
print(f"Rate limited! Retry after {e.retry_after} seconds")
except QuotaExceededError as e:
print(f"Quota exceeded for {e.service}")
except WatermarkExistsError:
print("Audio already has a watermark!")
except AuthenticationError:
print("Invalid API key")
except OfSpectrumError as e:
print(f"API error: {e.code} - {e.message}")
Retry Logic
from ofspectrum import OfSpectrum, RetryConfig, with_retry
# Use built-in retry decorator
@with_retry(RetryConfig(max_retries=3))
def encode_with_retry():
return client.audio.encode(...)
# Or configure retry globally
config = RetryConfig(
max_retries=5,
initial_delay=1.0,
max_delay=60.0,
exponential_base=2.0,
jitter=True
)
Context Manager
# Recommended: Use context manager for automatic cleanup
with OfSpectrum(api_key="your_api_key") as client:
tokens = client.tokens.list()
Configuration
client = OfSpectrum(
api_key="your_api_key",
base_url="https://api.ofspectrum.com/api/v1", # Optional: custom base URL
timeout=120.0 # Optional: request timeout in seconds
)
Requirements
- Python 3.8+
- httpx >= 0.24.0
License
MIT License
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
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 ofspectrum-1.1.3.tar.gz.
File metadata
- Download URL: ofspectrum-1.1.3.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0bf675909eceed2ddcf3dfde2c95f27d69b4dc795e140496cc61012c1d60876
|
|
| MD5 |
c14b436fb1f6162de15b53d5cc5fc1eb
|
|
| BLAKE2b-256 |
db39e9e895126e3ae211adc14b74dde577b232e9cbf38b44ea52f1bdba1c4f97
|
Provenance
The following attestation bundles were made for ofspectrum-1.1.3.tar.gz:
Publisher:
publish.yml on ofspectrum/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ofspectrum-1.1.3.tar.gz -
Subject digest:
c0bf675909eceed2ddcf3dfde2c95f27d69b4dc795e140496cc61012c1d60876 - Sigstore transparency entry: 781182403
- Sigstore integration time:
-
Permalink:
ofspectrum/python-sdk@502e3a7dac2abae8e8883575a5d07a39ae2fa160 -
Branch / Tag:
refs/tags/v1.1.3 - Owner: https://github.com/ofspectrum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@502e3a7dac2abae8e8883575a5d07a39ae2fa160 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ofspectrum-1.1.3-py3-none-any.whl.
File metadata
- Download URL: ofspectrum-1.1.3-py3-none-any.whl
- Upload date:
- Size: 24.6 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 |
deb8b7964c9903addafab5cedbd5257c460dd04dd8f0e7f6e250df90bb316c1c
|
|
| MD5 |
60f7a961e56ee6f4844beb92c59f844a
|
|
| BLAKE2b-256 |
4ea3b9b3152bd69b8a87839ddf3dd4911df58f65b3f87918cb25471e694a8135
|
Provenance
The following attestation bundles were made for ofspectrum-1.1.3-py3-none-any.whl:
Publisher:
publish.yml on ofspectrum/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ofspectrum-1.1.3-py3-none-any.whl -
Subject digest:
deb8b7964c9903addafab5cedbd5257c460dd04dd8f0e7f6e250df90bb316c1c - Sigstore transparency entry: 781182404
- Sigstore integration time:
-
Permalink:
ofspectrum/python-sdk@502e3a7dac2abae8e8883575a5d07a39ae2fa160 -
Branch / Tag:
refs/tags/v1.1.3 - Owner: https://github.com/ofspectrum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@502e3a7dac2abae8e8883575a5d07a39ae2fa160 -
Trigger Event:
push
-
Statement type: