Skip to main content
The official Unkey Python SDK (unkey-py) provides full access to Unkey’s API for managing keys, verifying requests, and rate limiting in Python applications.

Installation

Requirements: Python 3.9 or higher

Initialization

Create a client with your root key:
Never expose your root key in client-side code or commit it to version control.

Verify API Keys

Validate a user’s API key:

Verification Response

The result object contains:

Framework Integration

FastAPI

Protect your FastAPI endpoints:

FastAPI Dependency

Create reusable authentication:

Flask

Integrate with Flask applications:

Flask Decorator

Django

Create custom middleware for Django:
Add to settings.py:
Use in views:

Create API Keys

Issue new keys for your users:
The full API key is only returned once at creation. Unkey stores only a cryptographic hash.

Create Key with Permissions


Update Keys

Modify an existing key:

Delete Keys

Permanently revoke a key:
Or disable temporarily:

Rate Limiting

Use the rate limit API directly:

Cost-Based Rate Limiting


Async Support

All methods have async variants:

Async FastAPI


Error Handling

Handle errors gracefully:

Advanced Usage

Managing APIs

Identity Management


Complete Example: API Service


GitHub Repository

Python SDK on GitHub

Complete auto-generated API reference and source code

Next Steps

Python Quickstart

Step-by-step integration guide

Rate Limiting

Protect endpoints from abuse

Authorization

Add roles and permissions

API Reference

REST API documentation