Python integration for x402 Payment Protocol with 4mica credit flow
Project description
4mica-x402
Python integration for the x402 Payment Protocol with 4mica credit flow support.
Install
pip install 4mica-x402
Optional extras:
fastapi(FastAPI middleware)flask(Flask middleware)httpx(async HTTP client wrapper)requests(sync HTTP client wrapper)all(everything)
Quick Start (Server)
from fastapi import FastAPI
from fourmica_x402.http import fastapi_payment_middleware_from_config
app = FastAPI()
routes = {
"GET /premium": {
"accepts": {
"scheme": "4mica-credit",
"price": "$0.01",
"network": "eip155:11155111",
"payTo": "0xRecipient",
}
}
}
middleware = fastapi_payment_middleware_from_config(
routes,
tab_endpoint="https://api.example.com/payment/tab",
)
@app.middleware("http")
async def x402_mw(request, call_next):
return await middleware(request, call_next)
Quick Start (Client)
from x402 import x402ClientSync
from x402.http.clients import x402_requests
from fourmica_x402.client_scheme import FourMicaEvmScheme
client = x402ClientSync()
client.register("eip155:11155111", FourMicaEvmScheme("0xYourPrivateKey"))
session = x402_requests(client)
resp = session.get("https://api.example.com/premium")
print(resp.status_code, resp.text)
Development
python -m build
python -m pytest
Install dev tools:
pip install -e .[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
4mica_x402-1.0.1.tar.gz
(12.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file 4mica_x402-1.0.1.tar.gz.
File metadata
- Download URL: 4mica_x402-1.0.1.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37a2bbdffaad562c3e20acb22d538a57869adaac45557fc3002997740fbafe91
|
|
| MD5 |
65bfa8b2445544dde5a1e8c9deab590f
|
|
| BLAKE2b-256 |
0c96dc5fba932777007944111b1faa529f980bbe3e979ce160d240a1a463c2de
|
File details
Details for the file 4mica_x402-1.0.1-py3-none-any.whl.
File metadata
- Download URL: 4mica_x402-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bb29d567a6580794d61f009b7ffe46556285a6f5a29d97b9480e1cadb59a020
|
|
| MD5 |
70c246637f43b4995814123d2d9e1aae
|
|
| BLAKE2b-256 |
654a946b3f740448acd59ab759d11c0a3c087e133940ab5305a3309cf3a06059
|