Skip to main content

Multiple API Key Manager (Next Generation, sqlalchemy_mate free)

Project description

apipool-ng

apipool-ng is a next-generation Multiple API Key Manager.

It allows developers to manage multiple API keys simultaneously. For example, if a single API key has 1000/day quota, you can register 10 API keys and let apipool-ng automatically rotate them.

Features

  • Automatically rotate API keys across multiple credentials.
  • Built-in usage statistics, searchable by time, status, and apikey. Stats collector can be deployed on any relational database (SQLite by default).
  • Clean API, minimal code required to implement complex features.
  • No uncommon dependencies — only requires sqlalchemy.

Installation

pip install apipool-ng

Quick Start

Implement an ApiKey subclass, then create an ApiKeyManager:

from apipool import ApiKey, ApiKeyManager

class MyApiKey(ApiKey):
    def __init__(self, key):
        self.key = key

    def get_primary_key(self):
        return self.key

    def create_client(self):
        return MyApiClient(api_key=self.key)

    def test_usability(self, client):
        return client.test_connection()

apikeys = [MyApiKey(k) for k in ["key1", "key2", "key3"]]
manager = ApiKeyManager(apikey_list=apikeys)
manager.check_usable()

# Use dummyclient like your real client — keys auto-rotate
result = manager.dummyclient.some_api_method(arg)

DummyClient

Use manager.dummyclient just like your original API client. Under the hood, it automatically selects a usable key, records usage events, and rotates keys on rate-limit errors.

manager.check_usable()

# Keys are automatically rotated
result = manager.dummyclient.some_method()

for _ in range(10):
    manager.dummyclient.some_method()

StatsCollector

Query usage statistics through manager.stats:

from apipool import StatusCollection

# Usage count per key in last hour
manager.stats.usage_count_stats_in_recent_n_seconds(3600)
# {"key1": 3, "key2": 5, "key3": 2}

# Count specific events
count = manager.stats.usage_count_in_recent_n_seconds(
    n_seconds=3600,
    status_id=StatusCollection.c9_ReachLimit.id,
)

License

MIT License

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

apipool_ng-1.0.5.tar.gz (57.3 kB view details)

Uploaded Source

Built Distribution

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

apipool_ng-1.0.5-py3-none-any.whl (57.6 kB view details)

Uploaded Python 3

File details

Details for the file apipool_ng-1.0.5.tar.gz.

File metadata

  • Download URL: apipool_ng-1.0.5.tar.gz
  • Upload date:
  • Size: 57.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for apipool_ng-1.0.5.tar.gz
Algorithm Hash digest
SHA256 f0b7f218f7a0e01c7f26950b89e1e2bcddc54095d8abf1c6fb1be24ca37fa546
MD5 0c40c3e07689a34117a323930c7f1645
BLAKE2b-256 36fa9a8d82bbd2a561008af6412168747a6204edab96130151e4197a1aebf432

See more details on using hashes here.

File details

Details for the file apipool_ng-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: apipool_ng-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 57.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for apipool_ng-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 27baf39d3fc2af06f48c1b3b14fac74a3eb84aeacfa32e263f3b916466859de3
MD5 31fd347070f576ed7ede87b0a4bfc2fc
BLAKE2b-256 2b191f26468cb47937f1fe9812ce9e9395f09e2e37b48a276e934f891f017769

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