chainalysis.sql package - Data Solutions Python SDK 0.7.0 documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# chainalysis.sql package

## Submodules

## chainalysis.sql.analytical module

class chainalysis.sql.analytical.Analytical(api_key: str)

  Bases: `object`

  This class provides methods to execute SQL queries on Data Solutions analytical tables. It supports fetching results as JSON or a pandas DataFrame, and provides query execution statistics.

  __call__(query: str, parameters: dict[str] = {}, polling_interval_sec: int = 5, autopaginate: bool = True)

    Execute a SQL query asynchronously using the provided parameters and polling interval.

    Autopagination is enabled by default. If autopagination is enabled, the method will fetch all pages of results and return a single Analytical object with all results.

    Otherwise, the method will return an Analytical object with the first page of results. Use the next_page() method to fetch the next page of results and the stats() method to get statistics that can help you determine the approach to take to fetch all results.

    Parameters:

      - query (str) – The SQL query to be executed.

      - parameters (dict[str], optional) – A dictionary of parameters to be used in the query.

      - polling_interval_sec (int, optional) – The interval in seconds between status checks. The minimum value is 5 seconds.

      - autopaginate (bool, optional) – Whether to automatically full results instead of individual pages.

    Returns:

      An instance of the Analytical class with query results.

    Return type:

      Analytical

  __init__(api_key: str)

    Initialize the Analytical class with the provided API key.

    Parameters:

      api_key (str) – The API key for accessing the analytical service.

  df()

    Convert query results into a pandas DataFrame.

    Raises:

      Exception – Raises an exception if the query resulted in an error.

    Returns:

      DataFrame containing the results of the SQL query.

    Return type:

      pd.DataFrame

  has_next() → bool

    Return if the next page exists.

    Returns:

      Whether next page exists.

    Return type:

      bool

  json()

    Return results as a JSON.

    Raises:

      Exception – Raises an exception if the query resulted in an error.

    Returns:

      Results of the SQL query as a JSON.

    Return type:

      dict

  next_page()

    Fetch the next page of analytical query results.

    Returns:

      An instance of the Analytical class with the next page of results.

    Return type:

      Analytical

  stats()

    Get the statistics of the executed query.

    Returns:

      Statistics of the query execution.

    Return type:

      dict

  status_code()

    Get the HTTP status code of the response.

    Returns:

      HTTP status code.

    Return type:

      int

  total_pages() → int

    Return total number of pages.

    Returns:

      Number of pages.

    Return type:

      int

  was_successful()

    Determine if the query executed successfully.

    Returns:

      True if the query was successful, False otherwise.

    Return type:

      bool

## chainalysis.sql.sql module

class chainalysis.sql.sql.Sql(api_key: str)

  Bases: `object`

  __init__(api_key: str)

## chainalysis.sql.transactional module

class chainalysis.sql.transactional.Transactional(api_key: str)

  Bases: `object`

  This class provides methods to handle transactional queries. It supports fetching results as JSON or pandas DataFrame, and provides query execution statistics.

  __call__(query: str, parameters: dict[str, str] = {}, options: dict[str, str] = {}) → Transactional

    Execute a SQL query using the provided parameters and options.

    Parameters:

      - query (str) – SQL query template with placeholders for parameters.

      - parameters (dict[str, str]) – Parameters to format the SQL query.

      - options (dict[str, str]) – Additional options for query execution.

    Returns:

      Returns self for chaining or method chaining.

    Return type:

      Transactional

  __init__(api_key: str)

    Initialize the Transactional object with an API key.

    Parameters:

      api_key (str) – API key for authenticating requests.

  df() → DataFrame

    Convert query results into a pandas DataFrame.

    Raises:

      Exception – Raises an exception if the query resulted in an error.

    Returns:

      DataFrame containing the results of the SQL query.

    Return type:

      pd.DataFrame

  json() → dict

    Return the JSON data of the results.

    Raises:

      Exception – Raises an exception if the query resulted in an error.

    Returns:

      JSON results of the SQL query.

    Return type:

      dict

  stats() → dict

    Get the statistics of the executed query.

    Returns:

      Statistics of the query execution.

    Return type:

      dict

  status_code() → int

    Return the status code of the query.

    Returns:

      The status code of the query.

    Return type:

      int

  was_successful() → bool

    Determine if the query executed successfully.

    Returns:

      True if the query was successful, False otherwise.

    Return type:

      bool

## Module contents