Skip to main content

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)

V2 Validation Policy Notes

For x402 V2 requests, include validation policy metadata in paymentRequirements.extra:

  • validationRegistryAddress
  • validatorAddress
  • validatorAgentId
  • minValidationScore
  • optional requiredValidationTag

validationChainId is optional. When omitted, the underlying 4mica SDK derives validation_chain_id from the CAIP-2 network value (for example, eip155:1). If provided, it must match that network chain id.

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.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

4mica_x402-1.0.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file 4mica_x402-1.0.0.tar.gz.

File metadata

  • Download URL: 4mica_x402-1.0.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for 4mica_x402-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8c86df1acfa13b94815b70d6a8fe7084f307903fbe65a197d515adc544ffbab3
MD5 093e2e431e50e3ff6b5d760227afced3
BLAKE2b-256 3165f29160147518fe4fb721aeaacd738157375f48bed3c36a3af49d3fe62ee4

See more details on using hashes here.

File details

Details for the file 4mica_x402-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: 4mica_x402-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for 4mica_x402-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9def8f624e3636b2c1540fefc79737e84dc305866cb08e63c83259c0112a079d
MD5 279198e3839e1601626aee74c556e8f1
BLAKE2b-256 69370b135d080d6c86744d553163816cf07929de6bf7b6a0c633caae0c389f2e

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