Skip to main content

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+
  • requests library

Links

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

cnvrt_sdk-1.0.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

cnvrt_sdk-1.0.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

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

Hashes for cnvrt_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 52409f3dd8a28b27967dc793ab0dc310d74d1a4049850743679ce5221f966f16
MD5 38f856e35a706a8fed9f6d7452bd0e55
BLAKE2b-256 135f9b9e5283d949e746db0e4f1e3fc927d331bd792f46b7d2e5c55b7c81e36b

See more details on using hashes here.

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

Hashes for cnvrt_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40d5df4aae09c23020d60470c7b001f5bcb240423e613871144cd806eb412695
MD5 38aac54fdf2aa08bc2ae6b56e8cdc005
BLAKE2b-256 fbb5615765ecd15d41a9b7ba9d58a9365fc62b9def2404e74e62f40498c8dce6

See more details on using hashes here.

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