Skip to main content

A Python module for communicating with the VocaFuse API and generating voice note applications.

Project description

VocaFuse Python SDK ✨

A comprehensive Python SDK for integrating with the VocaFuse voice API.

Installation

pip install -r requirements.txt

Quick Start

import os
from vocafuse import Client, AccessToken  # Everything from main package

# Initialize client (auto-detects environment from API key prefix)
client = Client(
    api_key=os.environ["VOCAFUSE_API_KEY"],
    api_secret=os.environ["VOCAFUSE_API_SECRET"]
)

# List voicenotes
voicenotes = client.voicenotes.list(limit=10)
print(f"Found {len(voicenotes['data'])} voicenotes")

# Get specific voicenote
voicenote = client.voicenotes.get('voicenote_id')
print(f"Status: {voicenote['data']['status']}")

# Get transcription (nested access pattern)
transcription = client.voicenotes('voicenote_id').transcription.get()
print(f"Text: {transcription['data']['text']}")

# Generate JWT token for frontend authentication (standalone approach)
token = AccessToken(
    api_key=os.environ["VOCAFUSE_API_KEY"],
    api_secret=os.environ["VOCAFUSE_API_SECRET"],
    identity='user_123'
)
jwt_response = token()
jwt_token = jwt_response['data']['jwt_token']

# Manage webhooks
webhook = client.webhooks.create(
    url='https://myapp.com/webhooks',
    events=['voicenote.completed', 'voicenote.failed']
)

# Verify webhook signatures (standalone validator from main package)
from vocafuse import RequestValidator

validator = RequestValidator('your-webhook-secret')
is_valid = validator.validate(webhook_payload, webhook_signature)

Features

🎯 Complete API Client

  • Auto-environment Detection: Automatically detects dev/test/live from API key prefix
  • Comprehensive Error Handling: Specific exceptions for different error types
  • Type Hints: Full type hint support for better development experience

📡 Resource Management

  • Voicenotes: List, get, delete voicenotes with transcription access
  • Webhooks: Create, update, delete, list webhook configurations
  • API Keys: Create, list, delete API keys for authentication
  • Account: Get and update account information and settings
  • JWT Generation: Standalone AccessToken class for frontend authentication
  • Webhook Verification: Standalone RequestValidator for signature verification

🔐 JWT Token Generation

  • Callable Interface: Simple token() method for generation
  • Custom Scopes & Expiration: Flexible token configuration

API Reference

Main Client

Client(api_key, api_secret, base_url=None)

Initialize the VocaFuse client with API credentials.

from vocafuse import Client

client = Client(
    api_key="your-api-key",
    api_secret="your-api-secret"
)

Environment Auto-Detection:

  • sk_live_* → Production: https://api.vocafuse.com/v1
  • sk_test_* → Testing: https://test-api.vocafuse.com/v1
  • Other → Development: Current dev URL

JWT Token Generation

AccessToken(api_key, api_secret, identity, base_url=None)

Generate JWT tokens for frontend authentication.

from vocafuse.jwt.access_token import AccessToken

# Create token generator
token = AccessToken(
    api_key='your-api-key',
    api_secret='your-api-secret',
    identity='user_123'
)

# Generate token with default settings
response = token()
jwt_token = response['data']['jwt_token']

# Generate token with custom options
response = token(
    expires_in=3600,  # 1 hour
    scopes=['voicenotes:read', 'voicenotes:write']
)

Default Scopes: ['voice-api.upload_voicenote']

Voicenotes Resource

# List voicenotes with filters
voicenotes = client.voicenotes.list(
    page=0,
    limit=50,
    status='completed',
    date_from='2024-01-01',
    date_to='2024-12-31'
)

# Get specific voicenote
voicenote = client.voicenotes.get('voicenote_id')

# Delete voicenote
client.voicenotes.delete('voicenote_id')

# Nested access pattern
voicenote_instance = client.voicenotes('voicenote_id')
voicenote_data = voicenote_instance.get()
transcription = voicenote_instance.transcription.get()
voicenote_instance.delete()

Webhooks Resource

# List webhooks
webhooks = client.webhooks.list()

# Create webhook
webhook = client.webhooks.create(
    url='https://myapp.com/webhooks',
    events=['voicenote.completed', 'voicenote.failed'],
    secret='optional-webhook-secret'
)

# Update webhook
client.webhooks.update(
    webhook_id='webhook_id',
    url='https://myapp.com/new-webhook',
    events=['voicenote.completed']
)

# Delete webhook
client.webhooks.delete('webhook_id')

# Verify webhook signature (standalone)
from vocafuse import RequestValidator
validator = RequestValidator('your-webhook-secret')
is_valid = validator.validate(payload, signature)

API Keys Resource

# List API keys
keys = client.api_keys.list()

# Create new API key
new_key = client.api_keys.create(name='Production Key')
print(f"Key: {new_key['data']['key']}")
print(f"Secret: {new_key['data']['secret']}")

# Delete API key
client.api_keys.delete('key_id')

Account Resource

# Get account info
account = client.account.get()
print(f"Account: {account['data']['name']}")
print(f"Tenant ID: {account['data']['tenant_id']}")

# Update account
client.account.update(name='New Company Name')

Webhook Verification

from flask import Flask, request, jsonify
from vocafuse import Client, RequestValidator

app = Flask(__name__)
client = Client(
    api_key='your-api-key',
    api_secret='your-api-secret'
)
webhook_validator = RequestValidator('your-webhook-secret')

@app.route('/webhooks/vocafuse', methods=['POST'])
def handle_webhook():
    payload = request.get_data(as_text=True)
    signature = request.headers.get('X-VocaFuse-Signature')

    if webhook_validator.validate(payload, signature):
        # Process webhook
        data = request.get_json()
        print(f"Webhook event: {data['event']}")
        return jsonify({"status": "received"})
    else:
        return jsonify({"error": "Invalid signature"}), 401

Error Handling

The SDK provides specific exceptions for different error scenarios:

from vocafuse import (
    Client,
    VocaFuseError,
    AuthenticationError,
    ValidationError,
    VoicenoteNotFoundError,
    WebhookNotFoundError
)

try:
    voicenote = client.voicenotes.get('invalid-id')
except VoicenoteNotFoundError as e:
    print(f"Voicenote not found: {e}")
    print(f"Status code: {e.status_code}")
    print(f"Error code: {e.error_code}")
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
except VocaFuseError as e:
    print(f"General API error: {e}")

Examples

See examples/complete_usage.py for a comprehensive example demonstrating all SDK features.

# Set environment variables
export VOCAFUSE_API_KEY="your-api-key"
export VOCAFUSE_API_SECRET="your-api-secret"

# Run the complete example
python examples/complete_usage.py

Environment Variables

VOCAFUSE_API_KEY=your_api_key_here
VOCAFUSE_API_SECRET=your_api_secret_here
VOCAFUSE_WEBHOOK_SECRET=your_webhook_secret_here  # For webhook verification

Requirements

  • Python 3.7+
  • requests >= 2.25.0

Support

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

vocafuse-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

vocafuse-0.1.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file vocafuse-0.1.0.tar.gz.

File metadata

  • Download URL: vocafuse-0.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vocafuse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 699d6f43d7c8f5b43a3cb608cdbfc16346ec2dbbac0e20d70624762c4f20625b
MD5 c46d5d4b031f3ff676184f07bdf86914
BLAKE2b-256 7bd6d31ff1903d7d5c0dea143a2a63fc8def8669e43975945043218bb1300642

See more details on using hashes here.

Provenance

The following attestation bundles were made for vocafuse-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on VocaFuse/vocafuse-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vocafuse-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vocafuse-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vocafuse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25d126ba56d225a3dc102ec44cecaa1a20ebdd2e7fc8cf26d3a1262fd71abfe9
MD5 59aad89a0d92b06a1012a9e7cb3d9d38
BLAKE2b-256 8e1a874497ac773acfbc60903ebe2597d62fd3052b70716aff895c382f3a0307

See more details on using hashes here.

Provenance

The following attestation bundles were made for vocafuse-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on VocaFuse/vocafuse-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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