Python bindings for the Chaingrep API
Project description
Chaingrep Python Library
The Chaingrep Python library provides convenient access to the Chaingrep API from applications written in Python.
Documentation
See the Chaingrep docs.
Installation
You don't need this source code unless you want to modify the package. If you want to use the package, just run:
pip install chaingrep
Install from source with:
python setup.py install
Requirements
- Python 3.6+
Usage
The library needs to be instantiated with your Chaingrep API key. Here's are a few examples of how the library can be used:
from chaingrep import Chaingrep
from datetime import datetime, timedelta
chaingrep = Chaingrep("<API_KEY>")
# Parse a transaction
transaction = chaingrep.transaction("0xc4fd8359894ad78b04a5cd784106bcf6c413db8372492e744433533abc848ac6").parse()
print(transaction.transaction_type)
# Parse an account's transactions
account_transactions = chaingrep.account("0xa4722f1b4B552951828e6A334C5724b34B19A327").parse_transactions()
for transaction in account_transactions:
print(transaction.time.timeago)
# Query all interactions between an account and a contract in the past month
target_account = "0xa4722f1b4B552951828e6A334C5724b34B19A327" # Me
target_contract = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" # USDC
current_datetime = datetime.utcnow()
past_datetime = current_datetime - timedelta(days=30) # One month ago
# Construct the query
query = chaingrep.query()
query.query({
"account": target_account,
"contract": target_contract
})
query.timeframe(past_datetime, current_datetime)
# Return a count
interactions_count = query.count()
# Return results
interactions = query.execute()
Handling exceptions
Unsuccessful requests raise exceptions. The class of the exception will reflect the sort of error that occurred, and the error message will provide more context. See Exceptions for more.
from chaingrep import Chaingrep
chaingrep = Chaingrep("<API_KEY>")
transaction = chaingrep.transaction("not_a_valid_hash").parse()
# InvalidTransactionHashError: <error message>
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
Built Distribution
File details
Details for the file chaingrep-0.0.6.tar.gz
.
File metadata
- Download URL: chaingrep-0.0.6.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cedbf45598b0d2e4dd1e427cb55536cd833694df421c2e298880f8bc7998868 |
|
MD5 | 87176cd59f8c5ea5ac15eb00a0372278 |
|
BLAKE2b-256 | a2c26b83d3c1355dfa2065d462ebe14dd4f8ddc181afbdce4b177227cbb1a0db |
File details
Details for the file chaingrep-0.0.6-py2.py3-none-any.whl
.
File metadata
- Download URL: chaingrep-0.0.6-py2.py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6624b4b5d991ef6c38fec75263228e1278dfe6b815019a6e9b22299dd547e59 |
|
MD5 | b90b511fd7edfba561f1d4302ea0d00e |
|
BLAKE2b-256 | 9644e5528b47f81a4add09f2eda84556d862a06de4997093b5d1cb7a51614c06 |