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.2.0.tar.gz
(12.3 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.2.0.tar.gz.
File metadata
- Download URL: 4mica_x402-1.2.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bedabc24446a469216b640e78853f6dfa960dfb71e2474cb9cd17e0c2f5bca57
|
|
| MD5 |
60b6c379a1ee2b1c6f7d340173316579
|
|
| BLAKE2b-256 |
69b0c03b2bcf4ca8d1ddec62b6c73972d8cde9bb0b5cc309c201bed5d1e534ea
|
File details
Details for the file 4mica_x402-1.2.0-py3-none-any.whl.
File metadata
- Download URL: 4mica_x402-1.2.0-py3-none-any.whl
- Upload date:
- Size: 11.3 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 |
56b5e78c3acccc566fa1ca36bd0a31ef7ed3d559942d4cd91106072c980fd454
|
|
| MD5 |
2278e368be6e46ac01d1ec8c9f943f02
|
|
| BLAKE2b-256 |
74d82392b80dd636832870f724900c30b74ca98399dc4e74f2e3fb98f1e9aa73
|