Skip to main content

A comprehensive Python client for the Venice.ai API with automatic parameter validation

Project description

PyVenice

Python Version PyPI Version License Tests Code Style

A comprehensive Python client library for the Venice.ai API with automatic parameter validation, type safety, and support for all endpoints.

PyVenice Banner

✨ Features

  • 🔧 Automatic Parameter Validation - Removes unsupported parameters based on model capabilities
  • 🛡️ Full Type Safety - Pydantic models for all requests and responses
  • 📡 Complete API Coverage - All 16 Venice.ai endpoints implemented
  • Async Support - Both synchronous and asynchronous clients
  • 🌊 Streaming Responses - Efficient streaming for chat completions and audio
  • 🔒 Secure by Default - HTTPS only, credentials stay local
  • ⚙️ Zero Configuration - Sensible defaults with full customization
  • 🧪 Thoroughly Tested - 82% test coverage with comprehensive test suite

Looking for Venice.ai access? Consider using my referreal code https://venice.ai/chat?ref=0Y4qyR or register at venice.ai

📦 Installation

pip install pyvenice

For development:

pip install pyvenice[dev]

Troubleshooting Installation

If you encounter build errors (especially on ARM64 Android/Termux), see our Installation Troubleshooting Guide.

🚀 Quick Start

from pyvenice import VeniceClient, ChatCompletion

# Initialize client (uses VENICE_API_KEY env var by default)
client = VeniceClient()

# Create a chat completion
chat = ChatCompletion(client)
response = chat.create(
    model="venice-uncensored",
    messages=[{"role": "user", "content": "Hello, Venice!"}]
)

print(response.choices[0].message.content)

💡 Usage Examples

Chat Completions with Streaming

from pyvenice import VeniceClient, ChatCompletion

client = VeniceClient(api_key="your-api-key")
chat = ChatCompletion(client)

# Stream responses
for chunk in chat.create_streaming(
    model="venice-coder",
    messages=[{"role": "user", "content": "Write a Python function"}],
    temperature=0.7
):
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Image Generation

from pyvenice import VeniceClient, ImageGeneration

client = VeniceClient()
image_gen = ImageGeneration(client)

response = image_gen.generate(
    prompt="A serene lake at sunset",
    model="flux-schnell",
    width=1024,
    height=1024,
    steps=4
)

# Save the image
import base64
image_data = base64.b64decode(response.images[0])
with open("sunset.png", "wb") as f:
    f.write(image_data)

Automatic Parameter Validation

PyVenice automatically removes parameters that aren't supported by specific models:

# This won't cause an error even if venice-uncensored doesn't support parallel_tool_calls
response = chat.create(
    model="venice-uncensored",
    messages=[{"role": "user", "content": "Hello!"}],
    parallel_tool_calls=True  # Automatically removed if unsupported
)

Async Support

import asyncio
from pyvenice import VeniceClient, ChatCompletion

async def main():
    client = VeniceClient()
    chat = ChatCompletion(client)
    
    response = await chat.acreate(
        model="venice-coder",
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(response.choices[0].message.content)

asyncio.run(main())

🎯 Supported Endpoints

  • 💬 Chat Completions - /chat/completions with streaming and web search
  • 🎨 Image Generation - /image/generate, /images/generations
  • 🔍 Image Upscaling - /image/upscale
  • 🔊 Text to Speech - /audio/speech with streaming
  • 📊 Embeddings - /embeddings
  • 🤖 Model Management - /models, /models/traits
  • 🔑 API Keys - /api_keys, rate limits, and web3 key generation
  • 👤 Characters - /characters for character-based interactions
  • 💰 Billing - /billing/usage with pagination

⚙️ Configuration

Environment Variables

export VENICE_API_KEY="your-api-key"
export VENICE_BASE_URL="https://api.venice.ai/api/v1"  # Optional

Client Configuration

client = VeniceClient(
    api_key="your-api-key",
    base_url="https://api.venice.ai/api/v1",
    timeout=30.0,
    max_retries=3
)

🧪 Testing

The test suite is included with the package for verification:

# Basic installation (no test dependencies)
pip install pyvenice

# Installation with test dependencies
pip install pyvenice[test]

# Run tests after installing with [test]
pytest -m "not integration"  # Unit tests only (no API key needed)
pytest --cov=pyvenice       # With coverage

# For development (includes test + dev tools)
pip install -e .[dev]

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

# Setup development environment
git clone https://github.com/TheLustriVA/PyVenice.git
cd PyVenice
pip install -e .[dev]

# Run tests before submitting PR
pytest
black .
ruff check .

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔒 Security

PyVenice prioritizes security:

  • All communications use HTTPS with certificate verification
  • API keys are never logged or included in error messages
  • No telemetry or data collection
  • Minimal dependencies, all well-maintained and audited
  • Input validation prevents injection attacks

For security concerns, please email [kieran@bicheno.me] or open an issue on GitHub

📚 Documentation

For detailed documentation, visit our docs or check out the examples directory.

🙏 Acknowledgments

Built with ❤️ using:

📈 Project Status

PyVenice is under active development. We follow semantic versioning and maintain backwards compatibility for all minor releases.

Star History Chart

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

pyvenice-0.3.1.tar.gz (51.4 kB view details)

Uploaded Source

Built Distribution

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

pyvenice-0.3.1-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file pyvenice-0.3.1.tar.gz.

File metadata

  • Download URL: pyvenice-0.3.1.tar.gz
  • Upload date:
  • Size: 51.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyvenice-0.3.1.tar.gz
Algorithm Hash digest
SHA256 96c89a4384ac74c508a86ef40706b39ba7f86bd2ce23dae4aa602980b0c20d4b
MD5 023ae2ef8e6de0637417943ec7a5aaff
BLAKE2b-256 fa5134ff980ab46c11c8d9a1e225a116f9e3a7947f151d7ec89c1b5d56be4935

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvenice-0.3.1.tar.gz:

Publisher: build-wheels.yml on TheLustriVA/PyVenice

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

File details

Details for the file pyvenice-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pyvenice-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyvenice-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a69b193ed841470522d68729d5c7c58b48dad35f80458b4d7d78678778007b41
MD5 fea3b63ed1689230822c1e93b7716407
BLAKE2b-256 fb038876831d650fcb85d411113a1979d82e975d5d4838d54ab108bdad2ad03f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvenice-0.3.1-py3-none-any.whl:

Publisher: build-wheels.yml on TheLustriVA/PyVenice

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