pyoso 0.1.0__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.
- pyoso-0.1.0/PKG-INFO +50 -0
- pyoso-0.1.0/README.md +43 -0
- pyoso-0.1.0/pyoso/__init__.py +8 -0
- pyoso-0.1.0/pyoso/client.py +47 -0
- pyoso-0.1.0/pyoso/exceptions.py +12 -0
- pyoso-0.1.0/pyoso.egg-info/PKG-INFO +50 -0
- pyoso-0.1.0/pyoso.egg-info/SOURCES.txt +10 -0
- pyoso-0.1.0/pyoso.egg-info/dependency_links.txt +1 -0
- pyoso-0.1.0/pyoso.egg-info/top_level.txt +1 -0
- pyoso-0.1.0/pyproject.toml +10 -0
- pyoso-0.1.0/setup.cfg +4 -0
- pyoso-0.1.0/tests/test_client.py +78 -0
pyoso-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: pyoso
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Author-email: Icaro Guerra <icaro@karibalabs.co>
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# pyoso
|
|
9
|
+
|
|
10
|
+
_WARNING: THIS IS A WORK IN PROGRESS_
|
|
11
|
+
|
|
12
|
+
`pyoso` is a Python package for fetching models and metrics from OSO. This package provides an easy-to-use interface to interact with oso and retrieve valuable data for analysis and monitoring.
|
|
13
|
+
|
|
14
|
+
## Current Features
|
|
15
|
+
|
|
16
|
+
- Execute custom SQL queries for analyzing the OSO dataset
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
You can install `pyoso` using pip:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install pyoso
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Here is a basic example of how to use `pyoso`:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from pyoso import Client
|
|
32
|
+
|
|
33
|
+
# Initialize the client
|
|
34
|
+
os.environ["OSO_API_KEY"] = 'your_api_key'
|
|
35
|
+
client = Client()
|
|
36
|
+
|
|
37
|
+
# Fetch artifacts
|
|
38
|
+
query = "SELECT * FROM artifacts_v1 LIMIT 5"
|
|
39
|
+
artifacts = client.query(query)
|
|
40
|
+
|
|
41
|
+
print(artifacts)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Documentation
|
|
45
|
+
|
|
46
|
+
For detailed documentation about the OSO dataset, please refer to the [official documentation](https://docs.opensource.observer/docs/integrate/datasets/).
|
|
47
|
+
|
|
48
|
+
## Future Plans
|
|
49
|
+
|
|
50
|
+
- Create DataFrame wrapper for creating SQL query from data transforms
|
pyoso-0.1.0/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# pyoso
|
|
2
|
+
|
|
3
|
+
_WARNING: THIS IS A WORK IN PROGRESS_
|
|
4
|
+
|
|
5
|
+
`pyoso` is a Python package for fetching models and metrics from OSO. This package provides an easy-to-use interface to interact with oso and retrieve valuable data for analysis and monitoring.
|
|
6
|
+
|
|
7
|
+
## Current Features
|
|
8
|
+
|
|
9
|
+
- Execute custom SQL queries for analyzing the OSO dataset
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
You can install `pyoso` using pip:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install pyoso
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Here is a basic example of how to use `pyoso`:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from pyoso import Client
|
|
25
|
+
|
|
26
|
+
# Initialize the client
|
|
27
|
+
os.environ["OSO_API_KEY"] = 'your_api_key'
|
|
28
|
+
client = Client()
|
|
29
|
+
|
|
30
|
+
# Fetch artifacts
|
|
31
|
+
query = "SELECT * FROM artifacts_v1 LIMIT 5"
|
|
32
|
+
artifacts = client.query(query)
|
|
33
|
+
|
|
34
|
+
print(artifacts)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
For detailed documentation about the OSO dataset, please refer to the [official documentation](https://docs.opensource.observer/docs/integrate/datasets/).
|
|
40
|
+
|
|
41
|
+
## Future Plans
|
|
42
|
+
|
|
43
|
+
- Create DataFrame wrapper for creating SQL query from data transforms
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import List, Optional, TypedDict
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
from pyoso.exceptions import OsoError, OsoHTTPError
|
|
8
|
+
|
|
9
|
+
_DEFAULT_BASE_URL = "https://opensource.observer/api/v1/"
|
|
10
|
+
OSO_API_KEY = "OSO_API_KEY"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class ClientConfig:
|
|
15
|
+
base_url: Optional[str]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Client:
|
|
19
|
+
def __init__(
|
|
20
|
+
self, api_key: Optional[str] = None, client_opts: Optional[ClientConfig] = None
|
|
21
|
+
):
|
|
22
|
+
self.__api_key = api_key if api_key else os.environ.get(OSO_API_KEY)
|
|
23
|
+
if not self.__api_key:
|
|
24
|
+
raise OsoError(
|
|
25
|
+
"API key is required. Either set it in the environment variable OSO_API_KEY or pass it as an argument."
|
|
26
|
+
)
|
|
27
|
+
self.__base_url = _DEFAULT_BASE_URL
|
|
28
|
+
if client_opts and client_opts.base_url:
|
|
29
|
+
self.__base_url = client_opts.base_url
|
|
30
|
+
if not self.__base_url.endswith("/"):
|
|
31
|
+
self.__base_url += "/"
|
|
32
|
+
|
|
33
|
+
def query(self, query: str):
|
|
34
|
+
headers = {}
|
|
35
|
+
if self.__api_key:
|
|
36
|
+
headers["Authorization"] = f"Bearer {self.__api_key}"
|
|
37
|
+
try:
|
|
38
|
+
response = requests.post(
|
|
39
|
+
f"{self.__base_url}sql",
|
|
40
|
+
headers=headers,
|
|
41
|
+
json={"query": query},
|
|
42
|
+
stream=True,
|
|
43
|
+
)
|
|
44
|
+
response.raise_for_status()
|
|
45
|
+
return response.json()
|
|
46
|
+
except requests.HTTPError as e:
|
|
47
|
+
raise OsoHTTPError(e, response=e.response) from None
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from requests import HTTPError
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class OsoError(Exception):
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OsoHTTPError(HTTPError):
|
|
9
|
+
def __str__(self):
|
|
10
|
+
str = super().__str__()
|
|
11
|
+
response = self.response.json()
|
|
12
|
+
return f"{str} - {response["error"] if response["error"] else response}"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: pyoso
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Author-email: Icaro Guerra <icaro@karibalabs.co>
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
|
|
8
|
+
# pyoso
|
|
9
|
+
|
|
10
|
+
_WARNING: THIS IS A WORK IN PROGRESS_
|
|
11
|
+
|
|
12
|
+
`pyoso` is a Python package for fetching models and metrics from OSO. This package provides an easy-to-use interface to interact with oso and retrieve valuable data for analysis and monitoring.
|
|
13
|
+
|
|
14
|
+
## Current Features
|
|
15
|
+
|
|
16
|
+
- Execute custom SQL queries for analyzing the OSO dataset
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
You can install `pyoso` using pip:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install pyoso
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Here is a basic example of how to use `pyoso`:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from pyoso import Client
|
|
32
|
+
|
|
33
|
+
# Initialize the client
|
|
34
|
+
os.environ["OSO_API_KEY"] = 'your_api_key'
|
|
35
|
+
client = Client()
|
|
36
|
+
|
|
37
|
+
# Fetch artifacts
|
|
38
|
+
query = "SELECT * FROM artifacts_v1 LIMIT 5"
|
|
39
|
+
artifacts = client.query(query)
|
|
40
|
+
|
|
41
|
+
print(artifacts)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Documentation
|
|
45
|
+
|
|
46
|
+
For detailed documentation about the OSO dataset, please refer to the [official documentation](https://docs.opensource.observer/docs/integrate/datasets/).
|
|
47
|
+
|
|
48
|
+
## Future Plans
|
|
49
|
+
|
|
50
|
+
- Create DataFrame wrapper for creating SQL query from data transforms
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyoso
|
pyoso-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from logging import config
|
|
3
|
+
from unittest import TestCase, mock
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
from pyoso.client import Client, ClientConfig
|
|
7
|
+
from pyoso.exceptions import OsoError, OsoHTTPError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestClient(TestCase):
|
|
11
|
+
DEFAULT_API_KEY = "test_key"
|
|
12
|
+
CUSTOM_API_KEY = "custom_key"
|
|
13
|
+
|
|
14
|
+
@mock.patch.dict(os.environ, {"OSO_API_KEY": ""})
|
|
15
|
+
def test_constructor_without_api_key(self):
|
|
16
|
+
with self.assertRaises(OsoError):
|
|
17
|
+
Client(api_key=None)
|
|
18
|
+
|
|
19
|
+
@mock.patch("requests.post")
|
|
20
|
+
def test_query(self, mock_get):
|
|
21
|
+
mock_response = mock.Mock()
|
|
22
|
+
expected_json = {"data": "test"}
|
|
23
|
+
mock_response.json.return_value = expected_json
|
|
24
|
+
mock_get.return_value = mock_response
|
|
25
|
+
|
|
26
|
+
client = Client(
|
|
27
|
+
api_key=self.CUSTOM_API_KEY,
|
|
28
|
+
client_opts=ClientConfig(base_url="http://localhost:8000/api/v1"),
|
|
29
|
+
)
|
|
30
|
+
query = "SELECT * FROM test_table"
|
|
31
|
+
response = client.query(query)
|
|
32
|
+
|
|
33
|
+
mock_get.assert_called_once_with(
|
|
34
|
+
"http://localhost:8000/api/v1/sql",
|
|
35
|
+
headers={"Authorization": f"Bearer {self.CUSTOM_API_KEY}"},
|
|
36
|
+
json={"query": query},
|
|
37
|
+
stream=True,
|
|
38
|
+
)
|
|
39
|
+
self.assertEqual(response, expected_json)
|
|
40
|
+
|
|
41
|
+
@mock.patch.dict(os.environ, {"OSO_API_KEY": DEFAULT_API_KEY})
|
|
42
|
+
@mock.patch("requests.post")
|
|
43
|
+
def test_query_with_default_api_key(self, mock_get):
|
|
44
|
+
mock_response = mock.Mock()
|
|
45
|
+
expected_json = {"data": "test"}
|
|
46
|
+
mock_response.json.return_value = expected_json
|
|
47
|
+
mock_get.return_value = mock_response
|
|
48
|
+
|
|
49
|
+
client = Client()
|
|
50
|
+
query = "SELECT * FROM test_table"
|
|
51
|
+
response = client.query(query)
|
|
52
|
+
|
|
53
|
+
mock_get.assert_called_once_with(
|
|
54
|
+
"https://opensource.observer/api/v1/sql",
|
|
55
|
+
headers={"Authorization": f"Bearer {self.DEFAULT_API_KEY}"},
|
|
56
|
+
json={"query": query},
|
|
57
|
+
stream=True,
|
|
58
|
+
)
|
|
59
|
+
self.assertEqual(response, expected_json)
|
|
60
|
+
|
|
61
|
+
@mock.patch("requests.post")
|
|
62
|
+
def test_query_http_error(self, mock_get):
|
|
63
|
+
mock_response = mock.Mock()
|
|
64
|
+
mock_response.raise_for_status.side_effect = requests.HTTPError("HTTP Error")
|
|
65
|
+
mock_get.return_value = mock_response
|
|
66
|
+
|
|
67
|
+
client = Client(api_key=self.CUSTOM_API_KEY)
|
|
68
|
+
query = "SELECT * FROM test_table"
|
|
69
|
+
|
|
70
|
+
with self.assertRaises(OsoHTTPError):
|
|
71
|
+
client.query(query)
|
|
72
|
+
|
|
73
|
+
mock_get.assert_called_once_with(
|
|
74
|
+
"https://opensource.observer/api/v1/sql",
|
|
75
|
+
headers={"Authorization": f"Bearer {self.CUSTOM_API_KEY}"},
|
|
76
|
+
json={"query": query},
|
|
77
|
+
stream=True,
|
|
78
|
+
)
|