ams-sdk 1.0.6__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.
ams_sdk-1.0.6/LICENSE ADDED
@@ -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.
ams_sdk-1.0.6/PKG-INFO ADDED
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.3
2
+ Name: ams-sdk
3
+ Version: 1.0.6
4
+ Summary: Python SDK for the Alternative Macro Signals API
5
+ Author: Laurent Bilke
6
+ Author-email: laurent@alternativemacrosignals.com
7
+ Classifier: Programming Language :: Python :: 2
8
+ Classifier: Programming Language :: Python :: 2.7
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.4
11
+ Classifier: Programming Language :: Python :: 3.5
12
+ Classifier: Programming Language :: Python :: 3.6
13
+ Classifier: Programming Language :: Python :: 3.7
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Requires-Dist: requests (>=2.0.0,<3.0.0)
21
+ Description-Content-Type: text/markdown
22
+
23
+ # AMS-SDK
24
+ ![Python Version](https://img.shields.io/badge/Python-3.7%2B-blue)
25
+ [![License](https://img.shields.io/badge/License-MIT-yellow)](LICENSE)
26
+
27
+ `ams-sdk` is a wrapper around `ams-api` and handles the authentification and query process in just a few steps.
28
+
29
+
30
+
31
+ Please refer to [AMS API documentation](https://github.com/alternative-macro-signals/api-docs)
32
+ for a detailed description of the API endpoints, including parameters specification.
33
+
34
+ ---
35
+
36
+ ## Features ✨
37
+
38
+ - **Easy Queries**: Query from all AMS API endpoints in two lines of Python code
39
+
40
+
41
+ - **Authentication**: SDK takes care of the full authentication process, with just your API key required (given by AMS)
42
+
43
+ ---
44
+
45
+ ## Installation 🛠️
46
+
47
+ From PyPI (recommended):
48
+
49
+ ```shell
50
+ pip install ams-sdk
51
+ ```
52
+
53
+ Alternatively, directly from repo:
54
+
55
+ ```shell
56
+ pip install git+https://github.com/alternative-macro-signals/ams-sdk.git
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Requirements 📋
62
+
63
+
64
+ The following dependencies are necessary to use this SDK:
65
+
66
+ - `Python 3.7` or higher (likely to work with 3+ but not tested)
67
+ - `requests>=2.0.0` (installed automatically if needed)
68
+
69
+ ---
70
+
71
+ ## Usage 📖
72
+
73
+
74
+ ### Initialization
75
+ First, initialize the `AMSClient` with the service URL and API key provided by AMS.
76
+ ```python
77
+ from ams_sdk.client import AMSClient
78
+ ```
79
+ ```python
80
+ client = AMSClient(service_url=SERVICE_URL, api_key=API_KEY)
81
+ ```
82
+
83
+ ### Authentication
84
+
85
+ Call the `authenticate()` method to fetch the bearer token required for further requests:
86
+
87
+ ```python
88
+ client.authenticate()
89
+ ```
90
+
91
+ ### Querying Endpoints
92
+
93
+ Use the `query_endpoint` method to query specific AMS API endpoints:
94
+
95
+ ```python
96
+ result = client.query_endpoint("/nbstat", params={
97
+ "location": "Japan",
98
+ "txt": "rice",
99
+ "start": "2021-01-01"
100
+ })
101
+ print(result)
102
+ ```
103
+
104
+ ```python
105
+ result = client.query_endpoint("/nipi", params={
106
+ "location": "Euro area",
107
+ "sector": "Food",
108
+ })
109
+ print(result)
110
+ ```
111
+
112
+
113
+
114
+
115
+ ### Output
116
+
117
+ Transform the `/nbstat` or `/nipi` 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
+ In order to get 7-day and 30-day rolling balances from `/nbstat` (similar to the NewsBot app):
128
+ ```python
129
+ df7 = df.rolling(7).mean()
130
+ df30 = df.rolling(30).mean()
131
+ ```
132
+
133
+ Note: NIPI is already a 30-day rolling diffusion index.
134
+
135
+
136
+ ---
137
+ ## API endpoints callable from `AMSClient` 🌐
138
+
139
+
140
+ ### [`/nbstat`](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nbstat.md) [![API Status](https://img.shields.io/badge/API-Live-brightgreen)](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nbstat.md)
141
+
142
+ Retrieve Inflation News Balance and News Volumes associated with specific text queries.
143
+
144
+ ### [`/nipi`](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nipi.md) [![API Status](https://img.shields.io/badge/API-Live-brightgreen)](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nbstat.md)
145
+
146
+ [//]: # ([![API Status]&#40;https://img.shields.io/badge/API-Forthcoming-orange&#41;]&#40;#&#41;)
147
+
148
+ Download NIPI data.
149
+
150
+ [//]: # ()
151
+ [//]: # (### /inb)
152
+
153
+ [//]: # ([![API Status]&#40;https://img.shields.io/badge/API-Forthcoming-orange&#41;]&#40;#&#41;)
154
+
155
+ [//]: # ()
156
+ [//]: # (Inflation NewsBot daily lists &#40;meanwhile possible through dedicated JSON endpoints&#41;.)
157
+
158
+ ----
159
+
160
+ ## We welcome suggestions! 💡
161
+
162
+ 📧: support@alternativemacrosignals.com
163
+
164
+ ---
165
+
166
+ ## Project Structure 📂
167
+
168
+
169
+ - **`client.py`**: Contains the `AMSClient` class which offers the core functionality for interacting with the API.
170
+ - **`utils.py`**: `AMSClient` usage examples.
171
+ - **`setup.py`**: Handles package configuration and installation details.
172
+ - **`README.md`**: Documentation for the `ams-sdk`.
173
+
174
+ ---
175
+
176
+ ## License 📜
177
+
178
+
179
+ 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.
180
+
181
+
182
+ ---
183
+
184
+ ## Author
185
+
186
+ - **Author**: Laurent Bilke - [laurent@alternativemacrosignals.com](mailto:laurent@alternativemacrosignals.com)
187
+ - **Repository**: [GitHub](https://github.com/alternative-macro-signals/ams-sdk)
188
+
189
+
190
+
191
+
192
+
193
+ ---------
194
+
195
+
196
+
197
+ © 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">
198
+
@@ -0,0 +1,175 @@
1
+ # AMS-SDK
2
+ ![Python Version](https://img.shields.io/badge/Python-3.7%2B-blue)
3
+ [![License](https://img.shields.io/badge/License-MIT-yellow)](LICENSE)
4
+
5
+ `ams-sdk` is a wrapper around `ams-api` and handles the authentification and query process in just a few steps.
6
+
7
+
8
+
9
+ Please refer to [AMS API documentation](https://github.com/alternative-macro-signals/api-docs)
10
+ for a detailed description of the API endpoints, including parameters specification.
11
+
12
+ ---
13
+
14
+ ## Features ✨
15
+
16
+ - **Easy Queries**: Query from all AMS API endpoints in two lines of Python code
17
+
18
+
19
+ - **Authentication**: SDK takes care of the full authentication process, with just your API key required (given by AMS)
20
+
21
+ ---
22
+
23
+ ## Installation 🛠️
24
+
25
+ From PyPI (recommended):
26
+
27
+ ```shell
28
+ pip install ams-sdk
29
+ ```
30
+
31
+ Alternatively, directly from repo:
32
+
33
+ ```shell
34
+ pip install git+https://github.com/alternative-macro-signals/ams-sdk.git
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Requirements 📋
40
+
41
+
42
+ The following dependencies are necessary to use this SDK:
43
+
44
+ - `Python 3.7` or higher (likely to work with 3+ but not tested)
45
+ - `requests>=2.0.0` (installed automatically if needed)
46
+
47
+ ---
48
+
49
+ ## Usage 📖
50
+
51
+
52
+ ### Initialization
53
+ First, initialize the `AMSClient` with the service URL and API key provided by AMS.
54
+ ```python
55
+ from ams_sdk.client import AMSClient
56
+ ```
57
+ ```python
58
+ client = AMSClient(service_url=SERVICE_URL, api_key=API_KEY)
59
+ ```
60
+
61
+ ### Authentication
62
+
63
+ Call the `authenticate()` method to fetch the bearer token required for further requests:
64
+
65
+ ```python
66
+ client.authenticate()
67
+ ```
68
+
69
+ ### Querying Endpoints
70
+
71
+ Use the `query_endpoint` method to query specific AMS API endpoints:
72
+
73
+ ```python
74
+ result = client.query_endpoint("/nbstat", params={
75
+ "location": "Japan",
76
+ "txt": "rice",
77
+ "start": "2021-01-01"
78
+ })
79
+ print(result)
80
+ ```
81
+
82
+ ```python
83
+ result = client.query_endpoint("/nipi", params={
84
+ "location": "Euro area",
85
+ "sector": "Food",
86
+ })
87
+ print(result)
88
+ ```
89
+
90
+
91
+
92
+
93
+ ### Output
94
+
95
+ Transform the `/nbstat` or `/nipi` output in a Pandas dataframe:
96
+
97
+ ```python
98
+ import pandas as pd
99
+ df = pd.DataFrame(result.get('content'))
100
+ df['date'] = pd.to_datetime(df['date'])
101
+ df = df.set_index('date')
102
+ df.sort_index(inplace=True)
103
+ ```
104
+
105
+ In order to get 7-day and 30-day rolling balances from `/nbstat` (similar to the NewsBot app):
106
+ ```python
107
+ df7 = df.rolling(7).mean()
108
+ df30 = df.rolling(30).mean()
109
+ ```
110
+
111
+ Note: NIPI is already a 30-day rolling diffusion index.
112
+
113
+
114
+ ---
115
+ ## API endpoints callable from `AMSClient` 🌐
116
+
117
+
118
+ ### [`/nbstat`](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nbstat.md) [![API Status](https://img.shields.io/badge/API-Live-brightgreen)](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nbstat.md)
119
+
120
+ Retrieve Inflation News Balance and News Volumes associated with specific text queries.
121
+
122
+ ### [`/nipi`](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nipi.md) [![API Status](https://img.shields.io/badge/API-Live-brightgreen)](https://github.com/alternative-macro-signals/api-docs/blob/master/docs/api-reference/endpoints/nbstat.md)
123
+
124
+ [//]: # ([![API Status]&#40;https://img.shields.io/badge/API-Forthcoming-orange&#41;]&#40;#&#41;)
125
+
126
+ Download NIPI data.
127
+
128
+ [//]: # ()
129
+ [//]: # (### /inb)
130
+
131
+ [//]: # ([![API Status]&#40;https://img.shields.io/badge/API-Forthcoming-orange&#41;]&#40;#&#41;)
132
+
133
+ [//]: # ()
134
+ [//]: # (Inflation NewsBot daily lists &#40;meanwhile possible through dedicated JSON endpoints&#41;.)
135
+
136
+ ----
137
+
138
+ ## We welcome suggestions! 💡
139
+
140
+ 📧: support@alternativemacrosignals.com
141
+
142
+ ---
143
+
144
+ ## Project Structure 📂
145
+
146
+
147
+ - **`client.py`**: Contains the `AMSClient` class which offers the core functionality for interacting with the API.
148
+ - **`utils.py`**: `AMSClient` usage examples.
149
+ - **`setup.py`**: Handles package configuration and installation details.
150
+ - **`README.md`**: Documentation for the `ams-sdk`.
151
+
152
+ ---
153
+
154
+ ## License 📜
155
+
156
+
157
+ 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.
158
+
159
+
160
+ ---
161
+
162
+ ## Author
163
+
164
+ - **Author**: Laurent Bilke - [laurent@alternativemacrosignals.com](mailto:laurent@alternativemacrosignals.com)
165
+ - **Repository**: [GitHub](https://github.com/alternative-macro-signals/ams-sdk)
166
+
167
+
168
+
169
+
170
+
171
+ ---------
172
+
173
+
174
+
175
+ © 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">
File without changes
@@ -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
+
@@ -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}")
Binary file
@@ -0,0 +1,20 @@
1
+ [tool.poetry]
2
+ name = "ams-sdk"
3
+ version = "1.0.6"
4
+ description = "Python SDK for the Alternative Macro Signals API"
5
+ authors = ["Laurent Bilke <laurent@alternativemacrosignals.com>"]
6
+ readme = "README.md"
7
+ include = [
8
+ "logo_icon_small_tw.jpg",
9
+ "LICENSE",
10
+ ]
11
+ #requires-python = ">=3.9,<3.13"
12
+
13
+ [tool.poetry.dependencies]
14
+ #python = "^3.7"
15
+ #poetry = "^2.0.0"
16
+ requests = "^2.0.0"
17
+
18
+ [build-system]
19
+ requires = ["poetry-core"]
20
+ build-backend = "poetry.core.masonry.api"