pyxatu 0.1__tar.gz
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-0.1/MANIFEST.in +2 -0
- pyxatu-0.1/PKG-INFO +27 -0
- pyxatu-0.1/README.md +12 -0
- pyxatu-0.1/pyproject.toml +3 -0
- pyxatu-0.1/pyxatu/__init__.py +3 -0
- pyxatu-0.1/pyxatu/cli.py +21 -0
- pyxatu-0.1/pyxatu/config.json +5 -0
- pyxatu-0.1/pyxatu/core.py +69 -0
- pyxatu-0.1/pyxatu.egg-info/PKG-INFO +27 -0
- pyxatu-0.1/pyxatu.egg-info/SOURCES.txt +14 -0
- pyxatu-0.1/pyxatu.egg-info/dependency_links.txt +1 -0
- pyxatu-0.1/pyxatu.egg-info/entry_points.txt +2 -0
- pyxatu-0.1/pyxatu.egg-info/requires.txt +2 -0
- pyxatu-0.1/pyxatu.egg-info/top_level.txt +1 -0
- pyxatu-0.1/setup.cfg +4 -0
- pyxatu-0.1/setup.py +55 -0
pyxatu-0.1/MANIFEST.in
ADDED
pyxatu-0.1/PKG-INFO
ADDED
|
@@ -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()
|
pyxatu-0.1/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# PyXatu Configuration
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Steps to Modify Configuration
|
|
6
|
+
|
|
7
|
+
1. **Run Your Script**:
|
|
8
|
+
On the first run, the default configuration file will be copied to your current working directory.
|
|
9
|
+
```python
|
|
10
|
+
import pyxatu
|
|
11
|
+
|
|
12
|
+
xatu = pyxatu.PyXatu()
|
pyxatu-0.1/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()
|
|
@@ -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,14 @@
|
|
|
1
|
+
MANIFEST.in
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
pyxatu/__init__.py
|
|
6
|
+
pyxatu/cli.py
|
|
7
|
+
pyxatu/config.json
|
|
8
|
+
pyxatu/core.py
|
|
9
|
+
pyxatu.egg-info/PKG-INFO
|
|
10
|
+
pyxatu.egg-info/SOURCES.txt
|
|
11
|
+
pyxatu.egg-info/dependency_links.txt
|
|
12
|
+
pyxatu.egg-info/entry_points.txt
|
|
13
|
+
pyxatu.egg-info/requires.txt
|
|
14
|
+
pyxatu.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyxatu
|
pyxatu-0.1/setup.cfg
ADDED
pyxatu-0.1/setup.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
from setuptools.command.install import install
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import shutil
|
|
6
|
+
|
|
7
|
+
class PostInstallCommand(install):
|
|
8
|
+
"""Post-installation for installation mode."""
|
|
9
|
+
def run(self):
|
|
10
|
+
install.run(self)
|
|
11
|
+
self._copy_config_to_home()
|
|
12
|
+
|
|
13
|
+
def _copy_config_to_home(self):
|
|
14
|
+
home = Path.home()
|
|
15
|
+
user_config_path = home / '.pyxatu_config.json'
|
|
16
|
+
default_config_path = Path(__file__).parent / 'pyxatu' / 'config.json'
|
|
17
|
+
if not user_config_path.exists():
|
|
18
|
+
shutil.copy(default_config_path, user_config_path)
|
|
19
|
+
print(f"Default configuration copied to {user_config_path}. Please modify it with your actual credentials.")
|
|
20
|
+
else:
|
|
21
|
+
print(f"User configuration already exists at {user_config_path}")
|
|
22
|
+
|
|
23
|
+
setup(
|
|
24
|
+
name='pyxatu',
|
|
25
|
+
version='0.1',
|
|
26
|
+
packages=find_packages(),
|
|
27
|
+
include_package_data=True,
|
|
28
|
+
package_data={
|
|
29
|
+
'pyxatu': ['config.json'],
|
|
30
|
+
},
|
|
31
|
+
install_requires=[
|
|
32
|
+
'requests',
|
|
33
|
+
'pandas',
|
|
34
|
+
],
|
|
35
|
+
entry_points={
|
|
36
|
+
'console_scripts': [
|
|
37
|
+
'xatu-query=pyxatu.cli:main',
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
cmdclass={
|
|
41
|
+
'install': PostInstallCommand,
|
|
42
|
+
},
|
|
43
|
+
author='Toni Wahrstätter',
|
|
44
|
+
author_email='toni@ethereum.org',
|
|
45
|
+
description='A Python interface for the Xatu API',
|
|
46
|
+
long_description=open('README.md').read(),
|
|
47
|
+
long_description_content_type='text/markdown',
|
|
48
|
+
url='https://github.com/nerolation/pyxatu',
|
|
49
|
+
classifiers=[
|
|
50
|
+
'Programming Language :: Python :: 3',
|
|
51
|
+
'License :: OSI Approved :: MIT License',
|
|
52
|
+
'Operating System :: OS Independent',
|
|
53
|
+
],
|
|
54
|
+
python_requires='>=3.6',
|
|
55
|
+
)
|