Skip to main content

pyl402: L402 tools for Python

Take the L402 pill...

Overview

pyl402 is a Python package designed to handle HTTP requests with integrated payment functionality, specifically focusing on the Lightning Network protocol L402 and automatic handling of HTTP 402 Payment Required responses. It integrates seamlessly with Lightning wallets to provide a smooth experience when dealing with paid resources.

Note: This project is currently in alpha stage and is considered Work-In-Progress (WIP). Features and functionality are subject to change, and more testing is needed to ensure stability and reliability.

Installation

To install pyl402, you can use pip:

pip install pyl402

Please note that this package requires Python 3.7 or later.

Features

  • Automatic Token Handling: Manages L402 tokens automatically, storing and retrieving tokens as needed.
  • Integrated Payment: Automatically handles payment processes if a resource requires payment, through compatible wallet implementations.
  • Extensible: Easily extend the library to support different wallet types and token storage mechanisms.

Usage

Here's a quick example to get you started with the L402 Client:

from pyl402.wallet import AlbyWallet
from pyl402.token_store import MemoryTokenStore
from pyl402.client import L402Client

# Initialize wallet and token store
wallet = AlbyWallet(token="your_alby_api_token_here")
store = MemoryTokenStore()

# Create the L402 Client
client = L402Client(wallet=wallet, store=store)

# Use the client to send HTTP requests
response = client.get('http://rnd.ln.sulu.sh/randomnumber')
print(response.text)

This example demonstrates creating an L402 client using an Alby wallet and a memory-based token store to access a resource that may require payment.

Example with OpenAI SDK and Sulu Inference Endpoints

With this example you can access inference APIs just with Bitcoin and the Lightning Network!

import os
from openai import OpenAI

from pyl402.wallet import AlbyWallet
from pyl402.client import L402Client
from pyl402.token_store import MemoryTokenStore

# Create the L402 client
alby_wallet = AlbyWallet(os.getenv("ALBY_BEARER_TOKEN"))
token_store = MemoryTokenStore()
client = L402Client(wallet=alby_wallet, store=token_store)

client = OpenAI(
    http_client=client,
    base_url='https://suluai.ln.sulu.sh/v1',
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    model="meta-llama/Llama-3-70b-chat-hf",
)
print(chat_completion.choices[0].message.content)

Contributions

Contributions are welcome! If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

Licensing

The code in this project is licensed under the MIT license. See LICENSE for details.

Disclaimer

This is an alpha release, and as such, it might contain bugs and incomplete features. We do not recommend using it in a production environment.

Metadata

Release files for pyl402 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyl402 0.1.2
File Size Uploaded Provenance Actions
pyl402-0.1.2.tar.gz 5.3 kB Without provenance Details for pyl402-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyl402 0.1.2
File Interpreter ABI Platform Actions
pyl402-0.1.2-py3-none-any.whl Python 3 none any Details for pyl402-0.1.2-py3-none-any.whl

Total release size: 12.4 kB

Release files / pyl402-0.1.2.tar.gz

Download URL pyl402-0.1.2.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c2c6739c7b879e50f52c7287b64e3291dc00f331f97fade10b985171e2936e3f
BLAKE2b-256 checksum
How to use checksums
65055fd5868417f88afcb7bbca63a3e2f47a84ed0dfbda7fe4a1c8c138dd89a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.12 Linux/5.15.146.1-microsoft-standard-WSL2

Release files / pyl402-0.1.2-py3-none-any.whl

Download URL pyl402-0.1.2-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e80e3afabc0ac82ba4d156d7c988b923599abc4bd7856f83fd6b7abc0f6a856
BLAKE2b-256 checksum
How to use checksums
9cd41cde7b9b8bb7971be8121ad612e31be6eb4c34e4c46b41aececef2d86843
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.12 Linux/5.15.146.1-microsoft-standard-WSL2

Security for pyl402 0.1.2

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.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page