Skip to main content

Lion Service

A unified interface for AI model providers (OpenAI, Anthropic, Perplexity, Groq) with rate limiting and token management.

Version License

Features

  • Unified interface for multiple AI providers
  • Built-in rate limiting and token tracking
  • Automatic retries with exponential backoff
  • Token calculation using tiktoken

Installation

uv pip install lion-service

# Provider-specific packages
uv pip install lion-openai      # For OpenAI
uv pip install lion-anthropic   # For Anthropic
uv pip install lion-perplexity  # For Perplexity
uv pip install lion-groq        # For Groq

Usage

from lion_service import iModel

# Initialize
model = iModel(
    provider="openai",
    task="chat",
    model="gpt-4",
    api_key="your-api-key",
    interval_tokens=90000,  # Optional: Token limit per minute
    interval_requests=3500  # Optional: Request limit per minute
)

# Make requests
async def chat():
    response = await model.invoke(
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(response)

Rate Limiting

# Token and request limits
model = iModel(
    provider="openai",
    interval_tokens=90000,  # 90K tokens/min
    interval_requests=3500  # 3.5K requests/min
)

Error Handling

from lion_service import RateLimitError

try:
    response = await model.invoke(...)
except RateLimitError as e:
    print(f"Rate limit exceeded: {e.requested_tokens} tokens")

Custom Services

from lion_service import Service, register_service

@register_service
class MyService(Service):
    def __init__(self, api_key: str):
        self.api_key = api_key
        self.name = "my_service"

    def list_tasks(self):
        return ["chat", "completion"]

Contributing

  1. Fork and clone the repository
  2. Install dev dependencies: uv pip install -e ".[dev]"
  3. Make changes
  4. Run tests: pytest
  5. Submit a pull request

See Contributing Guide for detailed instructions.

License

Apache License 2.0 - see LICENSE

Metadata

Release files for lion-service 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lion-service 1.2.0
File Size Uploaded Provenance
lion_service-1.2.0.tar.gz 23.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for lion-service 1.2.0
File Interpreter ABI Platform
lion_service-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.9 kB

Release files / lion_service-1.2.0.tar.gz

Download URL lion_service-1.2.0.tar.gz
Size 23.5 kB
Tags Source
SHA-256 checksum
How to use checksums
830c9f200c6e2d6a3c838ec6dbdd5a0da8ff01cea3a2475d7868313d3dc417fb
BLAKE2b-256 checksum
How to use checksums
6785a938c3cd88ca4715125b04b9e8cc43df94ba185e8026b924f975c84221cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / lion_service-1.2.0-py3-none-any.whl

Download URL lion_service-1.2.0-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd11036ff26c8b7490f2384a633347d3ea858929625612574c7af0cdedb7111c
BLAKE2b-256 checksum
How to use checksums
1c605530762a16d8f6a66dc5627f00a7a70f08f9d3177f3525706c0285c4dfb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Security for lion-service 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page