PyLotus-RPC
PyLotus-RPC is a Python client library for interacting with the Lotus JSON-RPC API. It provides a convenient way to communicate with Filecoin nodes from your Python applications.
This codebase is still a WIP. All Filecoin.StateXXXX, Filecoin.ChainXXX, and Filecoin.NetXXX calls have been implemented. Other methods are being added over time.
Installation
pip install pylotus-rpc
Quick Start
The LotusClient provides access to Filecoin blockchain data through Chain, State, and Net APIs. All methods require an HttpJsonRpcConnector for communication with Lotus nodes.
Basic Setup
from pylotus_rpc import LotusClient, HttpJsonRpcConnector
# Connect to a public Filecoin node
connector = HttpJsonRpcConnector(host='https://api.node.glif.io/rpc/v0')
client = LotusClient(connector)
# Or connect to your local Lotus node with authentication
connector = HttpJsonRpcConnector(
host='http://localhost:1234/rpc/v0',
api_token='your_lotus_api_token'
)
client = LotusClient(connector)
Chain Methods
Access blockchain data including blocks, tipsets, and messages.
# Get the current chain head
chain_head = client.Chain.head()
print(f"Current height: {chain_head.height}")
# Get a specific block by CID
block_cid = "bafy2bzacedkoa5xstphncs3da4d6kpbdvbxlg5zkfgxsxhpbcsfmzfhtm7v3y"
block = client.Chain.get_block(cid=block_cid)
# Get messages in a block
block_messages = client.Chain.get_block_messages(block_cid=block_cid)
# Get a tipset by keys
tipset_key = [{'/': block_cid}]
tipset = client.Chain.get_tip_set(tipset_key=tipset_key)
# Read raw object data
object_data = client.Chain.read_obj(cid=block_cid)
State Methods
Query Filecoin network state including miner information, deals, and verifiers.
# Get miner power and information
miner_address = "f01000"
miner_power = client.State.miner_power(address=miner_address)
miner_info = client.State.miner_info(address=miner_address)
# Get active sectors for a miner
active_sectors = client.State.miner_active_sectors(address=miner_address)
# Wait for message confirmation
message_cid = "bafy2bzacedq..."
message_lookup = client.State.wait_msg_limited(
cid=message_cid,
confidence=3,
limit=100
)
# Check verifier status
verifier_address = "f1..."
verifier_status = client.State.verifier_status(address=verifier_address)
# Get network version and genesis info
network_version = client.State.network_version()
genesis = client.Chain.get_genesis()
Network Methods
Monitor and manage network connections, bandwidth, and peer information.
# Get network statistics
stats = client.Net.stat(scope="system")
print(f"Total bandwidth in: {stats['TotalIn']}")
# Get address information
addr_info = client.Net.addrs_listen()
print(f"Listening addresses: {addr_info}")
# Check NAT status
nat_info = client.Net.auto_nat_status()
# Set network limits (requires write permissions)
limits = {
"Memory": 1024 * 1024 * 1024, # 1GB
"Streams": 100
}
success = client.Net.set_limit("libp2p", limits)
Error Handling
Handle API errors using the specific ApiCallError exception:
from pylotus_rpc.http_json_rpc_connector import HttpJsonRpcConnector
ApiCallError = HttpJsonRpcConnector.ApiCallError
try:
block_info = client.Chain.get_block(cid="invalid_cid")
except ApiCallError as e:
print(f"API call failed: {e.method} - {e.message} (code: {e.code})")
except Exception as e:
print(f"Unexpected error: {e}")
Filecoin Concepts
- CID: Content Identifier, a unique hash identifying blocks, messages, and data
- Tipset: A set of blocks at the same height in the blockchain
- Miner: Storage provider in the Filecoin network
- Sector: Unit of storage committed by miners
- Message: Transactions and state changes in Filecoin
License:
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Metadata
Release files for pylotus-rpc 3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pylotus_rpc-3.0.tar.gz | 6.1 MB | Without provenance | Details for pylotus_rpc-3.0.tar.gz |
Release files / pylotus_rpc-3.0.tar.gz
| Download URL | pylotus_rpc-3.0.tar.gz |
|---|---|
| Size | 6.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f8ba1c5cdc2935073f826dadbb664718544e2033288268e8a937649fff76566
|
|
BLAKE2b-256 checksum How to use checksums |
3a80742b960f1bf7146dc20161a622c98e9ad1d40e0e8530beeacab10186825b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Security for pylotus-rpc 3.0
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.