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
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-0.1.0.tar.gz
(11.0 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-0.1.0.tar.gz.
File metadata
- Download URL: 4mica_x402-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de51ca77030980d13faacb9cd92199fc923254038a200397c1a8a4829bc4507b
|
|
| MD5 |
f3233efedd02af0d8a584809a4dad7cb
|
|
| BLAKE2b-256 |
ef91201845b133e93b6aee3447b99cb97f0d0e89df80c715e713b7c0dc7223b5
|
File details
Details for the file 4mica_x402-0.1.0-py3-none-any.whl.
File metadata
- Download URL: 4mica_x402-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd6d5074c84b8a64a315f15c5e106de26fe3a0f33440e8540b7246652a9d65d1
|
|
| MD5 |
9d2628684511e0b6fcdfcc3a3d89cfdb
|
|
| BLAKE2b-256 |
7ece0fead340aae1b950bd58f1edcf7cd7f02d5fcd4e0a58593d6b56bd2d1ce7
|