Official Python SDK for CNVRT media conversion API with x402 payment support
Project description
CNVRT Python SDK
Official Python SDK for CNVRT media conversion API with x402 payment support.
Installation
pip install cnvrt
Quick Start
from cnvrt import CNVRT
# Initialize client
client = CNVRT()
# Convert YouTube video to MP3
result = client.convert(
url="https://youtube.com/watch?v=dQw4w9WgXcQ",
format="mp3",
quality="best"
)
print(f"Download: {result['download_url']}")
Features
- ✅ Universal Media Conversion - YouTube, TikTok, Instagram, Twitter, and 1000+ platforms
- ✅ AI Transcription - 95%+ accuracy with OpenAI Whisper
- ✅ File Conversion - Images, documents, PDFs, archives
- ✅ x402 Payments - Automatic USDC micropayments on Base & Solana
- ✅ Agent-Friendly - Pre-flight validation, cost estimation, batch operations
- ✅ Type Hints - Full typing support for better IDE experience
- ✅ Async Support - (Coming soon)
Usage Examples
Convert Media
# From URL
result = client.convert(
url="https://youtube.com/watch?v=example",
format="mp4",
quality="1080p"
)
# From file
with open("video.mov", "rb") as f:
result = client.convert(
file=f,
format="mp4",
quality="best"
)
# Dry run (test without cost)
result = client.convert(
url="https://youtube.com/watch?v=example",
format="mp3",
dry_run=True
)
Transcribe Audio/Video
# Transcribe from URL
result = client.transcribe(
url="https://youtube.com/watch?v=example",
language="en"
)
print(result["text"])
print(result["segments"]) # Timestamps
# Transcribe from file
with open("audio.mp3", "rb") as f:
result = client.transcribe(file=f)
Agent-Friendly Features
# Validate before payment
validation = client.validate(
url="https://youtube.com/watch?v=example",
format="mp3",
quality="best"
)
if validation["valid"]:
result = client.convert(...)
# Estimate cost
cost = client.estimate_cost(
url="https://youtube.com/watch?v=example",
operation="convert",
format="mp3"
)
print(f"Estimated cost: ${cost['total_usd']}")
# Auto-detect format
suggestion = client.detect_format(
url="https://youtube.com/watch?v=example"
)
print(f"Suggested: {suggestion['suggested_format']}")
# Get usage stats
usage = client.get_usage()
print(f"Total requests: {usage['total_requests']}")
print(f"Success rate: {usage['success_rate']}%")
Idempotency
Prevent duplicate processing with idempotency keys:
result = client.convert(
url="https://youtube.com/watch?v=example",
format="mp3",
idempotency_key="unique-key-123"
)
# Same request will return cached result
result2 = client.convert(
url="https://youtube.com/watch?v=example",
format="mp3",
idempotency_key="unique-key-123"
)
x402 Protocol Info
# Get supported networks and payment info
x402_info = client.get_x402_info()
print(x402_info["networks"]) # Base, Solana
print(x402_info["facilitator"]) # CDP endpoints
Health Check
health = client.health_check()
if health["healthy"]:
print("Service is up!")
Configuration
client = CNVRT(
base_url="https://cnvrt.ing", # Service URL
network="base", # Payment network (base or solana)
timeout=120, # Request timeout in seconds
)
Error Handling
from cnvrt import CNVRT, CNVRTError, PaymentError, ConversionError
client = CNVRT()
try:
result = client.convert(
url="https://youtube.com/watch?v=example",
format="mp3"
)
except PaymentError as e:
print(f"Payment required: {e}")
except ConversionError as e:
print(f"Conversion failed: {e}")
except CNVRTError as e:
print(f"API error: {e}")
Supported Formats
Video Formats
MP4, WebM, MKV, AVI, MOV, FLV, WMV, etc.
Audio Formats
MP3, WAV, M4A, FLAC, OGG, AAC, etc.
Image Formats
JPG, PNG, WebP, GIF, BMP, TIFF, etc.
Document Formats
PDF, DOCX, TXT, etc.
Requirements
- Python 3.8+
requestslibrary
Links
- Documentation: https://docs.cnvrt.ing
- GitHub: https://github.com/iclipz/cnvrt
- PyPI: https://pypi.org/project/cnvrt/
- Support: support@cnvrt.ing
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 cnvrt_sdk-1.0.0.tar.gz.
File metadata
- Download URL: cnvrt_sdk-1.0.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52409f3dd8a28b27967dc793ab0dc310d74d1a4049850743679ce5221f966f16
|
|
| MD5 |
38f856e35a706a8fed9f6d7452bd0e55
|
|
| BLAKE2b-256 |
135f9b9e5283d949e746db0e4f1e3fc927d331bd792f46b7d2e5c55b7c81e36b
|
File details
Details for the file cnvrt_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: cnvrt_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40d5df4aae09c23020d60470c7b001f5bcb240423e613871144cd806eb412695
|
|
| MD5 |
38aac54fdf2aa08bc2ae6b56e8cdc005
|
|
| BLAKE2b-256 |
fbb5615765ecd15d41a9b7ba9d58a9365fc62b9def2404e74e62f40498c8dce6
|