graphsense / graphsense-python

A Python client for the GraphSense REST interface.
MIT License
19 stars 3 forks source link

Transparent handling of address chunks #7

Closed behas closed 2 years ago

behas commented 3 years ago

At the moment, list_addresses supports retrieval of up to 1000 (?) addresses per request, which means larger set must be divided in chunks on the client side before. See example below.

Transparent handling of chunks would certainly improve API usability.

# Yield successive n-sized
# chunks from l.
def divide_chunks(l, n):

    # looping till length l
    for i in range(0, len(l), n): 
        yield l[i:i + n]

address_chunks = list(divide_chunks(df['address'].values.tolist(), 1000))

with graphsense.ApiClient(configuration) as api_client:
    api_instance = addresses_api.AddressesApi(api_client)
    try:
        # Iterate over all chunks
        for chunk in address_chunks:
            # Retrieve all addresses in batch
            addresses = api_instance.list_addresses(CURRENCY, ids=chunk)
            for a in addresses.addresses:
                address_details[a.address] = a
            print("Finished chunk")
    except graphsense.ApiException as e:
        print("Exception when calling AddressesApi: %s\n" % e)
myrho commented 2 years ago

obsolete due to new bulk endpoint