Skip to main content

A Python library for API key validation

Project description

API Key Gateway

A Python library that provides an @apikey_login decorator to validate API keys with service-aware authentication.

Features

  • Automatically adds --apikey/-a CLI parameter to decorated functions
  • Validates API keys using argon2id hashing algorithm for strong security
  • Service-aware validation: Keys are scoped to specific services
  • Fetches valid public keys from a remote JSON endpoint
  • Easy to use decorator interface with service parameter

Installation

uv install apikey-gateway

Usage

The apikey_login decorator requires a service parameter to scope keys to specific services.

from apikey_gateway import apikey_login

@apikey_login(service="media-match")
def media_app():
    print("API key validated for media-match service!")
    # Your media application logic here

@apikey_login(service="analytics")
def analytics_app():
    print("API key validated for analytics service!")
    # Your analytics application logic here

if __name__ == "__main__":
    media_app()  # or analytics_app()

Run with:

python app.py --apikey your-secret-key

How It Works

  1. The application specifies the service name when using the @apikey_login decorator
  2. The user provides a secret API key via the --apikey/-a CLI parameter
  3. The library computes an argon2id hash (public key) from the secret key
  4. It fetches the list of valid public keys from https://api.jsonbin.io/v3/b/691ec6a543b1c97be9b8ea6d
  5. Valid keys are filtered to only those belonging to the specified service
  6. If the computed public key matches any valid service-specific public key, access is granted

JSON Format

The remote JSON follows a service-aware structure where keys are organized by service name:

Service-Aware Structure

{
  "service1": {
    "key_id_1": "argon2id_hash_here",
    "key_id_2": "another_hash_here"
  },
  "service2": "single_key_hash_here"
}
  • Top-level keys are service names
  • Each service can have either multiple keys (as a dictionary) or a single key (as a string)
  • The library automatically handles both formats when fetching keys

License

MIT

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

apikey_gateway-1.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

apikey_gateway-1.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file apikey_gateway-1.0.1.tar.gz.

File metadata

  • Download URL: apikey_gateway-1.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for apikey_gateway-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f7fc1fd49b927aa23505b9f8128435e65962d02e8703d029614555e3f0682063
MD5 af0cd09b8b9f15d79e75ab8f7893936a
BLAKE2b-256 7ef3697472a20ebeda58a66ca691cede14ab9c246d537157114b578c9badb7bc

See more details on using hashes here.

File details

Details for the file apikey_gateway-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for apikey_gateway-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0117316386196c3bf88bf3d5304325a8a59131a1b66e4367c46c5f0a165af48
MD5 9f153a68ccf958409cf41619f6148c0a
BLAKE2b-256 a9c4c73b164b2146cec2da62beba6fba3a4158fcc28fae798c038fa7e6db588e

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