Skip to main content

Lineage Python SDK

Python SDK for interacting with the Lineage blockchain. This SDK provides a simple interface for wallet operations and blockchain queries.

Installation

pip install lineage-sdk

The distribution is published as lineage-sdk; the import name is lineage:

import lineage

Quick Start

Basic Blockchain Queries

from lineage.blockchain import BlockchainClient

# Initialize blockchain client. api_key is optional and, when set, is sent
# as the x-api-key header on every request.
client = BlockchainClient(
    storage_host='https://storage.lineage.to',
    mempool_host='https://mempool.lineage.to',
    api_key='your-api-key'
)

# Query blockchain
latest_block = client.get_latest_block()
if latest_block.is_ok:
    print(f"Latest block: {latest_block.get_ok()['content']['block_num']}")

# Get specific block by number
block = client.get_block_by_num(1)
if block.is_ok:
    print(f"Block 1: {block.get_ok()['content']}")

# Get blockchain entry by hash
entry = client.get_blockchain_entry('some_hash')

# Get transaction by hash
transaction = client.get_transaction_by_hash('tx_hash')

# Get multiple transactions
transactions = client.fetch_transactions(['hash1', 'hash2'])

# Get supply information (requires mempool host) - returns {total, issued}
total_supply = client.get_total_supply()
issued_supply = client.get_issued_supply()

Wallet Operations

from lineage.wallet import Wallet

# Create wallet
wallet = Wallet()

# Generate seed phrase
seed_phrase = wallet.generate_seed_phrase()
print(f"Seed phrase: {seed_phrase}")

# Initialize wallet from seed. apiKey is optional and, when set, is sent
# as the x-api-key header on every mempool request.
config = {
    'passphrase': 'your-secure-passphrase',
    'mempoolHost': 'https://mempool.lineage.to',
    'storageHost': 'https://storage.lineage.to',
    'valenceHost': 'https://valence.lineage.to',
    'apiKey': 'your-api-key'
}

result = wallet.from_seed(seed_phrase, config)
if result.is_ok:
    print(f"Wallet address: {wallet.get_address()}")
else:
    print(result.error, result.error_message)

# Check balance - fetch_balance returns {balance: {address: {...}}}
balance_result = wallet.fetch_balance([wallet.current_keypair.address])
if balance_result.is_ok:
    print(balance_result.get_ok())

# Create an item asset via POST /v1/items. On success this returns
# {asset, to_address, tx_hash}.
item_result = wallet.create_item_asset(
    secret_key=wallet.current_keypair.secret_key,
    public_key=wallet.current_keypair.public_key,
    amount=1
)
if item_result.is_ok:
    print(item_result.get_ok())

# Send a payment. This builds and signs a real UTXO transaction client-side
# (the same construction as sdk-js) and submits it via POST /v1/transactions.
# On success this returns {transaction_hash, payment_address, asset, used_addresses}.
payment_result = wallet.create_transactions(
    destination_address='recipient-address',
    amount=100
)
if payment_result.is_ok:
    print(payment_result.get_ok())

Features

Blockchain Client

  • get_latest_block() - Get the latest block information
  • get_block_by_num(block_num) - Get a specific block by number
  • get_blockchain_entry(hash) - Get blockchain entry by hash
  • get_transaction_by_hash(tx_hash) - Get transaction details
  • fetch_transactions(tx_hashes) - Get multiple transactions
  • get_total_supply() - Get total token supply
  • get_issued_supply() - Get issued token supply

Wallet Operations

  • Generate and manage seed phrases
  • Create and manage keypairs
  • Construct and submit real, client-signed transactions (payments)
  • Create item assets
  • Check balances
  • Two-way payment protocol support (via the separate valence service)

All of the above talk to the /v1 REST API on the mempool/storage hosts. Reads and writes go through lineage/blockchain.py's shared transport, which maps application/problem+json error bodies onto the SDK's IResult error types. The 2-way payment flow (make_2way_payment, fetch_pending_2way_payments, accept_2way_payment, reject_2way_payment) is unrelated to /v1 - it talks to the valence node directly and its wire format hasn't changed.

create_transactions now does real work: it fetches the current balance for the spending addresses, selects UTXOs, builds and signs a CreateTransaction the same way sdk-js does, and submits it to POST /v1/transactions. Previously this only produced a signed payload without ever confirming it reached the network - callers who relied on the old behaviour should check payment_result.get_ok()['transaction_hash'] to confirm the payment was actually accepted.

Configuration

The SDK uses environment variables for configuration. Create a .env file:

LINEAGE_PASSPHRASE="your-secure-passphrase"
LINEAGE_STORAGE_HOST="https://storage.lineage.to"
LINEAGE_MEMPOOL_HOST="https://mempool.lineage.to"
LINEAGE_VALENCE_HOST="https://valence.lineage.to"

# Optional - sent as the x-api-key header on every /v1 request
LINEAGE_API_KEY="your-api-key"

Error Handling

All methods return IResult objects with proper error handling:

result = client.get_latest_block()
if result.is_ok:
    data = result.get_ok()
    print(f"Success: {data}")
else:
    print(result.error, result.error_message)

Development

  1. Clone the repository
  2. Install uv (https://docs.astral.sh/uv/)
  3. Run tests: uv pip install -q pytest requests-mock && uv run pytest -q

The suite is offline by default; tests marked integration talk to a live network and are excluded from the default run.

Documentation

Links

Contributing

See CONTRIBUTING.md.

License

MIT – see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lineage_sdk-1.0.1.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

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

lineage_sdk-1.0.1-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

Details for the file lineage_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: lineage_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lineage_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3e0f44ad20c8d1a9a86cf74ec874d62a38a61535281b9d5c3f506ed066f873f0
MD5 889503053f9743d648388203ff5b8211
BLAKE2b-256 40170e65747dea7a627f6b113031e00458d703712708ffb60997e3882a79b702

See more details on using hashes here.

Provenance

The following attestation bundles were made for lineage_sdk-1.0.1.tar.gz:

Publisher: publish.yml on lineage-foundation/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lineage_sdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: lineage_sdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 38.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lineage_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db97aa396fb497f847b50cd770f3a8f7fd33409521bf74e31225d432909be0b5
MD5 aa9f55401c0951af04db1cd45f4ad54d
BLAKE2b-256 08e2576b51e6393357807cb18d541ab79af06d45f52374d0d3ea30672a1fc692

See more details on using hashes here.

Provenance

The following attestation bundles were made for lineage_sdk-1.0.1-py3-none-any.whl:

Publisher: publish.yml on lineage-foundation/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

2 files

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