Skip to main content

Compact Python library for interacting with Ankr's Advanced APIs.

Project description

⚓️ Ankr Python SDK

Compact Python library for interacting with Ankr's Advanced APIs.

Get started in 2 minutes

1. Install the package from PyPi

pip install ankr-sdk

2. Initialize the SDK

from ankr import AnkrWeb3

ankr_w3 = AnkrWeb3()

# Or, if you have an Ankr Protocol premium plan
ankr_w3 = AnkrWeb3("YOUR-TOKEN")

3. Use the sdk and call one of the supported methods

Node's API

eth_block = ankr_w3.eth.get_block("latest")
bsc_block = ankr_w3.bsc.get_block("latest")
polygon_block = ankr_w3.polygon.get_block("latest")

Ankr NFT API

from ankr.types import Blockchain

nfts = ankr_w3.nft.get_nfts(
    blockchain=[Blockchain.ETH, Blockchain.BSC],
    wallet_address="0x0E11A192d574b342C51be9e306694C41547185DD",
    filter=[
        {"0x700b4b9f39bb1faf5d0d16a20488f2733550bff4": []},
        {"0xd8682bfa6918b0174f287b888e765b9a1b4dc9c3": ["8937"]},
    ],
)

Ankr Token API

assets = ankr_w3.token.get_account_balance(
    wallet_address="0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527"
)

Ankr Query API

logs = ankr_w3.query.get_logs(
    blockchain="eth",
    from_block="0xdaf6b1",
    to_block=14350010,
    address=["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"],
    topics=[
        [],
        ["0x000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff"],
    ],
    decode_logs=True,
)

Ankr Advanced APIs supported chains

ankr-sdk supports the following chains at this time:

  • ETH: "eth"
  • BSC: "bsc"
  • Polygon: "polygon"
  • Fantom: "fantom"
  • Arbitrum: "arbitrum"
  • Avalanche: "avalanche"
  • Syscoin NEVM: "syscoin"

Available methods

ankr-sdk supports the following methods:

get_nfts

Get data about all the NFTs (collectibles) owned by a wallet.

nfts = ankr_w3.nft.get_nfts(
    blockchain="eth",
    wallet_address="0x0E11A192d574b342C51be9e306694C41547185DD",
    filter=[
        {"0x700b4b9f39bb1faf5d0d16a20488f2733550bff4": []},
        {"0xd8682bfa6918b0174f287b888e765b9a1b4dc9c3": ["8937"]},
    ],
)

get_nft_metadata

Get metadata of NFT.

nfts = ankr_w3.nft.get_nft_metadata(
    blockchain="eth",
    contract_address="0x4100670ee2f8aef6c47a4ed13c7f246e621228ec",
    token_id="4",
)

get_token_holders

Get holders of a token.

holders = ankr_w3.token.get_token_holders(
    blockchain="bsc",
    contract_address="0xf307910A4c7bbc79691fD374889b36d8531B08e3",
    limit=10,
)

get_token_holders_count_history

Get token holders count daily history.

daily_holders_history = ankr_w3.token.get_token_holders_count_history(
    blockchain="bsc",
    contract_address="0xf307910A4c7bbc79691fD374889b36d8531B08e3",
    limit=10,  # last 10 days history
)

get_token_holders_count

Get token holders count at the latest block.

holders_count = ankr_w3.token.get_token_holders_count(
    blockchain="bsc",
    contract_address="0xf307910A4c7bbc79691fD374889b36d8531B08e3",
)

get_account_balance

Get account assets.

assets = ankr_w3.token.get_account_balance(
    wallet_address="0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527",
    blockchain=["eth", "bsc"],
)

get_logs

Get logs matching the filter.

logs = ankr_w3.query.get_logs(
    blockchain="eth",
    from_block="0xdaf6b1",
    to_block=14350010,
    address=["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"],
    topics=[
        [],
        ["0x000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff"],
    ],
    decode_logs=True,
)

get_blocks

Query data about blocks within a specified range.

blocks = ankr_w3.query.get_blocks(
    blockchain="eth",
    from_block=14500001,
    to_block=14500001,
    desc_order=True,
    include_logs=True,
    include_txs=True,
    decode_logs=True,
)

get_transaction

Get Transaction by hash.

tx = ankr_w3.query.get_transaction(
    transaction_hash="0x82c13aaac6f0b6471afb94a3a64ae89d45baa3608ad397621dbb0d847f51196f",
    include_logs=True,
    decode_logs=True,
    decode_tx_data=True,
)

About API keys

For now, Ankr is offering free access to these APIs with no request limits i.e. you don't need an API key at this time.

Later on, these APIs will become a part of Ankr Protocol's Premium Plan.

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

ankr_sdk-0.3.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ankr_sdk-0.3.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file ankr_sdk-0.3.0.tar.gz.

File metadata

  • Download URL: ankr_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.11.2 Linux/5.15.0-1034-azure

File hashes

Hashes for ankr_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8aff82c461dbc2e3c2ad9f2524958c1313561695b2beb26ef103143e158574a5
MD5 bb96ce5c7f6b73ddf3dc6fcd70413d02
BLAKE2b-256 72e33d26d179c7caa19d572965e77804cbb511c9f00ea703c56e8084c27feb8d

See more details on using hashes here.

File details

Details for the file ankr_sdk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ankr_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.11.2 Linux/5.15.0-1034-azure

File hashes

Hashes for ankr_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e2f38f67bfc2cc4ec9c195a556c3bb8d8e62d881befd39325be07a1edc26866
MD5 91663ec47852d8ccb34a49aa0a552edc
BLAKE2b-256 f55199a6f20c2ee5c1e17cab494dc9d827b8370a047c58909d69310bd70b7868

See more details on using hashes here.

Supported by

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