inter-service-sdk 1.0.2__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.
- inter_service_sdk-1.0.2/LICENSE +21 -0
- inter_service_sdk-1.0.2/PKG-INFO +332 -0
- inter_service_sdk-1.0.2/README.md +283 -0
- inter_service_sdk-1.0.2/inter_service_sdk/__init__.py +42 -0
- inter_service_sdk-1.0.2/inter_service_sdk/client.py +251 -0
- inter_service_sdk-1.0.2/inter_service_sdk/crypto.py +177 -0
- inter_service_sdk-1.0.2/inter_service_sdk/exceptions.py +31 -0
- inter_service_sdk-1.0.2/inter_service_sdk/server.py +238 -0
- inter_service_sdk-1.0.2/inter_service_sdk/utils.py +61 -0
- inter_service_sdk-1.0.2/inter_service_sdk.egg-info/PKG-INFO +332 -0
- inter_service_sdk-1.0.2/inter_service_sdk.egg-info/SOURCES.txt +19 -0
- inter_service_sdk-1.0.2/inter_service_sdk.egg-info/dependency_links.txt +1 -0
- inter_service_sdk-1.0.2/inter_service_sdk.egg-info/requires.txt +18 -0
- inter_service_sdk-1.0.2/inter_service_sdk.egg-info/top_level.txt +1 -0
- inter_service_sdk-1.0.2/pyproject.toml +96 -0
- inter_service_sdk-1.0.2/setup.cfg +4 -0
- inter_service_sdk-1.0.2/setup.py +80 -0
- inter_service_sdk-1.0.2/tests/test_client.py +491 -0
- inter_service_sdk-1.0.2/tests/test_crypto.py +268 -0
- inter_service_sdk-1.0.2/tests/test_server.py +351 -0
- inter_service_sdk-1.0.2/tests/test_utils.py +156 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Blazel
|
|
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,332 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: inter-service-sdk
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Complete framework for inter-service communication with client, server utilities, auth and encryption
|
|
5
|
+
Home-page: https://github.com/AlexanderRyzhko/inter-service-sdk
|
|
6
|
+
Author: Blazel
|
|
7
|
+
Author-email: Blazel <dev@blazel.com>
|
|
8
|
+
Project-URL: Homepage, https://github.com/AlexanderRyzhko/inter-service-sdk
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/AlexanderRyzhko/inter-service-sdk/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/AlexanderRyzhko/inter-service-sdk#readme
|
|
11
|
+
Project-URL: Source Code, https://github.com/AlexanderRyzhko/inter-service-sdk
|
|
12
|
+
Keywords: http,client,server,api,rest,fastapi,inter-service,microservices,authentication,encryption,ecc,bearer-token
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
25
|
+
Classifier: Topic :: Security :: Cryptography
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: requests>=2.31.0
|
|
30
|
+
Requires-Dist: fastapi>=0.104.0
|
|
31
|
+
Provides-Extra: crypto
|
|
32
|
+
Requires-Dist: cryptography>=41.0.0; extra == "crypto"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-mock>=3.11.1; extra == "dev"
|
|
37
|
+
Requires-Dist: requests-mock>=1.11.0; extra == "dev"
|
|
38
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: flake8>=6.1.0; extra == "dev"
|
|
40
|
+
Requires-Dist: mypy>=1.5.0; extra == "dev"
|
|
41
|
+
Requires-Dist: types-requests>=2.31.0; extra == "dev"
|
|
42
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
43
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
44
|
+
Requires-Dist: cryptography>=41.0.0; extra == "dev"
|
|
45
|
+
Dynamic: author
|
|
46
|
+
Dynamic: home-page
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
Dynamic: requires-python
|
|
49
|
+
|
|
50
|
+
# Inter-Service SDK
|
|
51
|
+
|
|
52
|
+
Generic HTTP client for secure service-to-service communication with bearer token authentication and optional ECC encryption.
|
|
53
|
+
|
|
54
|
+
## Features
|
|
55
|
+
|
|
56
|
+
- 🔐 **Bearer Token Auth** - Automatic authentication headers
|
|
57
|
+
- 🔒 **Optional ECC Encryption** - End-to-end encryption for sensitive data
|
|
58
|
+
- 🎯 **Path & Query Parameters** - Clean parameter substitution
|
|
59
|
+
- 🔄 **Automatic Retries** - Exponential backoff for failed requests
|
|
60
|
+
- 📝 **Structured Logging** - Request/response tracking
|
|
61
|
+
- 🚀 **Zero Dependencies** - Only requests and cryptography (optional)
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install inter-service-sdk
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Quick Start
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from inter_service_sdk import InterServiceClient
|
|
73
|
+
|
|
74
|
+
# Initialize client
|
|
75
|
+
client = InterServiceClient(
|
|
76
|
+
base_url="https://api.example.com",
|
|
77
|
+
api_key="your-secret-key"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Make a request
|
|
81
|
+
response = client.request(
|
|
82
|
+
endpoint="users/{user_id}",
|
|
83
|
+
path_params={"user_id": 123}
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
print(response["data"])
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
### Basic GET Request
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
client = InterServiceClient(
|
|
95
|
+
base_url="https://api.example.com",
|
|
96
|
+
api_key="your-api-key"
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
# GET /api/v1/inter-service/users/123
|
|
100
|
+
user = client.request(
|
|
101
|
+
endpoint="users/{user_id}",
|
|
102
|
+
path_params={"user_id": 123}
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### With Query Parameters
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
# GET /api/v1/inter-service/users/search?q=john&type=email&limit=10
|
|
110
|
+
results = client.request(
|
|
111
|
+
endpoint="users/search",
|
|
112
|
+
query_params={
|
|
113
|
+
"q": "john",
|
|
114
|
+
"type": "email",
|
|
115
|
+
"limit": 10
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### POST Request
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
# POST /api/v1/inter-service/users
|
|
124
|
+
new_user = client.request(
|
|
125
|
+
endpoint="users",
|
|
126
|
+
method="POST",
|
|
127
|
+
data={
|
|
128
|
+
"name": "John Doe",
|
|
129
|
+
"email": "john@example.com"
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### With ECC Encryption
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
client = InterServiceClient(
|
|
138
|
+
base_url="https://api.example.com",
|
|
139
|
+
api_key="your-api-key",
|
|
140
|
+
ecc_private_key=os.getenv("PRIVATE_KEY"),
|
|
141
|
+
ecc_public_key=os.getenv("PUBLIC_KEY")
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# Auto-decrypt response
|
|
145
|
+
credentials = client.request(
|
|
146
|
+
endpoint="credentials/{id}",
|
|
147
|
+
path_params={"id": 456},
|
|
148
|
+
decrypt=True
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# Auto-encrypt request
|
|
152
|
+
client.request(
|
|
153
|
+
endpoint="secrets",
|
|
154
|
+
method="POST",
|
|
155
|
+
data={"secret": "sensitive data"},
|
|
156
|
+
encrypt=True
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Custom API Prefix
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
# Default prefix: /api/v1/inter-service
|
|
164
|
+
client = InterServiceClient(
|
|
165
|
+
base_url="https://api.example.com",
|
|
166
|
+
api_key="key",
|
|
167
|
+
api_prefix="/v2/api" # Custom prefix
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Override per request
|
|
171
|
+
response = client.request(
|
|
172
|
+
endpoint="custom",
|
|
173
|
+
api_prefix="/internal"
|
|
174
|
+
)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## API Reference
|
|
178
|
+
|
|
179
|
+
### InterServiceClient
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
InterServiceClient(
|
|
183
|
+
base_url: str,
|
|
184
|
+
api_key: str,
|
|
185
|
+
api_prefix: str = "/api/v1/inter-service",
|
|
186
|
+
timeout: int = 30,
|
|
187
|
+
retry_attempts: int = 3,
|
|
188
|
+
ecc_private_key: str = None,
|
|
189
|
+
ecc_public_key: str = None
|
|
190
|
+
)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### Parameters
|
|
194
|
+
|
|
195
|
+
- `base_url` (str): Base URL of the API (e.g., "https://api.example.com")
|
|
196
|
+
- `api_key` (str): Bearer token for authentication
|
|
197
|
+
- `api_prefix` (str, optional): API prefix. Default: "/api/v1/inter-service"
|
|
198
|
+
- `timeout` (int, optional): Request timeout in seconds. Default: 30
|
|
199
|
+
- `retry_attempts` (int, optional): Number of retry attempts. Default: 3
|
|
200
|
+
- `ecc_private_key` (str, optional): ECC private key for decryption
|
|
201
|
+
- `ecc_public_key` (str, optional): ECC public key for encryption
|
|
202
|
+
|
|
203
|
+
### request()
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
client.request(
|
|
207
|
+
endpoint: str,
|
|
208
|
+
path_params: dict = None,
|
|
209
|
+
query_params: dict = None,
|
|
210
|
+
method: str = "GET",
|
|
211
|
+
data: dict = None,
|
|
212
|
+
headers: dict = None,
|
|
213
|
+
encrypt: bool = False,
|
|
214
|
+
decrypt: bool = False,
|
|
215
|
+
timeout: int = None,
|
|
216
|
+
api_prefix: str = None
|
|
217
|
+
) -> dict
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### Parameters
|
|
221
|
+
|
|
222
|
+
- `endpoint` (str): Endpoint template (e.g., "users/{user_id}")
|
|
223
|
+
- `path_params` (dict, optional): Path parameters for substitution
|
|
224
|
+
- `query_params` (dict, optional): Query string parameters
|
|
225
|
+
- `method` (str, optional): HTTP method. Default: "GET"
|
|
226
|
+
- `data` (dict, optional): Request body (JSON)
|
|
227
|
+
- `headers` (dict, optional): Additional headers
|
|
228
|
+
- `encrypt` (bool, optional): Auto-encrypt request data. Default: False
|
|
229
|
+
- `decrypt` (bool, optional): Auto-decrypt response. Default: False
|
|
230
|
+
- `timeout` (int, optional): Override default timeout
|
|
231
|
+
- `api_prefix` (str, optional): Override default API prefix
|
|
232
|
+
|
|
233
|
+
#### Returns
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
{
|
|
237
|
+
"status": "success" | "error",
|
|
238
|
+
"data": {...} | None,
|
|
239
|
+
"status_code": int,
|
|
240
|
+
"error": None | str
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Error Handling
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
response = client.request(endpoint="users/123")
|
|
248
|
+
|
|
249
|
+
if response["status"] == "success":
|
|
250
|
+
user = response["data"]
|
|
251
|
+
print(user)
|
|
252
|
+
else:
|
|
253
|
+
print(f"Error: {response['error']}")
|
|
254
|
+
print(f"Status code: {response['status_code']}")
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Configuration
|
|
258
|
+
|
|
259
|
+
### Environment Variables
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# Recommended approach
|
|
263
|
+
export API_BASE_URL="https://api.example.com"
|
|
264
|
+
export API_KEY="your-secret-key"
|
|
265
|
+
export ECC_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----..."
|
|
266
|
+
export ECC_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----..."
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
import os
|
|
271
|
+
from inter_service_sdk import InterServiceClient
|
|
272
|
+
|
|
273
|
+
client = InterServiceClient(
|
|
274
|
+
base_url=os.getenv("API_BASE_URL"),
|
|
275
|
+
api_key=os.getenv("API_KEY"),
|
|
276
|
+
ecc_private_key=os.getenv("ECC_PRIVATE_KEY"),
|
|
277
|
+
ecc_public_key=os.getenv("ECC_PUBLIC_KEY")
|
|
278
|
+
)
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Development
|
|
282
|
+
|
|
283
|
+
### Install Development Dependencies
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
pip install -r requirements-dev.txt
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Run Tests
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
pytest tests/ -v
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Run Tests with Coverage
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
pytest tests/ --cov=inter_service_sdk --cov-report=html
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Code Formatting
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
black inter_service_sdk tests
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Type Checking
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
mypy inter_service_sdk
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Examples
|
|
314
|
+
|
|
315
|
+
See the `examples/` directory for more usage examples:
|
|
316
|
+
|
|
317
|
+
- `basic_usage.py` - Simple GET request
|
|
318
|
+
- `with_encryption.py` - ECC encryption example
|
|
319
|
+
- `search_example.py` - Query parameters example
|
|
320
|
+
- `post_example.py` - POST request example
|
|
321
|
+
|
|
322
|
+
## License
|
|
323
|
+
|
|
324
|
+
MIT License - see LICENSE file for details.
|
|
325
|
+
|
|
326
|
+
## Contributing
|
|
327
|
+
|
|
328
|
+
Contributions are welcome! Please open an issue or submit a pull request.
|
|
329
|
+
|
|
330
|
+
## Support
|
|
331
|
+
|
|
332
|
+
For questions or issues, please open a GitHub issue.
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# Inter-Service SDK
|
|
2
|
+
|
|
3
|
+
Generic HTTP client for secure service-to-service communication with bearer token authentication and optional ECC encryption.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔐 **Bearer Token Auth** - Automatic authentication headers
|
|
8
|
+
- 🔒 **Optional ECC Encryption** - End-to-end encryption for sensitive data
|
|
9
|
+
- 🎯 **Path & Query Parameters** - Clean parameter substitution
|
|
10
|
+
- 🔄 **Automatic Retries** - Exponential backoff for failed requests
|
|
11
|
+
- 📝 **Structured Logging** - Request/response tracking
|
|
12
|
+
- 🚀 **Zero Dependencies** - Only requests and cryptography (optional)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install inter-service-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from inter_service_sdk import InterServiceClient
|
|
24
|
+
|
|
25
|
+
# Initialize client
|
|
26
|
+
client = InterServiceClient(
|
|
27
|
+
base_url="https://api.example.com",
|
|
28
|
+
api_key="your-secret-key"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# Make a request
|
|
32
|
+
response = client.request(
|
|
33
|
+
endpoint="users/{user_id}",
|
|
34
|
+
path_params={"user_id": 123}
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
print(response["data"])
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Basic GET Request
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
client = InterServiceClient(
|
|
46
|
+
base_url="https://api.example.com",
|
|
47
|
+
api_key="your-api-key"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# GET /api/v1/inter-service/users/123
|
|
51
|
+
user = client.request(
|
|
52
|
+
endpoint="users/{user_id}",
|
|
53
|
+
path_params={"user_id": 123}
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### With Query Parameters
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
# GET /api/v1/inter-service/users/search?q=john&type=email&limit=10
|
|
61
|
+
results = client.request(
|
|
62
|
+
endpoint="users/search",
|
|
63
|
+
query_params={
|
|
64
|
+
"q": "john",
|
|
65
|
+
"type": "email",
|
|
66
|
+
"limit": 10
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### POST Request
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
# POST /api/v1/inter-service/users
|
|
75
|
+
new_user = client.request(
|
|
76
|
+
endpoint="users",
|
|
77
|
+
method="POST",
|
|
78
|
+
data={
|
|
79
|
+
"name": "John Doe",
|
|
80
|
+
"email": "john@example.com"
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### With ECC Encryption
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
client = InterServiceClient(
|
|
89
|
+
base_url="https://api.example.com",
|
|
90
|
+
api_key="your-api-key",
|
|
91
|
+
ecc_private_key=os.getenv("PRIVATE_KEY"),
|
|
92
|
+
ecc_public_key=os.getenv("PUBLIC_KEY")
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# Auto-decrypt response
|
|
96
|
+
credentials = client.request(
|
|
97
|
+
endpoint="credentials/{id}",
|
|
98
|
+
path_params={"id": 456},
|
|
99
|
+
decrypt=True
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# Auto-encrypt request
|
|
103
|
+
client.request(
|
|
104
|
+
endpoint="secrets",
|
|
105
|
+
method="POST",
|
|
106
|
+
data={"secret": "sensitive data"},
|
|
107
|
+
encrypt=True
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Custom API Prefix
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# Default prefix: /api/v1/inter-service
|
|
115
|
+
client = InterServiceClient(
|
|
116
|
+
base_url="https://api.example.com",
|
|
117
|
+
api_key="key",
|
|
118
|
+
api_prefix="/v2/api" # Custom prefix
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# Override per request
|
|
122
|
+
response = client.request(
|
|
123
|
+
endpoint="custom",
|
|
124
|
+
api_prefix="/internal"
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## API Reference
|
|
129
|
+
|
|
130
|
+
### InterServiceClient
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
InterServiceClient(
|
|
134
|
+
base_url: str,
|
|
135
|
+
api_key: str,
|
|
136
|
+
api_prefix: str = "/api/v1/inter-service",
|
|
137
|
+
timeout: int = 30,
|
|
138
|
+
retry_attempts: int = 3,
|
|
139
|
+
ecc_private_key: str = None,
|
|
140
|
+
ecc_public_key: str = None
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### Parameters
|
|
145
|
+
|
|
146
|
+
- `base_url` (str): Base URL of the API (e.g., "https://api.example.com")
|
|
147
|
+
- `api_key` (str): Bearer token for authentication
|
|
148
|
+
- `api_prefix` (str, optional): API prefix. Default: "/api/v1/inter-service"
|
|
149
|
+
- `timeout` (int, optional): Request timeout in seconds. Default: 30
|
|
150
|
+
- `retry_attempts` (int, optional): Number of retry attempts. Default: 3
|
|
151
|
+
- `ecc_private_key` (str, optional): ECC private key for decryption
|
|
152
|
+
- `ecc_public_key` (str, optional): ECC public key for encryption
|
|
153
|
+
|
|
154
|
+
### request()
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
client.request(
|
|
158
|
+
endpoint: str,
|
|
159
|
+
path_params: dict = None,
|
|
160
|
+
query_params: dict = None,
|
|
161
|
+
method: str = "GET",
|
|
162
|
+
data: dict = None,
|
|
163
|
+
headers: dict = None,
|
|
164
|
+
encrypt: bool = False,
|
|
165
|
+
decrypt: bool = False,
|
|
166
|
+
timeout: int = None,
|
|
167
|
+
api_prefix: str = None
|
|
168
|
+
) -> dict
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Parameters
|
|
172
|
+
|
|
173
|
+
- `endpoint` (str): Endpoint template (e.g., "users/{user_id}")
|
|
174
|
+
- `path_params` (dict, optional): Path parameters for substitution
|
|
175
|
+
- `query_params` (dict, optional): Query string parameters
|
|
176
|
+
- `method` (str, optional): HTTP method. Default: "GET"
|
|
177
|
+
- `data` (dict, optional): Request body (JSON)
|
|
178
|
+
- `headers` (dict, optional): Additional headers
|
|
179
|
+
- `encrypt` (bool, optional): Auto-encrypt request data. Default: False
|
|
180
|
+
- `decrypt` (bool, optional): Auto-decrypt response. Default: False
|
|
181
|
+
- `timeout` (int, optional): Override default timeout
|
|
182
|
+
- `api_prefix` (str, optional): Override default API prefix
|
|
183
|
+
|
|
184
|
+
#### Returns
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
{
|
|
188
|
+
"status": "success" | "error",
|
|
189
|
+
"data": {...} | None,
|
|
190
|
+
"status_code": int,
|
|
191
|
+
"error": None | str
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Error Handling
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
response = client.request(endpoint="users/123")
|
|
199
|
+
|
|
200
|
+
if response["status"] == "success":
|
|
201
|
+
user = response["data"]
|
|
202
|
+
print(user)
|
|
203
|
+
else:
|
|
204
|
+
print(f"Error: {response['error']}")
|
|
205
|
+
print(f"Status code: {response['status_code']}")
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Configuration
|
|
209
|
+
|
|
210
|
+
### Environment Variables
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# Recommended approach
|
|
214
|
+
export API_BASE_URL="https://api.example.com"
|
|
215
|
+
export API_KEY="your-secret-key"
|
|
216
|
+
export ECC_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----..."
|
|
217
|
+
export ECC_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----..."
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
import os
|
|
222
|
+
from inter_service_sdk import InterServiceClient
|
|
223
|
+
|
|
224
|
+
client = InterServiceClient(
|
|
225
|
+
base_url=os.getenv("API_BASE_URL"),
|
|
226
|
+
api_key=os.getenv("API_KEY"),
|
|
227
|
+
ecc_private_key=os.getenv("ECC_PRIVATE_KEY"),
|
|
228
|
+
ecc_public_key=os.getenv("ECC_PUBLIC_KEY")
|
|
229
|
+
)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Development
|
|
233
|
+
|
|
234
|
+
### Install Development Dependencies
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
pip install -r requirements-dev.txt
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Run Tests
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
pytest tests/ -v
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Run Tests with Coverage
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
pytest tests/ --cov=inter_service_sdk --cov-report=html
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Code Formatting
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
black inter_service_sdk tests
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Type Checking
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
mypy inter_service_sdk
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Examples
|
|
265
|
+
|
|
266
|
+
See the `examples/` directory for more usage examples:
|
|
267
|
+
|
|
268
|
+
- `basic_usage.py` - Simple GET request
|
|
269
|
+
- `with_encryption.py` - ECC encryption example
|
|
270
|
+
- `search_example.py` - Query parameters example
|
|
271
|
+
- `post_example.py` - POST request example
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT License - see LICENSE file for details.
|
|
276
|
+
|
|
277
|
+
## Contributing
|
|
278
|
+
|
|
279
|
+
Contributions are welcome! Please open an issue or submit a pull request.
|
|
280
|
+
|
|
281
|
+
## Support
|
|
282
|
+
|
|
283
|
+
For questions or issues, please open a GitHub issue.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Inter-Service SDK - Complete framework for service-to-service communication.
|
|
3
|
+
|
|
4
|
+
Provides both client-side and server-side utilities:
|
|
5
|
+
- Client: InterServiceClient for making inter-service HTTP requests
|
|
6
|
+
- Server: FastAPI utilities for creating inter-service endpoints
|
|
7
|
+
- Crypto: Optional ECC encryption/decryption
|
|
8
|
+
- Exceptions: Custom exception hierarchy
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .client import InterServiceClient
|
|
12
|
+
from .exceptions import (
|
|
13
|
+
InterServiceError,
|
|
14
|
+
AuthenticationError,
|
|
15
|
+
RequestError,
|
|
16
|
+
EncryptionError,
|
|
17
|
+
URLBuildError
|
|
18
|
+
)
|
|
19
|
+
from .server import (
|
|
20
|
+
create_inter_service_router,
|
|
21
|
+
inter_service_endpoint,
|
|
22
|
+
format_error_response,
|
|
23
|
+
format_success_response
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
__version__ = "1.0.2"
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
# Client
|
|
30
|
+
"InterServiceClient",
|
|
31
|
+
# Exceptions
|
|
32
|
+
"InterServiceError",
|
|
33
|
+
"AuthenticationError",
|
|
34
|
+
"RequestError",
|
|
35
|
+
"EncryptionError",
|
|
36
|
+
"URLBuildError",
|
|
37
|
+
# Server utilities
|
|
38
|
+
"create_inter_service_router",
|
|
39
|
+
"inter_service_endpoint",
|
|
40
|
+
"format_error_response",
|
|
41
|
+
"format_success_response",
|
|
42
|
+
]
|