l402-python
Usage
Installation
Install latest from the GitHub repository:
$ pip install git+https://github.com/Fewsats/l402-python.git
or from pypi
$ pip install l402_python
Documentation
Documentation can be found hosted on this GitHub repository’s pages. Additionally you can find package manager specific guidelines on conda and pypi respectively.
How to use
Server
# Create FastAPI app
app = FastAPI()
server = ServerManager(app).start()
INFO: Started server process [47447]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
Payment Server
from uuid import uuid4
ps = PaymentServer(
payment_request_url="http://localhost:8000/payment_request",
onchain_provider=create_test_wallet(fund=False),
)
@app.get("/offers")
def offers():
offers_list = [Offer(
amount=1,
currency='USD',
description='Purchase 1 credit for API access',
offer_id=str(uuid4()),
payment_methods=['onchain'], # maybe not needed because we can generate it from the payment provider
title='1 Credit Package',
type='one-time'
)]
offers_response = ps.create_offers(offers_list)
return JSONResponse(
content=offers_response.model_dump(),
status_code=402
)
@app.post("/payment_request")
async def create_payment_request(request: PaymentRequest):
payment_request = ps.create_payment_request(**request.model_dump())
return JSONResponse(
content=payment_request,
status_code=200
)
Client
w = create_test_wallet(fund=False)
c = Client(onchain_provider=CoinbaseProvider(wallet=w))
r1 = httpx.get("http://localhost:8000/offers")
r1.status_code, r1.json()
INFO: 127.0.0.1:50799 - "GET /offers HTTP/1.1" 402 Payment Required
INFO: 127.0.0.1:50800 - "POST /payment_request HTTP/1.1" 200 OK
(402,
{'offers': [{'amount': 1,
'currency': 'USD',
'description': 'Purchase 1 credit for API access',
'offer_id': '3731f7ea-b00e-4389-9370-fd6acedffd0d',
'payment_methods': ['onchain'],
'title': '1 Credit Package',
'type': 'one-time'}],
'payment_context_token': '34b9a1f8-422b-44c2-8063-9109f5d42e17',
'payment_request_url': 'http://localhost:8000/payment_request',
'version': '0.2.2'})
if r1.status_code == HTTPStatus.PAYMENT_REQUIRED:
try:
ps = c.pay(r1.json())
except Exception as e:
print(e)
Insufficient funds: have 0, need 1.
Metadata
Release files for l402 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| l402-0.1.0.tar.gz | 10.5 kB | Without provenance | Details for l402-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| l402-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for l402-0.1.0-py3-none-any.whl |
Total release size: 19.7 kB
Release files / l402-0.1.0.tar.gz
| Download URL | l402-0.1.0.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7885abb8a2919e522049f01b63368d6c41c1b99ac083f48eb23c9c3c8fbf55ec
|
|
BLAKE2b-256 checksum How to use checksums |
def920fbbda5a112ef1ba30dd40c9acb9519966de74c0779543c3ba3ec47eb05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Release files / l402-0.1.0-py3-none-any.whl
| Download URL | l402-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18bb9d0e53c2f83b6bd12d2a47dcdfe02085ce1cae2709cc35863ecae5e41299
|
|
BLAKE2b-256 checksum How to use checksums |
cbcd25de9216010719139f7ace4fe1c6c900e1319629d26f763f3f3f752cfa29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Security for l402 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.