ams-sdk 1.0.0__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.
- ams_sdk/__init__.py +0 -0
- ams_sdk/client.py +63 -0
- ams_sdk/utils.py +26 -0
- ams_sdk-1.0.0.dist-info/LICENSE +21 -0
- ams_sdk-1.0.0.dist-info/METADATA +186 -0
- ams_sdk-1.0.0.dist-info/RECORD +7 -0
- ams_sdk-1.0.0.dist-info/WHEEL +4 -0
ams_sdk/__init__.py
ADDED
|
File without changes
|
ams_sdk/client.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from typing import Dict, Any, Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AMSClient:
|
|
6
|
+
"""
|
|
7
|
+
Python SDK for the Alternative Macro Signals (AMS) API.
|
|
8
|
+
Provides methods for authentication and querying endpoints like `/nbstat`.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(self, service_url: str, api_key: str):
|
|
12
|
+
"""
|
|
13
|
+
Initialize the AMSClient with service URL and API key.
|
|
14
|
+
:param service_url: Base URL for the API service.
|
|
15
|
+
:param api_key: API key provided by AMS.
|
|
16
|
+
"""
|
|
17
|
+
self.service_url = service_url
|
|
18
|
+
self.api_key = api_key
|
|
19
|
+
self.token = None
|
|
20
|
+
|
|
21
|
+
def authenticate(self) -> str:
|
|
22
|
+
"""
|
|
23
|
+
Authenticate using the API key to fetch a Bearer token.
|
|
24
|
+
:return: Bearer token as a string.
|
|
25
|
+
:raises: Exception if the authentication request fails.
|
|
26
|
+
"""
|
|
27
|
+
headers = {'X-API-Key': self.api_key}
|
|
28
|
+
response = requests.post(f"{self.service_url}/token", headers=headers)
|
|
29
|
+
|
|
30
|
+
if response.status_code == 200:
|
|
31
|
+
self.token = response.json()
|
|
32
|
+
return self.token
|
|
33
|
+
else:
|
|
34
|
+
raise Exception(f"Authentication failed! Status: {response.status_code}, Message: {response.text}")
|
|
35
|
+
|
|
36
|
+
def _get_headers(self) -> Dict[str, str]:
|
|
37
|
+
"""
|
|
38
|
+
Construct headers for authenticated requests.
|
|
39
|
+
:return: A dictionary containing the Authorization header.
|
|
40
|
+
:raises: Exception if the token is missing.
|
|
41
|
+
"""
|
|
42
|
+
if not self.token:
|
|
43
|
+
raise Exception("Missing token! Please authenticate first using `authenticate()`.")
|
|
44
|
+
|
|
45
|
+
return {"Authorization": f"Bearer {self.token}"}
|
|
46
|
+
|
|
47
|
+
def query_endpoint(self, endpoint: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
48
|
+
"""
|
|
49
|
+
Generic function to query a specific endpoint.
|
|
50
|
+
:param endpoint: The endpoint path, e.g., "/nbstat".
|
|
51
|
+
:param params: Optional query parameters for the request.
|
|
52
|
+
:return: Response as a dictionary.
|
|
53
|
+
:raises: Exception if the request fails.
|
|
54
|
+
"""
|
|
55
|
+
url = f"{self.service_url}{endpoint}"
|
|
56
|
+
headers = self._get_headers()
|
|
57
|
+
response = requests.get(url, headers=headers, params=params)
|
|
58
|
+
|
|
59
|
+
if response.status_code == 200:
|
|
60
|
+
return response.json()
|
|
61
|
+
else:
|
|
62
|
+
raise Exception(f"Request to {endpoint} failed! Status: {response.status_code}, Message: {response.text}")
|
|
63
|
+
|
ams_sdk/utils.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from ams_sdk.client import AMSClient
|
|
2
|
+
|
|
3
|
+
# Initialize AMSClient
|
|
4
|
+
SERVICE_URL = "<service_url>" # Replace with actual service URL
|
|
5
|
+
API_KEY = "<your-api-key>" # Replace with your API key
|
|
6
|
+
|
|
7
|
+
client = AMSClient(SERVICE_URL, API_KEY)
|
|
8
|
+
|
|
9
|
+
# Authenticate and get Bearer token
|
|
10
|
+
try:
|
|
11
|
+
client.authenticate()
|
|
12
|
+
print("Authentication successful!")
|
|
13
|
+
except Exception as e:
|
|
14
|
+
print(f"Error during authentication: {e}")
|
|
15
|
+
|
|
16
|
+
# Query the `/nbstat` endpoint
|
|
17
|
+
try:
|
|
18
|
+
params = {
|
|
19
|
+
"location": "US",
|
|
20
|
+
"start": "2025-01-01",
|
|
21
|
+
"txt": "insurance NOT car"
|
|
22
|
+
}
|
|
23
|
+
data = client.query_endpoint("/nbstat", params=params)
|
|
24
|
+
print("Query successful:", data)
|
|
25
|
+
except Exception as e:
|
|
26
|
+
print(f"Error during query: {e}")
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alternative Macro Signals
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: ams-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python SDK for the Alternative Macro Signals API
|
|
5
|
+
Author: Laurent Bilke
|
|
6
|
+
Author-email: laurent@alternativemacrosignals.com
|
|
7
|
+
Requires-Python: >=3.7,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Dist: poetry (>=2.0.0,<3.0.0)
|
|
17
|
+
Requires-Dist: requests (>=2.0.0,<3.0.0)
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# AMS-SDK <img src="./logo_icon_small_tw.jpg" alt="Alternative Macro Signals Logo" width="90" align="right">
|
|
21
|
+

|
|
22
|
+
[](LICENSE)
|
|
23
|
+
|
|
24
|
+
[//]: # (<p align="right">)
|
|
25
|
+
|
|
26
|
+
[//]: # ( <img src="./logo_icon_small_tw.jpg" alt="Alternative Macro Signals Logo" width="100">)
|
|
27
|
+
|
|
28
|
+
[//]: # (</p>)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Python SDK for the Alternative Macro Signals (AMS) API, providing a convenient interface for authenticating and querying endpoints.
|
|
32
|
+
|
|
33
|
+
Please refer to the [AMS API documentation](https://github.com/alternative-macro-signals/api-docs)
|
|
34
|
+
for a detailed description of the API endpoints, including parameters specification.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Features ✨
|
|
39
|
+
|
|
40
|
+
- **Easy Queries**: Query from all AMS API endpoints in two lines of Python code
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
- **Authentication**: SDK takes care of the full authentication process, with just your API key required (given by AMS)
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Installation 🛠️
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Using pip
|
|
51
|
+
|
|
52
|
+
You can install the SDK from the source repository:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install git+[https://github.com/alternative-macro-signals/ams-sdk.git](https://github.com/alternative-macro-signals/ams-sdk.git)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### Installation from Source
|
|
60
|
+
Alternatively, download or clone the repository, then navigate to its root folder and install with:
|
|
61
|
+
```bash
|
|
62
|
+
git clone [https://github.com/alternative-macro-signals/ams-sdk.git](https://github.com/alternative-macro-signals/ams-sdk.git)
|
|
63
|
+
cd ams-sdk
|
|
64
|
+
pip install
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Requirements 📋
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
The following dependencies are necessary to use this SDK:
|
|
74
|
+
|
|
75
|
+
- `Python 3.7` or higher (likely to work with 3+ but not tested)
|
|
76
|
+
- `requests>=2.0.0` (installed automatically if needed)
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Usage 📖
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Initialization
|
|
84
|
+
First, initialize the `AMSClient` with the service URL and API key provided by AMS.
|
|
85
|
+
```python
|
|
86
|
+
from ams_sdk.client import AMSClient
|
|
87
|
+
```
|
|
88
|
+
```python
|
|
89
|
+
client = AMSClient(service_url=SERVICE_URL, api_key=API_KEY)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Authentication
|
|
93
|
+
|
|
94
|
+
Call the `authenticate()` method to fetch the bearer token required for further requests:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
client.authenticate()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Querying Endpoints
|
|
101
|
+
|
|
102
|
+
Use the `query_endpoint` method to query specific AMS API endpoints:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
result = client.query_endpoint("/nbstat", params={
|
|
106
|
+
"location": "Japan",
|
|
107
|
+
"txt": "rice",
|
|
108
|
+
"start": "2021-01-01"
|
|
109
|
+
})
|
|
110
|
+
print(result)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### Output
|
|
116
|
+
|
|
117
|
+
Transfer the `nbstat` output in a Pandas dataframe:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
import pandas as pd
|
|
121
|
+
df = pd.DataFrame(result.get('content'))
|
|
122
|
+
df['date'] = pd.to_datetime(df['date'])
|
|
123
|
+
df = df.set_index('date')
|
|
124
|
+
df.sort_index(inplace=True)
|
|
125
|
+
```
|
|
126
|
+
---
|
|
127
|
+
## API endpoints callable from `AMSClient` 🌐
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
### [`/nbstat`](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nbstat.md)
|
|
131
|
+
[](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nbstat.md)
|
|
132
|
+
|
|
133
|
+
Retrieve Inflation News Balance and News Volumes associated with specific text queries.
|
|
134
|
+
|
|
135
|
+
### /nipi
|
|
136
|
+
[](#)
|
|
137
|
+
|
|
138
|
+
Download NIPI data (meanwhile possible from the NIPI app or our CSV files endpoints)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
### /inb
|
|
142
|
+
[](#)
|
|
143
|
+
|
|
144
|
+
Inflation NewsBot daily lists (meanwhile possible through dedicated JSON endpoints).
|
|
145
|
+
|
|
146
|
+
----
|
|
147
|
+
|
|
148
|
+
## We welcome suggestions! 💡
|
|
149
|
+
|
|
150
|
+
📧: support@alternativemacrosignals.com
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Project Structure 📂
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
- **`client.py`**: Contains the `AMSClient` class which offers the core functionality for interacting with the API.
|
|
158
|
+
- **`utils.py`**: `AMSClient` usage examples.
|
|
159
|
+
- **`setup.py`**: Handles package configuration and installation details.
|
|
160
|
+
- **`README.md`**: Documentation for the `ams-sdk`.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## License 📜
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
This project is licensed under the MIT License. See the [LICENSE](https://github.com/alternative-macro-signals/ams-sdk/blob/main/LICENSE) file for details.
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Author
|
|
173
|
+
|
|
174
|
+
- **Author**: Laurent Bilke - [laurent@alternativemacrosignals.com](mailto:laurent@alternativemacrosignals.com)
|
|
175
|
+
- **Repository**: [GitHub](https://github.com/alternative-macro-signals/ams-sdk)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
---------
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
© 2025 Alternative Macro Signals. All rights reserved. https://alt.ms <img src="./logo_icon_small_tw.jpg" alt="Alternative Macro Signals Logo" width="30" align="right">
|
|
186
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ams_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
ams_sdk/client.py,sha256=rRPKv8XS12Dy4udhwCd5AXKEeSgFM3W-oQ1rW2SFlhc,2361
|
|
3
|
+
ams_sdk/utils.py,sha256=EpGhSYuo6oBwWkRzJNa4zlU_YOLnh-XIyvvt2iluLDY,713
|
|
4
|
+
ams_sdk-1.0.0.dist-info/LICENSE,sha256=NiEckLeU_6FlPYe-FtIdkRFOvFFfgU6ivneSHmkxEbY,1082
|
|
5
|
+
ams_sdk-1.0.0.dist-info/METADATA,sha256=VCSMx-lORhYKu9sQsxd4Ge6lSKwLotztihFIV_zhN2I,5056
|
|
6
|
+
ams_sdk-1.0.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
7
|
+
ams_sdk-1.0.0.dist-info/RECORD,,
|