Python client for interacting with the Lotus JSON-RPC API.
Project description
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 a Lotus node from your Python applications.
This codebase is still a WIP, all of the Filecoin.StateXXXX calls have been implemented, but others are being added slowly over time.
Installation
Installation from PyPi
pip install pylotus-rpc
Here are the usage instructions for the LotusClient
class and its methods in your Python code, which interacts with an API for blockchain data management:
LotusClient Usage Instructions
The LotusClient
class in Python allows interaction with a blockchain API to manage data related to blocks, transactions, and various state-related information.
Initializing the HttpJsonRpcConnector
Before you can use the LotusClient
, you must set up an HttpJsonRpcConnector
to handle the communication with the API server. Here's how you can initialize this connector:
Constructor Parameters
- host: The server's hostname or IP address. The default is 'http://localhost/rpc/v0'.
- port: The server's port. If not specified, it will try to use the port from the parsed host URL or default to
None
. - api_token: The API token for authentication. This should be provided if the server requires authentication.
Example Initialization
from pylotus_rpc import HttpJsonRpcConnector
# Example with default local host and no authentication
connector = HttpJsonRpcConnector()
# Example with specific host, port, and an API token
connector = HttpJsonRpcConnector(
host='http://your_api_server_address/rpc/v0',
port=1234,
api_token='your_api_token_here'
)
Notes
- Ensure the host includes the protocol (http or https) and any necessary API path.
- The port should match the server configuration where the API is accessible.
- The api_token is crucial for accessing APIs that require secure authentication.
Once the connector is properly configured, you can use it to initialize your LotusClient
and start making API calls to interact with the blockchain.
Initializing the LotusClient
Using an instance of HttpJsonRpcConnector
you can then initialize the LotusClient
with this connector.
from pylotus_rpc import LotusClient, HttpJsonRpcConnector
connector = HttpJsonRpcConnector(api_url='https://api.example.com')
client = LotusClient(connector)
Using Chain Methods
You can fetch block messages, tipsets, and other block-related data using the Chain
class.
# Fetch block messages by CID
block_messages = client.Chain.get_block_messages(block_cid='your_block_cid_here')
# Get specific tipset
tipset = client.Chain.get_tip_set(tipset_key=[{'/': 'your_tipset_key_here'}])
# Fetch the chain head
chain_head = client.Chain.get_chain_head()
# Get specific block information
block_info = client.Chain.get_block(cid='your_block_cid_here')
# Read object data by CID
object_data = client.Chain.read_obj(cid='your_block_cid_here')
Using State Methods
The State
class provides methods to access detailed node, sector, and state information.
# Wait for a message with specified CID, confidence, and limit
message_lookup = client.State.wait_msg_limited(cid='your_cid_here', confidence=3, limit=100)
# Fetch the status of a verifier in the blockchain
verifier_status = client.State.verifier_status(address='your_verifier_address_here')
# Get miner power details
miner_power = client.State.miner_power(address='your_miner_address_here')
# List all active sectors for a miner
active_sectors = client.State.miner_active_sectors(address='your_miner_address_here')
Each of these methods interacts with the blockchain to retrieve or manage data based on your specific needs.
Error Handling
Always handle potential exceptions from network issues or data errors:
try:
block_info = client.Chain.get_block(cid='your_block_cid_here')
except Exception as e:
print(f"An error occurred: {e}")
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.
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
File details
Details for the file pylotus_rpc-0.4.tar.gz
.
File metadata
- Download URL: pylotus_rpc-0.4.tar.gz
- Upload date:
- Size: 37.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab9d5903ff87fbb4536d4b7dcc06f42f904ff55879d1c78bfceea7c29bb69502 |
|
MD5 | 869f8f32c1c46f3e7f821177db97d512 |
|
BLAKE2b-256 | 747a024357705b45b7ee729bf5afb4b69e719946a85b5e24018311271de09f58 |
File details
Details for the file pylotus_rpc-0.4-py3-none-any.whl
.
File metadata
- Download URL: pylotus_rpc-0.4-py3-none-any.whl
- Upload date:
- Size: 48.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdc218d1edd26d3e4ca556d96cc252716e3ac9ed57d6152c31cc2aa055522e1f |
|
MD5 | 2cb59557b193a12ea661939d53ac8b1b |
|
BLAKE2b-256 | 7e8b82f4fe50c3e9d3f171f1584fbb56c6d073632756eff5e778ffcfb2d30771 |