Metadata-Version: 2.1
Name: hypersync
Version: 0.0.2
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
License-File: LICENSE
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# hypersync-client-python
Python package for [Envio's](https://envio.dev/) HyperSync client written in Rust

### Example usage
```python
import hypersync
import asyncio

async def main():

    # Create hypersync client using the mainnet hypersync endpoint
    client = hypersync.hypersync_client(
        "https://eth.hypersync.xyz",
    )

    height = await client.get_height()
    print("Height:", height)

    # The address we want to get all ERC20 transfers and transactions for
    addr = "1e037f97d730Cc881e77F01E409D828b0bb14de0"

    # The query to run
    query = {
        # start from block 0 and go to the end of the chain (we don't specify a toBlock).   
        "from_block": 0,
        # The logs we want. We will also automatically get transactions and blocks relating to these logs (the query implicitly joins them)
        "logs": [
            {
                "topics": [
                    # We want ERC20 transfers
                    ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],
                    [],
                    # We want the transfers that go to this address.
                    # appending zeroes because topic is 32 bytes but address is 20 bytes
                    ["0x000000000000000000000000" + addr],
                ],
            },
            {
                "topics": [
                    # We want ERC20 transfers
                    ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],
                    # We want the transfers that go to this address.
                    # appending zeroes because topic is 32 bytes but address is 20 bytes
                    ["0x000000000000000000000000" + addr],
                    [],
                ],
            },
        ],
        "transactions": [
            # We want all the transactions that come from this address
            {"from": ["0x" + addr]},
            # We want all the transactions that went to this address
            {"to": ["0x" + addr]},
        ],
        # Select the fields we are interested in
        "field_selection": {
            "block": ["number", "timestamp", "hash"],
            "log": [
                "block_number",
                "log_index",
                "transaction_index",
                "data",
                "address",
                "topic0",
                "topic1",
                "topic2",
                "topic3",
            ],
            "transaction": [
                "block_number",
                "transaction_index",
                "hash",
                "from",
                "to",
                "value",
                "input",
            ],
        },
    }

    print(query)

    # run the query once
    # res = await client.send_req(query)
    # print(res)
     
    # Create a parquet folder by running this query and writing the contents to disk
    await client.create_parquet_folder(query, "data")
    print("finished writing parquet folder")


asyncio.run(main())
```
