Metadata-Version: 2.4
Name: apikee
Version: 0.1.2b0
Summary: API key creation, validation & developer platform integration
Project-URL: Homepage, https://github.com/apikee-dev/python
Project-URL: Repository, https://github.com/apikee-dev/python
License: MIT
License-File: LICENSE
Keywords: api-key,authentication,middleware,security
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Security
Requires-Python: >=3.10
Provides-Extra: all
Requires-Dist: cryptography>=41.0; extra == 'all'
Requires-Dist: fastapi>=0.100; extra == 'all'
Requires-Dist: msgpack>=1.0; extra == 'all'
Requires-Dist: starlette>=0.27; extra == 'all'
Provides-Extra: fast
Requires-Dist: msgpack>=1.0; extra == 'fast'
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.100; extra == 'fastapi'
Requires-Dist: starlette>=0.27; extra == 'fastapi'
Provides-Extra: server
Requires-Dist: cryptography>=41.0; extra == 'server'
Description-Content-Type: text/markdown

# apikee · Python

[![PyPI](https://img.shields.io/pypi/v/apikee)](https://pypi.org/project/apikee/)

API key plugin for Python — FastAPI, Flask, and Starlette.

## Install

```bash
pip install apikee                # local mode, zero deps
pip install "apikee[fastapi]"     # + FastAPI middleware
pip install "apikee[server]"      # + encrypted server channel
pip install "apikee[all]"         # everything
pip install --pre apikee          # latest beta pre-release
```

## Configure

```bash
export APIKEE_SECRET=$(openssl rand -hex 32)

# Optional server mode — point to your self-hosted Apikee instance
export APIKEE_BASE_URL=https://apikee.example.com/api/v1
export APIKEE_SERVER_KEY=sk_...
export APIKEE_PROJECT_ENV=my-api-production
```

## FastAPI

```python
from apikee.fastapi import SecuredFastAPI, ApikeeDepends, require_scope
from apikee import ApikeeClaims
from fastapi import Depends

app = SecuredFastAPI()  # reads APIKEE_SECRET — done

@app.post("/keys")         # public endpoint — issue keys to customers
def create_key(tenant: str, scopes: str = "read,write"):
    key = app.apikee.create(tenant, scopes=scopes.split(","))
    return {"key": key}   # store it — returned once

@app.get("/data")
def get_data(claims: ApikeeClaims = ApikeeDepends()):
    return {"tenant": claims.tenant, "scopes": claims.scopes}

@app.delete("/admin", dependencies=[Depends(require_scope("admin"))])
def admin_action(): ...
```

Open `/docs` — every endpoint shows the 🔒 lock. Click **Authorize**, paste a key.

## Flask

```python
from flask import Flask
from apikee.flask import init_apikee, apikee_required, require_scope, get_claims

app = Flask(__name__)
init_apikee(app)  # reads APIKEE_SECRET — done

@app.get("/data")
@apikee_required
def data():
    return {"tenant": get_claims().tenant}

@app.delete("/admin")
@require_scope("admin")
def admin(): ...
```

## Any ASGI

```python
from apikee import Apikee

apikee = Apikee()
app.add_middleware(apikee.middleware)   # claims at request.state.apikee

# Or inline, no middleware:
claims = apikee.protect(request.headers.get("x-api-key"))
```

## Key rotation (zero downtime)

```bash
export APIKEE_SECRET=new-secret        # new keys signed with this
# Old keys still validate during the rotation window — pass both to Apikee():
```
```python
apikee = Apikee(secrets=["new-secret", "old-secret"])
```

## Environment Variables (.env)

Python frameworks (FastAPI, Flask, Starlette/ASGI) use the same variables.

Required:

```env
APIKEE_SECRET=replace-with-strong-random-secret
```

Optional (server mode — requires a running Apikee instance):

```env
APIKEE_BASE_URL=https://apikee.example.com/api/v1
APIKEE_SERVER_KEY=sk_...
APIKEE_PROJECT_ENV=my-api-production
APIKEE_SERVER_PUBLIC_KEY=base64-x25519-public-key   # enables payload encryption
APIKEE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----..."  # enables RSA request signing
```

## Project structure

```
apikee/     Library source — core + framework modules (FastAPI, Flask, server)
tests/      Test suite
examples/   Example apps (FastAPI, Flask, Starlette)
```

## Contributing

See [CONTRIBUTING.md](./CONTRIBUTING.md) for local setup, branch naming
conventions, and the release process.

## License

[MIT](./LICENSE)

## Docs

[github.com/apikee-dev](https://github.com/apikee-dev)
