attopy package
A Python interface for the Atto node API.
This module includes the synchronous client AttoClient (for interacting with the API) as well as utility classes and functions that may be needed during this interaction.
Typical usage example:
ADDRESS = 'atto://ad7z3jdoeqwayzpaiafizb5su6zc2fyvbeg2wq5t3yfj3q5iuprx23z437juk'
with AttoClient() as atto_client:
account = atto_client.get_account(ADDRESS)
# print first 100 transactions
print('Hash\tAmount')
for entry in atto_client.entries_stream(account,
from_height=1,
to_height=100,
timeout=None):
print(f'{entry.hash_[0:3]}...\t{entry.amount}')
Although this documentation should be sufficient, an API reference exists.
Submodules
attopy.Account module
The Account class definition.
attopy.AttoClient module
The AttoClient class definition.
- class attopy.AttoClient.AttoClient(base_url='https://h.tail006b6.ts.net/api', **kwargs)[source]
Bases:
objectA synchronous connection to an Atto Node.
The class methods directly correspond to API endpoints.
Because they are synchronous, all methods, including the generators, block the thread that they’re called in.
Typical usage example:
with AttoClient() as atto_client: account = atto_client.get_account(PUBLIC_KEY) # print first 100 transactions print('Hash\tAmount') for entry in atto_client.entries_stream(account, from_=1, to=100, timeout=None): print(f'{entry.hash_[0:3]}...\t{entry.amount}')
- base_url
the node API’s base URL
- account(account, *args, stream=False, **kwargs)[source]
Return an up-to-date Account object
- Parameters:
account – an Account object, an address (with or without the
atto – // protocol prefix) or a bytestring derived from the account
name
(using (with the version and checksum omitted)
address_to_key
- close()[source]
Close the client connection.
When used as a context generator, this is called automatically upon exiting the context.
- instants(instant=None)[source]
Return time information about the client and the server.
- Parameters:
instant – A datetime object. Defaults to datetime.now().
- Returns:
A dataclass containing the date and time of the client (client_instant), the date and time of the server (server_instant) and the time delta between the client and the server (difference).
attopy.Block module
The Block class definition.
attopy.Entry module
The Entry class definition.
attopy.Receivable module
The Receivable class definition.
attopy.Transaction module
The Transaction class definition.
attopy.boilerplate module
attopy.convert module
Conversion functions between the API’s types and our types
- attopy.convert.address_to_key(address_without_protocol)[source]
Convert an address into a public key.
Addresses are base32-encoded strings that start with atto://. Public keys are the decoded form, with the version and checksum removed.
Client API functions accept public keys, not addresses. Similarly, accounts returned from API functions contain public keys, not addresses.
- Parameters:
address – An address (which typically starts with atto://), with atto:// removed. The protocol (atto://) can be removed from an address using
address.removeprefix('atto://').- Returns:
A public key in the form of a binary string that can be passed to the Atto.py client API functions.
attopy.field_types module
Enum versions of strings from the API
String values correspond to strings received from the API.