Metadata-Version: 2.1
Name: graphsense-lib
Version: 2.3.6
Summary: Graphsense backend lib and automation cli
Home-page: https://graphsense.github.io/
Author: Iknaio Cryptoasset Analytics GmbH
Author-email: contact@ikna.io
License: MIT
Project-URL: Source, https://github.com/graphsense/graphsense-lib
Project-URL: Changelog, https://github.com/graphsense/graphsense-lib/blob/master/CHANGELOG.md
Project-URL: Tracker, https://github.com/graphsense/graphsense-lib/issues
Project-URL: Download, https://github.com/graphsense
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Utilities
Requires-Python: <3.11,>=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
License-File: LICENSE
Requires-Dist: importlib-metadata; python_version < "3.8"
Requires-Dist: cassandra-driver==3.27.0
Requires-Dist: lz4~=4.3.2
Requires-Dist: filelock<4.0,>=3.8.0
Requires-Dist: click<9.0,>=8.0.3
Requires-Dist: pandas<2.0,>=1.4.1
Requires-Dist: methodtools~=0.4
Requires-Dist: simplejson<4.0,>=3.17.6
Requires-Dist: goodconf[yaml]<4.0,>=3.0.0
Requires-Dist: requests<3.0,>=2.27.1
Requires-Dist: parsy<3.0,>=2.0
Requires-Dist: rich<13.0,>=12.6.0
Requires-Dist: eth-event<2.0,>=1.2.3
Requires-Dist: eth-hash~=0.3.0
Requires-Dist: ethereum-etl~=2.4.1
Requires-Dist: pyarrow<17.0,>=16.0.0
Requires-Dist: chainside-btcpy~=0.6
Requires-Dist: cashaddress<1.1,>=1.0.6
Requires-Dist: tenacity~=8.2.3
Requires-Dist: graphsense-bitcoin-etl==1.5.4
Requires-Dist: base58~=2.1
Requires-Dist: typeguard~=4.1
Requires-Dist: diskcache~=5.6
Requires-Dist: bitarray~=2.9
Requires-Dist: numpy<2.0.0
Requires-Dist: grpcio
Requires-Dist: deltalake==0.18.0
Provides-Extra: testing
Requires-Dist: setuptools; extra == "testing"
Requires-Dist: pytest; extra == "testing"
Requires-Dist: pytest-cov; extra == "testing"
Provides-Extra: dev
Requires-Dist: setuptools; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: flake8>=4.0.1; extra == "dev"
Requires-Dist: flake8-comprehensions>=3.11.1; extra == "dev"
Requires-Dist: flake8-builtins; extra == "dev"
Requires-Dist: black>=22.3.0; extra == "dev"
Requires-Dist: tox; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: setuptools_scm; extra == "dev"
Requires-Dist: pdbpp; extra == "dev"
Requires-Dist: grpcio-tools; extra == "dev"

# graphsense-lib

[![Test and Build Status](https://github.com/graphsense/graphsense-lib/actions/workflows/run_tests.yaml/badge.svg)](https://github.com/graphsense/graphsense-lib/actions) [![PyPI version](https://badge.fury.io/py/graphsense-lib.svg)](https://badge.fury.io/py/graphsense-lib) [![Python](https://img.shields.io/pypi/pyversions/graphsense-lib)](https://pypi.org/project/graphsense-lib/) [![Downloads](https://static.pepy.tech/badge/graphsense-lib)](https://pepy.tech/project/graphsense-lib)

A central repository for python utility functions and everything that deals with the graphsense backend. Its CLI interface can be used to control important graphsense maintainance tasks.

## Use

### As a library

Access the graphsense cassandra db. This requires a graphsense config (see Modules/Config)
```python3
from graphsenselib.db import DbFactory

env, currency = "test", "btc"

with DbFactory().from_config(env, currency) as db:
    print(db.transformed.get_highest_block())
```

Alternatively, the database can also be accessed without relying on the graphsense config file.
```python
from graphsenselib.db import DbFactory

with DbFactory().from_name(
        raw_keyspace_name="eth_raw",
        transformed_keyspace_name="eth_transformed",
        schema_type="account",
        cassandra_nodes = ["test.cassandra1", "test.cassandra2"]
    ) as db:
    print(db.transformed.get_highest_block())
```

### From the commandline.

Graphsenslib exposes a commandline interface - graphsence-cli.

Help can be viewed by:
```bash
> graphsense-cli --help
Usage: graphsense-cli [OPTIONS] COMMAND [ARGS]...

  Commandline interface of graphsense-lib

  graphsense-cli exposes many tools and features to manager your graphsense
  crypto-analytics database.

Options:
  -v, --verbose  One v for warning, two for info etc.
  --help         Show this message and exit.

Commands:
  config          Inspect the current configuration of graphsenselib.
  convert         Useful file convertions tools for the graphsense...
  db              Query related functions.
  delta-update    Updating the transformed keyspace from the raw keyspace.
  exchange-rates  Fetching and ingesting exchange rates.
  ingest          Ingesting raw cryptocurrency data from nodes into the...
  monitoring      Tools to monitor the graphsense infrastructure.
  schema          Creating and validating the db schema.
  version         Display the current version.
  watch           Commands for permanently watching cryptocurrency events.

  GraphSense - https://graphsense.github.io/
```


## Modules

### DB

Assess the current database state.

```bash
> graphsense-cli db --help
Usage: graphsense-cli db [OPTIONS] COMMAND [ARGS]...

  DB-management related functions.

Options:
  --help  Show this message and exit.

Commands:
  block  Special db query functions regarding blocks.
  logs   Special db query functions regarding logs.
  state  Summary Prints the current state of the graphsense database.

```

### Schema

Extracting and validating the current database schema.

```bash
> graphsense-cli schema --help
Usage: graphsense-cli schema [OPTIONS] COMMAND [ARGS]...

  Creating and validating the db schema.

Options:
  --help  Show this message and exit.

Commands:
  create               Creates the necessary graphsense tables in Cassandra.
  show-by-currency     Prints the current db schema expected from
                       graphsenselib
  show-by-schema-type  Prints the current db schema expected from
                       graphsenselib
  validate             Validates if the expected schema matches the database.

```

### Ingest

Loading raw data from cryptocurrency nodes into the graphsense raw keyspace.

```bash
> graphsense-cli ingest --help
Usage: graphsense-cli ingest [OPTIONS] COMMAND [ARGS]...

  Ingesting raw cryptocurrency data from nodes into the graphsense database

Options:
  --help  Show this message and exit.

Commands:
  from-node  Ingests cryptocurrency data form the client/node to the...
```


### Delta Update

Updates the data in the transformed keyspace based on the raw keyspace

```bash
> graphsense-cli delta-update --help
Usage: graphsense-cli delta-update [OPTIONS] COMMAND [ARGS]...

  Updating the transformed keyspace from the raw keyspace.

Options:
  --help  Show this message and exit.

Commands:
  patch-exchange-rates  Rewrites the transformed exchange rate at a...
  status                Shows the status of the delta updater.
  update                Updates transformed from raw, if possible.
  validate              Validates the current delta update status and its...
```

### Exchange Rates

Fetches exchange_rates from different sources and adds them to the database.

```bash
> graphsense-cli exchange-rates --help
Usage: graphsense-cli exchange-rates [OPTIONS] COMMAND [ARGS]...

  Fetching and ingesting exchange rates.

Options:
  --help  Show this message and exit.

Commands:
  coindesk       From coindesk.
  coinmarketcap  From coinmarketcap.
```


### Config

Shows the currently used configuration. Configurations reside per default in ~/graphsense.yaml. It contains the cassandra and keyspace configurations for different environments. A template config can be generated via ```graphsense-cli config template```

```bash
> graphsense-cli config --help
Usage: graphsense-cli config [OPTIONS] COMMAND [ARGS]...

  Inspect the current configuration of graphsenselib.

Options:
  --help  Show this message and exit.

Commands:
  path      Prints the path where the config is loaded from.
  show      Prints the configuration used in the environment.
  template  Generates a configuration template.
```

### Monitoring

Helpful functions to keep an eye on the state and health of your graphsense database state.

```bash
> graphsense-cli monitoring --help
Usage: graphsense-cli monitoring [OPTIONS] COMMAND [ARGS]...

  Tools to monitor the graphsense infrastructure.

Options:
  --help  Show this message and exit.

Commands:
  get-summary  Receives a summary record of the current database state.
  notify       Sends a message to the configured handlers (e.g. a slack
               channel) by topic.

```

### Watch (Alpha)

Provides functions to generate notifications on cryptocurrency events like value flows on certain addresses.

```bash
> graphsense-cli watch --help
Usage: graphsense-cli watch [OPTIONS] COMMAND [ARGS]...

  Commands for permanently watching cryptocurrency events.

Options:
  --help  Show this message and exit.

Commands:
  money-flows  Watches for movements money flows and generates...

```

## Install

To install the package from the python package index run.
```bash
  > pip install graphsense-lib
```

If you want to install it from source run
```bash
  > make install
```
or
```bash
  > pip install .
```

## Development

Caution: python 3.11 is currently not supported. Please use ```python3.10```.

it is advised to use a virtual environment (venv) for development. Run the following command to initialize one
```bash
    > python3 -m venv .venv
```

and activate it (in bash) using

```bash
    > source .venv/bin/activate
```
 For more information refer to ([venv](https://docs.python.org/3/library/venv.html)). Run

```bash
    > make dev
```

to initialize the dev environment.
If you want to install graphsenselib in development mode run

```bash
    > make install-dev
```

Before committing anything to the repository please format, lint and test your code in that order. Fix all linter warnings and make sure all test are passing before a commit.

Use the following commands for that:
```bash
    > make format
    > make lint
    > make test
```

or equivalently run
```bash
    > make pre-commit
```

Some slow tests are excluded when running make test. Occasionally, one should run
```bash
    > make test-all
```

to run the entire test-suite.

Linting and formatting should be automatically executed on every git commit, using pre-commit.

To create the documentation please run:
```bash
    > make docs
```

Creating the docs need python dev dependencies to build see ([Stackoverflow](https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory}))

### Tagging a release

To tag a new release please update the changelog first. Afterwards, update the Version numbers RELEASESEM and RELEASE in the main Makefile.

To apply the tags run
```bash
    > make tag-version
```

### Open SSL - Errors running test suites
Some components used by graphsense-lib use OpenSSL, to provide certain hash functions. Since OpenSSL 3.0 some hash functions needed are not available anymore by default (e.g. ripemd160). This leads to errors while running the test suite. To avoid these errors, enable legacy providers in the OpenSSL config. An example of the necessary changes can be found in the "fix openssl legacy mode" step in .github/workflows/run_tests.yaml
