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.

class attopy.Account.Account(dict_, client)[source]

Bases: object

entries(*args, **kwargs)[source]
get(*args, **kwargs)[source]
receivables(*args, **kwargs)[source]
stream(*args, **kwargs)[source]
transactions(*args, **kwargs)[source]

attopy.AttoClient module

The AttoClient class definition.

class attopy.AttoClient.AttoClient(base_url='https://h.tail006b6.ts.net/api', **kwargs)[source]

Bases: object

A 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.

entries(account=None, *args, from_=None, to=4294967295, stream=True, **kwargs)[source]
entry(hash_, *args, stream=False, **kwargs)[source]
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).

receivables(account, *args, min_amount=1, stream=True, **kwargs)[source]
transaction(hash_, *args, stream=False, **kwargs)[source]
transactions(account=None, *args, from_=None, to=None, stream=True, **kwargs)[source]

attopy.Block module

The Block class definition.

class attopy.Block.Block(dict_)[source]

Bases: object

attopy.Entry module

The Entry class definition.

class attopy.Entry.Entry(dict_, client)[source]

Bases: object

stream(*args, **kwargs)[source]

attopy.Receivable module

The Receivable class definition.

class attopy.Receivable.Receivable(dict_, client)[source]

Bases: object

attopy.Transaction module

The Transaction class definition.

class attopy.Transaction.Transaction(dict_, client)[source]

Bases: object

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.

class attopy.field_types.Algorithm(value)[source]

Bases: StrEnum

V1 = 'V1'
class attopy.field_types.BlockType(value)[source]

Bases: StrEnum

CHANGE = 'CHANGE'
OPEN = 'OPEN'
RECEIVE = 'RECEIVE'
SEND = 'SEND'
class attopy.field_types.Network(value)[source]

Bases: StrEnum

BETA = 'BETA'
DEV = 'DEV'
LIVE = 'LIVE'
TEST = 'TEST'