Skip to main content

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

chaingrep-0.0.5.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

chaingrep-0.0.5-py2.py3-none-any.whl (10.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file chaingrep-0.0.5.tar.gz.

File metadata

  • Download URL: chaingrep-0.0.5.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.9

File hashes

Hashes for chaingrep-0.0.5.tar.gz
Algorithm Hash digest
SHA256 3ee66922ee965493a089bc3a3034e24dbfcfd40bd32f8ef746286dd4ee0d8bcd
MD5 8067a23ac0eeb9c91841d771f61dc12a
BLAKE2b-256 9e6dc24ff7dcf85ef6d404157ab5bc92f738eb7c48a9ae29b76b952d99141b1e

See more details on using hashes here.

File details

Details for the file chaingrep-0.0.5-py2.py3-none-any.whl.

File metadata

  • Download URL: chaingrep-0.0.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.9

File hashes

Hashes for chaingrep-0.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5396a475a7b2c31512ba4b0b4e08b1c8553789415bb420b40d6f27a482c69473
MD5 f1a887b9c592d785aea6de85e3f8a012
BLAKE2b-256 ac64816036fa28be0ab9976b3fb4312bcd469ebeb2a50fec863ff2a119f346db

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page