Skip to main content

x402 paywall for AI agent traffic. Python SDK + proxy for FastAPI, Flask, Django, Starlette.

Project description

limen (Python)

x402 paywall middleware + standalone proxy for Python. USDC on Base and Solana. Drop-in for FastAPI, Flask, Django, Starlette.

pypi license


Install

pip install limen
# With optional framework extras:
pip install "limen[fastapi]"
pip install "limen[django]"
pip install "limen[flask]"

Python 3.11+.


FastAPI quickstart

import os
from fastapi import FastAPI
from limen.fastapi import LimenMiddleware

app = FastAPI()
app.add_middleware(
    LimenMiddleware,
    wallets={"base": os.environ["LIMEN_WALLET_BASE"]},
    endpoints=[
        {"path": "/api/v1/weather/*", "price_usdc": "0.001"},
        {"path": "/api/v1/premium/**", "price_usdc": "0.05"},
    ],
    redis_url=os.environ["REDIS_URL"],
)


@app.get("/api/v1/weather/{city}")
def weather(city: str) -> dict:
    return {"city": city, "temp_c": 17}

Flask

from flask import Flask
from limen.flask import limen_middleware

app = Flask(__name__)
app.wsgi_app = limen_middleware(
    app.wsgi_app,
    wallets={"base": os.environ["LIMEN_WALLET_BASE"]},
    endpoints=[{"path": "/api/v1/*", "price_usdc": "0.001"}],
    redis_url=os.environ["REDIS_URL"],
)

Django

settings.py:

MIDDLEWARE = [
    "limen.django.LimenMiddleware",
    # ...
]

LIMEN = {
    "wallets": {"base": os.environ["LIMEN_WALLET_BASE"]},
    "endpoints": [{"path": "/api/v1/*", "price_usdc": "0.001"}],
    "redis_url": os.environ["REDIS_URL"],
}

Standalone proxy

limen start --config limen.config.yml --upstream http://localhost:3000

CLI

limen start        Run the proxy.
limen doctor       Check config + connectivity + ports.
limen verify       Verify a transaction against config.
limen config       lint | print | explain | migrate
limen keys         generate-webhook-secret | generate-admin-keypair
limen audit        verify | tail

Security

This package enforces the nine invariants listed in docs/security.md § 4. Report vulnerabilities privately — see SECURITY.md.

Full getting-started, API reference, scaling, compliance docs: ../../docs/.


Development

hatch env create
hatch run test     # pytest with coverage
hatch run lint     # ruff
hatch run typecheck  # mypy strict

License

MIT — see 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

limenpay-0.1.0a1.tar.gz (43.3 kB view details)

Uploaded Source

Built Distribution

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

limenpay-0.1.0a1-py3-none-any.whl (55.4 kB view details)

Uploaded Python 3

File details

Details for the file limenpay-0.1.0a1.tar.gz.

File metadata

  • Download URL: limenpay-0.1.0a1.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for limenpay-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 b17bf4c47ef36ddfaf01779af1d30f7fc7208e0aaaee7c3afc248129f10c813d
MD5 99914e27f1d7d755e7cf78d9f51ebd02
BLAKE2b-256 a2ced807bd9dd3c6fca0bc24a26a822b03ce823ec23f527268a225e745431e65

See more details on using hashes here.

File details

Details for the file limenpay-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: limenpay-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 55.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for limenpay-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 9873cb25c7ac844afe5d350e8b3f27c213449f7bf716ee648ffa65a5c6176213
MD5 304ae05d118d57dc11209dccc0adc070
BLAKE2b-256 b646e5fe470d24d8d3ed36e6ac7e4195a5c29362b591ded558616a2498c1d347

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