pyxatu 0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyxatu might be problematic. Click here for more details.

pyxatu/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .core import PyXatu
2
+
3
+ __all__ = ['PyXatu']
pyxatu/cli.py ADDED
@@ -0,0 +1,21 @@
1
+ import argparse
2
+ from .core import PyXatu
3
+
4
+ def main():
5
+ parser = argparse.ArgumentParser(description="Run queries against the Xatu API")
6
+ parser.add_argument('query', type=str, help='The SQL query to execute')
7
+ parser.add_argument('--config', type=str, help='Path to the configuration file', default=None)
8
+ parser.add_argument('--columns', type=str, nargs='+', help='List of column names', default=None)
9
+
10
+ args = parser.parse_args()
11
+
12
+ xatu = PyXatu(config_path=args.config)
13
+ result = xatu.request_query(args.query, columns=args.columns)
14
+
15
+ if result is not None:
16
+ print(result)
17
+ else:
18
+ print("Query failed")
19
+
20
+ if __name__ == "__main__":
21
+ main()
pyxatu/config.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "CLICKHOUSE_USER": "YOUR-CLICKHOUSE-USER",
3
+ "CLICKHOUSE_PASSWORD": "YOUR-CLICKHOUSE-PASSPHRASE",
4
+ "CLICKHOUSE_URL": "https://clickhouse.analytics.production.platform.ethpandaops.io"
5
+ }
pyxatu/core.py ADDED
@@ -0,0 +1,69 @@
1
+ import os
2
+ import json
3
+ import requests
4
+ from requests.auth import HTTPBasicAuth
5
+ import pandas as pd
6
+ from io import StringIO
7
+ import time
8
+ from pathlib import Path
9
+ import shutil
10
+
11
+
12
+ class PyXatu:
13
+ def __init__(self, config_path=None):
14
+ self.user_config_path = os.path.join(Path.home(), '.pyxatu_config.json')
15
+
16
+ if config_path is None:
17
+ config_path = self.user_config_path
18
+
19
+ self.config_path = config_path
20
+ self.clickhouse_user, self.clickhouse_password, self.clickhouse_url = self.read_clickhouse_config()
21
+
22
+ def read_clickhouse_config(self):
23
+ with open(self.config_path, 'r') as file:
24
+ config = json.load(file)
25
+ clickhouse_user = config.get("CLICKHOUSE_USER")
26
+ clickhouse_password = config.get("CLICKHOUSE_PASSWORD")
27
+ url = config.get("CLICKHOUSE_URL")
28
+ print("Clickhouse configs set")
29
+ return clickhouse_user, clickhouse_password, url
30
+
31
+ def request_query(self, _query, columns=None, max_retries=5):
32
+ attempt = 0
33
+ while attempt < max_retries:
34
+ try:
35
+ if attempt > 0:
36
+ print(f"Attempt {attempt + 1} of {max_retries}...")
37
+ response = requests.get(
38
+ self.clickhouse_url,
39
+ params={'query': _query},
40
+ auth=HTTPBasicAuth(self.clickhouse_user, self.clickhouse_password),
41
+ timeout=1500
42
+ )
43
+
44
+ if response.status_code == 200:
45
+ data = StringIO(response.text)
46
+ df = pd.read_csv(data, sep='\t', header=None)
47
+ if columns:
48
+ df.columns = columns
49
+ return df
50
+ else:
51
+ print(response.text)
52
+ print(f"Query failed with status code {response.status_code}. Retrying...")
53
+
54
+ except requests.RequestException as e:
55
+ print(f"An error occurred: {e}. Retrying...")
56
+
57
+ attempt += 1
58
+ wait_time = 2 ** attempt
59
+ print(f"Waiting for {wait_time} seconds before next attempt...")
60
+ time.sleep(wait_time)
61
+
62
+ print("Max retries reached. Failed to retrieve data.")
63
+ return None
64
+
65
+ def __str__(self):
66
+ return f"PyXatu(config_path={self.config_path}, user={self.clickhouse_user}, url={self.clickhouse_url})"
67
+
68
+ def __repr__(self):
69
+ return self.__str__()
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyxatu
3
+ Version: 0.1
4
+ Summary: A Python interface for the Xatu API
5
+ Home-page: https://github.com/nerolation/pyxatu
6
+ Author: Toni Wahrstätter
7
+ Author-email: toni@ethereum.org
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: requests
14
+ Requires-Dist: pandas
15
+
16
+ # PyXatu Configuration
17
+
18
+ On the first run, the default configuration file will be copied to your current working directory as `pyxatu_config.json`. Please modify this file with your actual ClickHouse credentials.
19
+
20
+ ## Steps to Modify Configuration
21
+
22
+ 1. **Run Your Script**:
23
+ On the first run, the default configuration file will be copied to your current working directory.
24
+ ```python
25
+ import pyxatu
26
+
27
+ xatu = pyxatu.PyXatu()
@@ -0,0 +1,9 @@
1
+ pyxatu/__init__.py,sha256=9YfZorNYLahJCdueB5RKLyF5JqFbWQsskLFZ8mvMJdI,46
2
+ pyxatu/cli.py,sha256=b3w_V537a07Msf1tqp-Yj2RtBCkpY9mIMz0t1t-KHOo,697
3
+ pyxatu/config.json,sha256=ijwidQo0w9TJtawKDtEY1cIWzqui4c7GoTlZPflCD68,196
4
+ pyxatu/core.py,sha256=hRQxL9TxctduIIL7glPk5jR7GC1qVmMAvbmBSRkiuRI,2446
5
+ pyxatu-0.1.dist-info/METADATA,sha256=fQJ-L5ykMTCUGRlPSxRujwgwVYgCSrUVFg78edW0o9s,885
6
+ pyxatu-0.1.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
7
+ pyxatu-0.1.dist-info/entry_points.txt,sha256=l8MAh5m6Ym3axckVnkmAOvlsRw0e1yzw03gzyCeGTGo,47
8
+ pyxatu-0.1.dist-info/top_level.txt,sha256=UT4eKtFyG7uKohc_waGd0o66Y9J3DxQrsM0o0nZC9UA,7
9
+ pyxatu-0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (72.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ xatu-query = pyxatu.cli:main
@@ -0,0 +1 @@
1
+ pyxatu