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.aiblock.dev',
    mempool_host='https://mempool.aiblock.dev',
    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.aiblock.dev',
    'storageHost': 'https://storage.aiblock.dev',
    'valenceHost': 'https://valence.aiblock.dev',
    '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.aiblock.dev"
LINEAGE_MEMPOOL_HOST="https://mempool.aiblock.dev"
LINEAGE_VALENCE_HOST="https://valence.aiblock.dev"

# 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.0.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.0-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lineage_sdk-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 be219db8840ac6b5469b2e59eafdb4b3eb5ebfee396838337addc727d533d05c
MD5 60b64056721f565d2f3936af736fe0b6
BLAKE2b-256 96de812fb27d505893497028b7f79f551a6bcb303c0fb7e946f1d2d8447750ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for lineage_sdk-1.0.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: lineage_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 38.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89cd8aee77a267172097bc01b487bddaf5cd07c249cbbaf4685ba411ace4e1e0
MD5 6b344598dfabb06282ea9503c7d589f5
BLAKE2b-256 9df485e35009c001fd7a8f25dcbaba0255a104c2533246429c799b8b16f862f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for lineage_sdk-1.0.0-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

1.0.1

2 files

This release

1.0.0 This release

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