Skip to main content

API key creation, validation & developer platform integration

Project description

apikee · Python

PyPI

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

Install

pip install apikee                # local mode, zero deps
pip install "apikee[fastapi]"     # + FastAPI middleware
pip install "apikee[server]"      # + encrypted server channel (apikee.dev)
pip install "apikee[all]"         # everything

Configure (set 1 env var)

export APIKEE_SECRET=$(openssl rand -hex 32)

# Optional — enables server mode (usage tracking, rate limits, fraud detection)
export APIKEE_SERVER_KEY=sk_live_...
export APIKEE_PROJECT_ENV=my-api-production

FastAPI

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

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

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)

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

Workflows

Workflow Trigger Action
ci.yml push / PR Lint + test matrix (Python 3.10–3.12 × 3 OS)
release.yml tag v*.*.* or manual Build → PyPI → GitHub Release
version-bump.yml PR label or manual Bump version, commit, push tag
hotfix.yml manual Fast-track patch from main

Release: git tag v1.2.3 && git push --tags

Secrets needed (repo → Settings → Secrets → Actions):

Secret Notes
PyPI trusted publishing Configure at pypi.org/manage/account/publishing — no token needed
PYPI_API_TOKEN Alternative to OIDC — uncomment in release.yml

Docs

apikee.com/docs · apikee.dev

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

apikee-0.1.2.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

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

apikee-0.1.2-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file apikee-0.1.2.tar.gz.

File metadata

  • Download URL: apikee-0.1.2.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for apikee-0.1.2.tar.gz
Algorithm Hash digest
SHA256 faad6606eeab287541299f3eefd8f58654df888182d0aedb6be858e1e3b51894
MD5 a46e451bbcab92a999b22089468f0f02
BLAKE2b-256 6c22277f0430ca3c21540569df9e1bc785107f8212cd24f8e913cb86c7741c56

See more details on using hashes here.

File details

Details for the file apikee-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: apikee-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for apikee-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d1b1c94a4f3e59ea8a5370a92e6c06197af866a5babdde990c96b93f4873ef0
MD5 4ece99a6640d31590e4f8acaec940e91
BLAKE2b-256 d811db896e2946bfeb4923156c333471055bf6fd40886e64504957011d3c8815

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