openapi-python-sdk 0.1.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.
|
File without changes
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
OAUTH_BASE_URL = "https://oauth.openapi.it"
|
|
7
|
+
TEST_OAUTH_BASE_URL = "https://test.oauth.openapi.it"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class OauthClient:
|
|
11
|
+
def __init__(self, username: str, apikey: str, test: bool = False):
|
|
12
|
+
self.client = httpx.Client()
|
|
13
|
+
self.url: str = TEST_OAUTH_BASE_URL if test else OAUTH_BASE_URL
|
|
14
|
+
self.auth_header: str = (
|
|
15
|
+
"Basic " + base64.b64encode(f"{username}:{apikey}".encode("utf-8")).decode()
|
|
16
|
+
)
|
|
17
|
+
self.headers: Dict[str, Any] = {
|
|
18
|
+
"Authorization": self.auth_header,
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def get_scopes(self, limit: bool = False) -> Dict[str, Any]:
|
|
23
|
+
params = {"limit": int(limit)}
|
|
24
|
+
url = f"{self.url}/scopes"
|
|
25
|
+
return self.client.get(url=url, headers=self.headers, params=params).json()
|
|
26
|
+
|
|
27
|
+
def create_token(self, scopes: list[str] = [], ttl: int = 0) -> Dict[str, Any]:
|
|
28
|
+
payload = {"scopes": scopes, "ttl": ttl}
|
|
29
|
+
url = f"{self.url}/token"
|
|
30
|
+
return self.client.post(url=url, headers=self.headers, json=payload).json()
|
|
31
|
+
|
|
32
|
+
def get_token(self, scope: str = None) -> Dict[str, Any]:
|
|
33
|
+
params = {"scope": scope or ""}
|
|
34
|
+
url = f"{self.url}/token"
|
|
35
|
+
return self.client.get(url=url, headers=self.headers, params=params).json()
|
|
36
|
+
|
|
37
|
+
def delete_token(self, id: str) -> Dict[str, Any]:
|
|
38
|
+
url = f"{self.url}/token/{id}"
|
|
39
|
+
return self.client.delete(url=url, headers=self.headers).json()
|
|
40
|
+
|
|
41
|
+
def get_counters(self, period: str, date: str) -> Dict[str, Any]:
|
|
42
|
+
url = f"{self.url}/counters/{period}/{date}"
|
|
43
|
+
return self.client.get(url=url, headers=self.headers).json()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class Client:
|
|
47
|
+
def __init__(self, token: str):
|
|
48
|
+
self.client = httpx.Client()
|
|
49
|
+
self.auth_header: str = f"Bearer {token}"
|
|
50
|
+
self.headers: Dict[str, str] = {
|
|
51
|
+
"Authorization": self.auth_header,
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
def request(
|
|
56
|
+
self,
|
|
57
|
+
method: str = "GET",
|
|
58
|
+
url: str = None,
|
|
59
|
+
payload: Dict[str, Any] = None,
|
|
60
|
+
params: Dict[str, Any] = None,
|
|
61
|
+
) -> Dict[str, Any]:
|
|
62
|
+
payload = payload or {}
|
|
63
|
+
params = params or {}
|
|
64
|
+
url = url or ""
|
|
65
|
+
return self.client.request(
|
|
66
|
+
method=method,
|
|
67
|
+
url=url,
|
|
68
|
+
headers=self.headers,
|
|
69
|
+
json=payload,
|
|
70
|
+
params=params,
|
|
71
|
+
).json()
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: openapi-python-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary:
|
|
5
|
+
Author: Michael Cuffaro
|
|
6
|
+
Author-email: michael@cuffaro.com
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Requires-Dist: httpx (>=0.24.0,<0.25.0)
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
<div align="center">
|
|
18
|
+
<a href="https://openapi.com/">
|
|
19
|
+
<img alt="Openapi SDK for Python" src=".github/assets/repo-header-a3.png" >
|
|
20
|
+
</a>
|
|
21
|
+
|
|
22
|
+
<h1>Openapi® client for Python</h1>
|
|
23
|
+
<h4>The perfect starting point to integrate <a href="https://openapi.com/">Openapi®</a> within your Python project</h4>
|
|
24
|
+
|
|
25
|
+
[](https://github.com/openapi/openapi-python-sdk/actions/workflows/python.yml)
|
|
26
|
+
[](https://pypi.org/project/openapi-python-sdk/)
|
|
27
|
+
[](https://pypi.org/project/openapi-python-sdk/)
|
|
28
|
+
[](LICENSE)
|
|
29
|
+
[](https://pypi.org/project/openapi-python-sdk/)
|
|
30
|
+
<br>
|
|
31
|
+
[](https://www.linuxfoundation.org/about/members)
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
## Overview
|
|
35
|
+
|
|
36
|
+
A minimal and agnostic Python SDK for Openapi, inspired by a clean client implementation. This SDK provides only the core HTTP primitives needed to interact with any Openapi service.
|
|
37
|
+
|
|
38
|
+
## Pre-requisites
|
|
39
|
+
|
|
40
|
+
Before using the Openapi Python Client, you will need an account at [Openapi](https://console.openapi.com/) and an API key to the sandbox and/or production environment
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- **Agnostic Design**: No API-specific classes, works with any OpenAPI service
|
|
45
|
+
- **Minimal Dependencies**: Only requires Python 3.8+ and `requests`
|
|
46
|
+
- **OAuth Support**: Built-in OAuth client for token management
|
|
47
|
+
- **HTTP Primitives**: GET, POST, PUT, DELETE, PATCH methods
|
|
48
|
+
- **Clean Interface**: Similar to the Rust SDK design
|
|
49
|
+
|
|
50
|
+
## What you can do
|
|
51
|
+
|
|
52
|
+
With the Openapi Python Client, you can easily interact with a variety of services in the Openapi Marketplace. For example, you can:
|
|
53
|
+
|
|
54
|
+
- 📩 **Send SMS messages** with delivery reports and custom sender IDs
|
|
55
|
+
- 💸 **Process bills and payments** in real time via API
|
|
56
|
+
- 🧾 **Send electronic invoices** securely to the Italian Revenue Agency
|
|
57
|
+
- 📄 **Generate PDFs** from HTML content, including JavaScript rendering
|
|
58
|
+
- ✉️ **Manage certified emails** and legal communications via Italian Legalmail
|
|
59
|
+
|
|
60
|
+
For a complete list of all available services, check out the [Openapi Marketplace](https://console.openapi.com/) 🌐
|
|
61
|
+
|
|
62
|
+
# OpenApi IT Python Client
|
|
63
|
+
|
|
64
|
+
This client is used to interact with the API found at [openapi.it](https://openapi.it/)
|
|
65
|
+
|
|
66
|
+
## Pre-requisites
|
|
67
|
+
|
|
68
|
+
Before using the OpenApi IT Python Client, you will need an account at [openapi.it](https://openapi.it/) and an API key to the sandbox and/or production environment
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
You can install the OpenApi IT Python Client with the following command using go get:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install openapi-python-sdk
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from openapi_python_sdk.client import Client, OauthClient
|
|
83
|
+
|
|
84
|
+
# Initialize the oauth client on the sandbox environment
|
|
85
|
+
oauth_client = OauthClient(
|
|
86
|
+
username="<your_username>", apikey="<your_apikey>", test=True
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Create a token for a list of scopes
|
|
90
|
+
resp = oauth_client.create_token(
|
|
91
|
+
scopes=[
|
|
92
|
+
"GET:test.imprese.openapi.it/advance",
|
|
93
|
+
"POST:test.postontarget.com/fields/country",
|
|
94
|
+
],
|
|
95
|
+
ttl=3600,
|
|
96
|
+
)
|
|
97
|
+
token = resp["token"]
|
|
98
|
+
|
|
99
|
+
# Initialize the client
|
|
100
|
+
client = Client(token=token)
|
|
101
|
+
|
|
102
|
+
# Make a request with params
|
|
103
|
+
resp = client.request(
|
|
104
|
+
method="GET",
|
|
105
|
+
url="https://test.imprese.openapi.it/advance",
|
|
106
|
+
params={"denominazione": "altravia", "provincia": "RM", "codice_ateco": "6201"},
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
# Make a request with a payload
|
|
110
|
+
resp = client.request(
|
|
111
|
+
method="POST",
|
|
112
|
+
url="https://test.postontarget.com/fields/country",
|
|
113
|
+
payload={"limit": 0, "query": { "country_code": "IT"}}
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
# Delete the token
|
|
117
|
+
resp = oauth_client.delete_token(id=token)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
## Contributing
|
|
124
|
+
|
|
125
|
+
Contributions are always welcome! Whether you want to report bugs, suggest new features, improve documentation, or contribute code, your help is appreciated.
|
|
126
|
+
|
|
127
|
+
See [docs/contributing.md](docs/contributing.md) for detailed instructions on how to get started. Please make sure to follow this project's [docs/code-of-conduct.md](docs/code-of-conduct.md) to help maintain a welcoming and collaborative environment.
|
|
128
|
+
|
|
129
|
+
## Authors
|
|
130
|
+
|
|
131
|
+
Meet the project authors:
|
|
132
|
+
|
|
133
|
+
- Michael Cuffaro ([@maiku1008](https://www.github.com/maiku1008))
|
|
134
|
+
- Openapi Team ([@openapi-it](https://github.com/openapi-it))
|
|
135
|
+
|
|
136
|
+
## Partners
|
|
137
|
+
|
|
138
|
+
Meet our partners using Openapi or contributing to this SDK:
|
|
139
|
+
|
|
140
|
+
- [Blank](https://www.blank.app/)
|
|
141
|
+
- [Credit Safe](https://www.creditsafe.com/)
|
|
142
|
+
- [Deliveroo](https://deliveroo.it/)
|
|
143
|
+
- [Gruppo MOL](https://molgroupitaly.it/it/)
|
|
144
|
+
- [Jakala](https://www.jakala.com/)
|
|
145
|
+
- [Octotelematics](https://www.octotelematics.com/)
|
|
146
|
+
- [OTOQI](https://otoqi.com/)
|
|
147
|
+
- [PWC](https://www.pwc.com/)
|
|
148
|
+
- [QOMODO S.R.L.](https://www.qomodo.me/)
|
|
149
|
+
- [SOUNDREEF S.P.A.](https://www.soundreef.com/)
|
|
150
|
+
|
|
151
|
+
## Our Commitments
|
|
152
|
+
|
|
153
|
+
We believe in open source and we act on that belief. We became Silver Members
|
|
154
|
+
of the Linux Foundation because we wanted to formally support the ecosystem
|
|
155
|
+
we build on every day. Open standards, open collaboration, and open governance
|
|
156
|
+
are part of how we work and how we think about software.
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
161
|
+
|
|
162
|
+
The MIT License is a permissive open-source license that allows you to freely use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, provided that the original copyright notice and this permission notice are included in all copies or substantial portions of the software.
|
|
163
|
+
|
|
164
|
+
In short, you are free to use this SDK in your personal, academic, or commercial projects, with minimal restrictions. The project is provided "as-is", without any warranty of any kind, either expressed or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement.
|
|
165
|
+
|
|
166
|
+
For more details, see the full license text at the [MIT License page](https://choosealicense.com/licenses/mit/).
|
|
167
|
+
|
|
168
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
openapi_python_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
openapi_python_sdk/client.py,sha256=eFp_4OBZtVJM5oxmBwoqMnpzUyBbfHrG48JuyIr_ZrE,2443
|
|
3
|
+
openapi_python_sdk-0.1.0.dist-info/METADATA,sha256=uDaGL6GILPoO8ahG4Ys5Y3a0b_il-f4SH3fDbejm4gM,6691
|
|
4
|
+
openapi_python_sdk-0.1.0.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
|
|
5
|
+
openapi_python_sdk-0.1.0.dist-info/RECORD,,
|