near-tokens
Python async client for NEAR Protocol token operations and account queries.
Requirements
Python 3.9+
Installation
pip install near-tokens
Quick Start
import asyncio from near_tokens import NearTokensClient
async def main(): async with NearTokensClient() as client: balance = await client.get_balance("alice.near") print(f"Balance: {balance['balance_near']:.4f} NEAR")
asyncio.run(main())
Usage
Account Balance
import asyncio from near_tokens import NearTokensClient
async def main(): async with NearTokensClient() as client: balance = await client.get_balance("wrap.near") print(balance["balance_near"]) print(balance["balance_yocto"]) print(balance["storage_usage"])
asyncio.run(main())
Check Account Exists
import asyncio from near_tokens import NearTokensClient
async def main(): async with NearTokensClient() as client: exists = await client.account_exists("alice.near") print(exists) # True or False
asyncio.run(main())
Block and Gas Price
import asyncio from near_tokens import NearTokensClient
async def main(): async with NearTokensClient() as client: block = await client.get_block() gas_price = await client.get_gas_price() print(block, gas_price)
asyncio.run(main())
Fungible Token (FT) Queries
import asyncio from near_tokens import NearTokensClient
async def main(): async with NearTokensClient() as client: metadata = await client.get_ft_metadata("usdt.tether-token.near") ft_balance = await client.get_ft_balance("usdt.tether-token.near", "alice.near") print(metadata) print(ft_balance)
asyncio.run(main())
Validators
import asyncio from near_tokens import NearTokensClient
async def main(): async with NearTokensClient() as client: validators = await client.get_validators() print(validators)
asyncio.run(main())
Manual Session Management
import asyncio from near_tokens import NearTokensClient
async def main(): client = NearTokensClient(rpc_url="https://rpc.mainnet.near.org") balance = await client.get_balance("alice.near") print(balance) await client.close()
asyncio.run(main())
API Reference
| Method | Description |
|---|---|
get_balance(account_id) |
NEAR balance in yoctoNEAR and NEAR |
account_exists(account_id) |
Returns True if account exists |
get_block() |
Latest finalized block info |
get_gas_price() |
Current gas price |
get_ft_balance(contract_id, account_id) |
Fungible token balance |
get_ft_metadata(contract_id) |
Fungible token metadata |
get_validators() |
Current epoch validators |
close() |
Close the HTTP session |
License
MIT
Metadata
Release files for near-tokens 1.0.6883
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| near_tokens-1.0.6883.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| near_tokens-1.0.6883-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.3 kB
Release files / near_tokens-1.0.6883.tar.gz
| Download URL | near_tokens-1.0.6883.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d855985d157d0c4d17e8514bb9391f2eb162e6f649f49b69452ec4215d5e883
|
|
BLAKE2b-256 checksum How to use checksums |
89b85d7125ff8345ca0630bc6323e764da9c5ae1caef2fc3683cc2aa186ad899
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / near_tokens-1.0.6883-py3-none-any.whl
| Download URL | near_tokens-1.0.6883-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
793bd120b7ef227c2b32a2fc19f64346b62d15d1f4031f26868a67e9ed679142
|
|
BLAKE2b-256 checksum How to use checksums |
3a74ed618375290e9654b4e2cfd7dcbddcedaec3b6d1233f53d70f42ba1a2883
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|