Giter Site home page Giter Site logo

dune-analytics-api's Introduction

dune-analytics-api

It is a Python library to make SQL queries to databases provided by Dune Analytics. First, dune-analytics-api has tools to interact with Dune Analytics from Python scripts. Second, there is a command-line script that emulates terminal where you can query and download the data.

Installation

pip install git+https://github.com/fomalhaut88/dune-analytics-api.git

Use from command line

You must be registered on Dune Analytics to have username and password.

To run:

dune-analytics-api

If you set environment variables DUNE_USERNAME and DUNE_PASSWORD, you can run command line without authorization questions:

dune-analytics-api -e

Query example

$ dune-analytics-api -e
Trying to get username and password from environment...
Creating a session...
Welcome to dune-analytics-api (version 1.0) where you can perform SQL queries as at https://duneanalytics.com/
> SELECT count(*) FROM ethereum.blocks;
+----------+
|  count   |
+----------+
| 11620094 |
+----------+

Download to CSV

$ dune-analytics-api -e
Trying to get username and password from environment...
Creating a session...
Welcome to dune-analytics-api (version 1.0) where you can perform SQL queries as at https://duneanalytics.com/
> download data.csv
> SELECT * FROM ethereum.blocks LIMIT 100;
Saved to data.csv

Use from Python

A simple script that gets last 10 transactions in Ethereum.

# Import Session and QueryMaker
from dune_analytics_api import Session, QueryMaker

# The query
query = """
    SELECT * FROM ethereum.blocks
    ORDER BY "time" DESC
    LIMIT 10
"""

# You need to be registered on Dune Analytics to have username and password
session = Session.from_login('your_username', 'your_password')

# Create a QueryMaker object
query_maker = QueryMaker(session)

# Execute the query
rows = query_maker.exec(query)

# Print the result
for row in rows:
    print(row)

dune-analytics-api's People

Contributors

fomalhaut88 avatar

Stargazers

Mackay avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.