Skip to main content

Official Python SDK for the Luzia cryptocurrency pricing API

Project description

luziadev

Official Python SDK for the Luzia cryptocurrency pricing API.

Installation

pip install luziadev

For WebSocket support:

pip install luziadev[websocket]

Quick Start

import asyncio
from luziadev import Luzia

async def main():
    async with Luzia("lz_your_api_key") as client:
        # Get a single ticker
        ticker = await client.tickers.get("binance", "BTC/USDT")
        print(f"BTC/USDT: ${ticker.last}")

        # List all exchanges
        exchanges = await client.exchanges.list()
        for exchange in exchanges:
            print(f"{exchange.name} ({exchange.status})")

        # Get multiple tickers
        result = await client.tickers.list_filtered(
            exchange="binance",
            symbols=["BTC/USDT", "ETH/USDT"],
        )
        for t in result.tickers:
            print(f"{t.symbol}: ${t.last}")

        # Get OHLCV candles
        ohlcv = await client.history.get(
            "binance", "BTC/USDT",
            interval="1h",
            limit=24,
        )
        for candle in ohlcv.candles:
            print(f"{candle.timestamp}: O={candle.open} H={candle.high} L={candle.low} C={candle.close}")

        # List markets
        markets = await client.markets.list("binance", quote="USDT", limit=10)
        for market in markets.markets:
            print(f"{market.symbol} (active={market.active})")

asyncio.run(main())

WebSocket Streaming

import asyncio
from luziadev import Luzia

async def main():
    client = Luzia("lz_your_api_key")
    ws = client.create_websocket()

    ws.on("connected", lambda data: print(f"Connected! Max subs: {data['limits']['maxSubscriptions']}"))
    ws.on("ticker", lambda data: print(f"{data['data']['symbol']}: ${data['data']['last']}"))
    ws.on("error", lambda data: print(f"Error: {data['message']}"))
    ws.on("reconnecting", lambda data: print(f"Reconnecting (attempt {data['attempt']})..."))

    await ws.connect()

    ws.subscribe(["ticker:binance:BTC-USDT", "ticker:binance:ETH-USDT"])

    # Keep running
    try:
        await asyncio.sleep(3600)
    finally:
        ws.disconnect()
        await client.close()

asyncio.run(main())

Error Handling

from luziadev import Luzia, LuziaError

async with Luzia("lz_your_api_key") as client:
    try:
        ticker = await client.tickers.get("binance", "BTC/USDT")
    except LuziaError as e:
        match e.code:
            case "rate_limit":
                print(f"Rate limited. Retry after {e.retry_after}s")
            case "auth":
                print("Invalid API key")
            case "not_found":
                print("Symbol not found")
            case "timeout":
                print(f"Timed out after {e.timeout_ms}ms")
            case _:
                print(f"Error [{e.code}]: {e}")

Retry Configuration

from luziadev import Luzia, RetryOptions

client = Luzia(
    "lz_your_api_key",
    retry=RetryOptions(
        max_retries=5,
        initial_delay_ms=500,
        max_delay_ms=10000,
        backoff_multiplier=2.0,
        jitter=True,
    ),
)

Rate Limit Info

ticker = await client.tickers.get("binance", "BTC/USDT")

info = client.rate_limit_info
if info:
    print(f"Remaining: {info.remaining}/{info.limit}")
    print(f"Resets at: {info.reset}")

Development

Setup

cd packages/python-sdk
uv sync --extra dev --extra websocket

Running Tests

# Run all tests
uv run pytest

# Run with verbose output
uv run pytest -v

# Run a specific test file
uv run pytest tests/test_client.py

# Run a specific test
uv run pytest tests/test_client.py::test_auth_header_sent

Publishing to PyPI

  1. Build the package:
uv build

This creates dist/luziadev-X.Y.Z.tar.gz (sdist) and dist/luziadev-X.Y.Z-py3-none-any.whl (wheel).

  1. Upload to Test PyPI (optional, to verify first):
uv publish --index-url https://test.pypi.org/legacy/
  1. Upload to PyPI:
uv publish

You will be prompted for your PyPI credentials. To use an API token instead, pass --token pypi-YOUR_TOKEN.

Versioning

Update the version in two places before publishing:

  • pyproject.tomlversion
  • src/luziadev/__init__.py__version__

Requirements

  • Python 3.10+
  • httpx (installed automatically)
  • websockets (optional, for WebSocket support)

License

MIT

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

luziadev-0.1.0.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

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

luziadev-0.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file luziadev-0.1.0.tar.gz.

File metadata

  • Download URL: luziadev-0.1.0.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for luziadev-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ea07581ff92951b1cfb4dd9e33065d9bbd6bfe94a70921be0d23dfe97cbcfc0
MD5 85a9d4c59a7debbf6b225edd1dc4ad20
BLAKE2b-256 3bfb70f03194b03ab55bd27a1ff59fd3dffd9a98bf609ed5ea9c38d1b5a82ffd

See more details on using hashes here.

File details

Details for the file luziadev-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: luziadev-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for luziadev-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74a6060371ec22a9c6aa840836fa61cd6ad307b27adbbe113f7dce3cf5e7c550
MD5 e4acffe5e86ca1a9c265fbe3e65ac515
BLAKE2b-256 5e03498beb8d8ecce6bd247f76cabef45ae3e6d738b931a391bd5329b5541b78

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