A Cardano Kupo client for Python.
Project description
kupo-py
A Python client for interacting with Kupo, a lightweight and fast Cardano blockchain indexer. This client provides a simple and intuitive interface to query and interact with Kupo's HTTP API.
Features
- Asynchronous HTTP client for optimal performance
- Type-safe responses using Pydantic models
- Comprehensive API coverage
- Easy-to-use interface for common Kupo operations
Installation
pip install kupo-py
Quick Start
Setting up Kupo
Before using this client, you'll need to have a Kupo instance running. The easiest way to get started is using Docker:
docker run -d \
--name kupo \
-p 1442:1442 \
cardanosolutions/kupo:latest
For more detailed setup instructions and configuration options, please refer to the Kupo documentation.
Using the Client
from kupo import KupoClient
from kupo.models import Order, Limit, Point
# Initialize the client
client = KupoClient("http://localhost", 1442)
# Check the health of the API
health = await client.health_async()
print(f"API Health: {health}")
# Get matches for an address
matches = await client.get_matches_async(
pattern="addr1qxy2k...", # See pattern matching syntax below
policy_id="policy1...",
asset_name="asset1",
order=Order.DESC
)
for match in matches:
print(f"Found match: {match}")
Pattern Matching
Kupo uses a powerful pattern matching syntax to filter and match blockchain data. The pattern can be:
- A Cardano address
- A policy ID
- A script hash
- A datum hash
- A combination of these using the
*wildcard
For example:
addr1qxy2k...- Match a specific addresspolicy1...- Match a specific policy IDscript1...- Match a specific scriptdatum1...- Match a specific datumaddr1*- Match all addresses starting with "addr1"
For detailed pattern matching syntax and examples, see the Kupo Pattern Matching documentation.
Examples
Querying Matches
# Get all matches with filtering
matches = await client.get_all_matches_async(
spent=True, # Only get spent transactions
created_after=1000000, # Created after slot 1000000
order=Order.ASC # Oldest first
)
# Get matches for a specific address
matches = await client.get_matches_async(
pattern="addr1qxy2k...",
unspent=True, # Only get unspent UTxOs
policy_id="policy1..." # Filter by policy ID
)
Working with Scripts and Datums
# Get a script by its hash
script = await client.get_script_by_hash_async("script1...")
print(f"Script: {script}")
# Get a datum by its hash
datum = await client.get_datum_by_hash_async("datum1...")
print(f"Datum: {datum}")
# Get metadata for a transaction
metadata = await client.get_metadata_by_tx_async("tx1...")
print(f"Transaction metadata: {metadata}")
Managing Patterns
# Get all patterns
patterns = await client.get_patterns_async()
print(f"Active patterns: {patterns}")
# Add a new pattern
pattern = await client.add_pattern_async(
pattern="addr1qxy2k...",
rollback_to=Point(slot_no=1000000), # Rollback to specific slot
limit=Limit.SAFE
)
# Add multiple patterns at once
patterns = await client.bulk_add_pattern_async(
patterns=["addr1qxy2k...", "addr1qxy2k..."],
rollback_to={"slot_no": 1000000}
)
API Reference
For detailed API documentation, please refer to the Kupo documentation.
Contributing
Contributions are welcome! Please follow these guidelines when contributing:
Branch Naming
This project uses semantic versioning and automated version bumping based on branch names. When creating a new branch, please follow these naming conventions:
- For new features:
feat/your-feature-nameorfeature/your-feature-name- This will trigger a minor version bump when merged to dev
- For bug fixes:
fix/your-fix-nameorbugfix/your-fix-name- This will trigger a patch version bump when merged to dev
Development Workflow
- Create a new branch following the naming convention above
- Make your changes
- Submit a pull request to the
devbranch - Once merged, the version will be automatically bumped based on your branch name
- When ready for release, create a pull request from
devtomaster
Code Style
- Follow PEP 8 guidelines
- Use type hints
- Add docstrings for all public functions and classes
- Include tests for new functionality
Pre-commit Hooks
This project uses pre-commit hooks to ensure code quality and consistency. Before submitting a pull request:
-
Install pre-commit:
pip install pre-commit
-
Install the project's pre-commit hooks:
pre-commit install -
Run the pre-commit hooks on all files:
pre-commit run --all-files
-
Make sure all hooks pass before submitting your pull request.
The pre-commit hooks will check for:
- Code formatting (black)
- Import sorting (isort)
- Type checking (mypy)
- Linting (ruff)
- And other quality checks
Please feel free to submit a Pull Request!
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 kupo_py-0.1.2.tar.gz.
File metadata
- Download URL: kupo_py-0.1.2.tar.gz
- Upload date:
- Size: 101.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38c51ec66c3edb1d317de572f8a450ebca8e64db7cafa7ad5e4566f64544ba33
|
|
| MD5 |
0991a46a83e25f08ff0dd79ef8ad3390
|
|
| BLAKE2b-256 |
782a3a8cdafe38f96a606d2a7da9bf6710ce152f76a89d15ca98919ae0ae57b8
|
File details
Details for the file kupo_py-0.1.2-py3-none-any.whl.
File metadata
- Download URL: kupo_py-0.1.2-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7176ca83db045218ca346feae32135dc507a583b0a071719981ed16267e63b6a
|
|
| MD5 |
7015f1cd727a2f8aa9291fe03ff2994a
|
|
| BLAKE2b-256 |
99cdd15060591ba28aa6ad708192bb75c89a16eccbb9d616d18d9f9edd223922
|