emitfy 0.2.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.
emitfy-0.2.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Emitfy
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.
emitfy-0.2.2/PKG-INFO ADDED
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: emitfy
3
+ Version: 0.2.2
4
+ Summary: Official Emitfy API SDK for Python
5
+ Author: Emitfy
6
+ License: MIT
7
+ Project-URL: Homepage, https://api.emitfy.com/docs/sdks
8
+ Project-URL: Documentation, https://api.emitfy.com/docs
9
+ Project-URL: Repository, https://github.com/emitfy/emitfy-python
10
+ Keywords: emitfy,nfe,nfse,fiscal,brazil,sdk
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # emitfy (Python)
17
+
18
+ Official Emitfy API SDK for Python.
19
+
20
+ ```bash
21
+ pip install emitfy
22
+ ```
23
+
24
+ ```python
25
+ from emitfy import Emitfy
26
+ import os
27
+
28
+ emitfy = Emitfy(os.environ["EMITFY_API_KEY"], os.environ["EMITFY_API_SECRET"])
29
+ emitfy.webhooks.create({
30
+ "url": "https://seu-sistema.com/webhooks/emitfy",
31
+ "events": {"invoice": ["nfse.authorized"], "cte": []},
32
+ })
33
+ company = emitfy.company(os.environ["EMITFY_COMPANY_ID"])
34
+ company.nfse.create({"serviceDescription": "Serviço", "amount": 100})
35
+ ```
36
+
37
+ Docs: https://api.emitfy.com/docs/sdks
emitfy-0.2.2/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # emitfy (Python)
2
+
3
+ Official Emitfy API SDK for Python.
4
+
5
+ ```bash
6
+ pip install emitfy
7
+ ```
8
+
9
+ ```python
10
+ from emitfy import Emitfy
11
+ import os
12
+
13
+ emitfy = Emitfy(os.environ["EMITFY_API_KEY"], os.environ["EMITFY_API_SECRET"])
14
+ emitfy.webhooks.create({
15
+ "url": "https://seu-sistema.com/webhooks/emitfy",
16
+ "events": {"invoice": ["nfse.authorized"], "cte": []},
17
+ })
18
+ company = emitfy.company(os.environ["EMITFY_COMPANY_ID"])
19
+ company.nfse.create({"serviceDescription": "Serviço", "amount": 100})
20
+ ```
21
+
22
+ Docs: https://api.emitfy.com/docs/sdks
@@ -0,0 +1,225 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import time
5
+ import urllib.error
6
+ import urllib.parse
7
+ import urllib.request
8
+ from typing import Any
9
+
10
+
11
+ class EmitfyError(Exception):
12
+ def __init__(
13
+ self,
14
+ message: str,
15
+ code: str | None = None,
16
+ details: Any = None,
17
+ status_code: int = 0,
18
+ ) -> None:
19
+ super().__init__(message)
20
+ self.code = code
21
+ self.details = details
22
+ self.status_code = status_code
23
+
24
+
25
+ class _HttpClient:
26
+ def __init__(
27
+ self,
28
+ api_key: str,
29
+ api_secret: str,
30
+ base_url: str = "https://api.emitfy.com/v1",
31
+ max_retries: int = 2,
32
+ ) -> None:
33
+ self.api_key = api_key
34
+ self.api_secret = api_secret
35
+ self.base_url = base_url.rstrip("/")
36
+ self.max_retries = max_retries
37
+
38
+ def request(
39
+ self,
40
+ method: str,
41
+ path: str,
42
+ body: dict[str, Any] | None = None,
43
+ extra_headers: dict[str, str] | None = None,
44
+ ) -> Any:
45
+ url = f"{self.base_url}/{path.lstrip('/')}"
46
+ attempt = 0
47
+
48
+ while True:
49
+ attempt += 1
50
+ headers = {
51
+ "X-Api-Key": self.api_key,
52
+ "X-Api-Secret": self.api_secret,
53
+ "Accept": "application/json",
54
+ "Content-Type": "application/json",
55
+ }
56
+ if extra_headers:
57
+ headers.update(extra_headers)
58
+
59
+ data = None if body is None else json.dumps(body).encode("utf-8")
60
+ req = urllib.request.Request(url, data=data, headers=headers, method=method.upper())
61
+
62
+ try:
63
+ with urllib.request.urlopen(req) as response:
64
+ raw = response.read().decode("utf-8")
65
+ status = response.status
66
+ retry_after = response.headers.get("Retry-After", "1")
67
+ except urllib.error.HTTPError as exc:
68
+ raw = exc.read().decode("utf-8")
69
+ status = exc.code
70
+ retry_after = exc.headers.get("Retry-After", "1") if exc.headers else "1"
71
+
72
+ if status == 429 and attempt <= self.max_retries + 1:
73
+ time.sleep(max(1, int(retry_after or "1")))
74
+ continue
75
+
76
+ decoded = json.loads(raw) if raw else None
77
+
78
+ if status >= 400:
79
+ error = (decoded or {}).get("error") if isinstance(decoded, dict) else None
80
+ message = (
81
+ error.get("message")
82
+ if isinstance(error, dict)
83
+ else "Request failed."
84
+ )
85
+ raise EmitfyError(
86
+ str(message),
87
+ error.get("code") if isinstance(error, dict) else None,
88
+ error.get("details") if isinstance(error, dict) else None,
89
+ status,
90
+ )
91
+
92
+ if isinstance(decoded, dict) and "data" in decoded:
93
+ return decoded["data"]
94
+
95
+ return decoded
96
+
97
+
98
+ class CompanyResource:
99
+ def __init__(self, http: _HttpClient, base_path: str) -> None:
100
+ self._http = http
101
+ self._base_path = base_path
102
+
103
+ def list(self, **query: Any) -> Any:
104
+ path = self._base_path
105
+ if query:
106
+ path = f"{path}?{urllib.parse.urlencode(query)}"
107
+ return self._http.request("GET", path)
108
+
109
+ def create(self, payload: dict[str, Any], idempotency_key: str | None = None) -> Any:
110
+ headers = {"Idempotency-Key": idempotency_key} if idempotency_key else None
111
+ return self._http.request("POST", self._base_path, payload, headers)
112
+
113
+ def get(self, id: str) -> Any:
114
+ return self._http.request("GET", f"{self._base_path}/{urllib.parse.quote(id)}")
115
+
116
+ def update(self, id: str, payload: dict[str, Any]) -> Any:
117
+ return self._http.request("PUT", f"{self._base_path}/{urllib.parse.quote(id)}", payload)
118
+
119
+ def delete(self, id: str) -> Any:
120
+ return self._http.request("DELETE", f"{self._base_path}/{urllib.parse.quote(id)}")
121
+
122
+ def post(
123
+ self,
124
+ suffix: str,
125
+ payload: dict[str, Any] | None = None,
126
+ idempotency_key: str | None = None,
127
+ ) -> Any:
128
+ headers = {"Idempotency-Key": idempotency_key} if idempotency_key else None
129
+ return self._http.request(
130
+ "POST",
131
+ f"{self._base_path.rstrip('/')}/{suffix.lstrip('/')}",
132
+ payload,
133
+ headers,
134
+ )
135
+
136
+
137
+ class CompanyContext:
138
+ def __init__(self, http: _HttpClient, company_id: str) -> None:
139
+ self._http = http
140
+ self._company_id = company_id
141
+ prefix = f"/companies/{urllib.parse.quote(company_id)}"
142
+ self.nfse = CompanyResource(http, f"{prefix}/nfse")
143
+ self.nfe = CompanyResource(http, f"{prefix}/nfe")
144
+ self.nfce = CompanyResource(http, f"{prefix}/nfce")
145
+ self.cte = CompanyResource(http, f"{prefix}/cte")
146
+ self.customers = CompanyResource(http, f"{prefix}/customers")
147
+ self.products = CompanyResource(http, f"{prefix}/products")
148
+ self.sales = CompanyResource(http, f"{prefix}/sales")
149
+ self.invoices = CompanyResource(http, f"{prefix}/invoices")
150
+ self.received_nfes = CompanyResource(http, f"{prefix}/received-nfes")
151
+
152
+ def id(self) -> str:
153
+ return self._company_id
154
+
155
+ def create_cte_os(
156
+ self, payload: dict[str, Any], idempotency_key: str | None = None
157
+ ) -> Any:
158
+ headers = {"Idempotency-Key": idempotency_key} if idempotency_key else None
159
+ return self._http.request(
160
+ "POST",
161
+ f"/companies/{urllib.parse.quote(self._company_id)}/cte-os",
162
+ payload,
163
+ headers,
164
+ )
165
+
166
+
167
+ class Emitfy:
168
+ def __init__(
169
+ self,
170
+ api_key: str,
171
+ api_secret: str,
172
+ base_url: str = "https://api.emitfy.com/v1",
173
+ max_retries: int = 2,
174
+ ) -> None:
175
+ api_key = (api_key or "").strip()
176
+ api_secret = (api_secret or "").strip()
177
+ if not api_key or not api_secret:
178
+ raise EmitfyError("api_key and api_secret are required.")
179
+ self._http = _HttpClient(api_key, api_secret, base_url, max_retries)
180
+ self.webhooks = _Webhooks(self._http)
181
+ self.companies = _Companies(self._http)
182
+
183
+ def company(self, company_id: str) -> CompanyContext:
184
+ company_id = (company_id or "").strip()
185
+ if not company_id:
186
+ raise EmitfyError("company_id is required.")
187
+ return CompanyContext(self._http, company_id)
188
+
189
+
190
+ class _Webhooks:
191
+ def __init__(self, http: _HttpClient) -> None:
192
+ self._http = http
193
+
194
+ def list(self) -> Any:
195
+ return self._http.request("GET", "/webhooks")
196
+
197
+ def create(self, payload: dict[str, Any]) -> Any:
198
+ return self._http.request("POST", "/webhooks", payload)
199
+
200
+ def update(self, id: str, payload: dict[str, Any]) -> Any:
201
+ return self._http.request("PUT", f"/webhooks/{urllib.parse.quote(id)}", payload)
202
+
203
+ def set_active(self, id: str, active: bool) -> Any:
204
+ return self._http.request(
205
+ "PATCH",
206
+ f"/webhooks/{urllib.parse.quote(id)}/active",
207
+ {"active": active},
208
+ )
209
+
210
+ def delete(self, id: str) -> Any:
211
+ return self._http.request("DELETE", f"/webhooks/{urllib.parse.quote(id)}")
212
+
213
+
214
+ class _Companies:
215
+ def __init__(self, http: _HttpClient) -> None:
216
+ self._http = http
217
+
218
+ def list(self) -> Any:
219
+ return self._http.request("GET", "/companies")
220
+
221
+ def create(self, payload: dict[str, Any]) -> Any:
222
+ return self._http.request("POST", "/companies", payload)
223
+
224
+
225
+ __all__ = ["Emitfy", "EmitfyError", "CompanyContext"]
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: emitfy
3
+ Version: 0.2.2
4
+ Summary: Official Emitfy API SDK for Python
5
+ Author: Emitfy
6
+ License: MIT
7
+ Project-URL: Homepage, https://api.emitfy.com/docs/sdks
8
+ Project-URL: Documentation, https://api.emitfy.com/docs
9
+ Project-URL: Repository, https://github.com/emitfy/emitfy-python
10
+ Keywords: emitfy,nfe,nfse,fiscal,brazil,sdk
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # emitfy (Python)
17
+
18
+ Official Emitfy API SDK for Python.
19
+
20
+ ```bash
21
+ pip install emitfy
22
+ ```
23
+
24
+ ```python
25
+ from emitfy import Emitfy
26
+ import os
27
+
28
+ emitfy = Emitfy(os.environ["EMITFY_API_KEY"], os.environ["EMITFY_API_SECRET"])
29
+ emitfy.webhooks.create({
30
+ "url": "https://seu-sistema.com/webhooks/emitfy",
31
+ "events": {"invoice": ["nfse.authorized"], "cte": []},
32
+ })
33
+ company = emitfy.company(os.environ["EMITFY_COMPANY_ID"])
34
+ company.nfse.create({"serviceDescription": "Serviço", "amount": 100})
35
+ ```
36
+
37
+ Docs: https://api.emitfy.com/docs/sdks
@@ -0,0 +1,8 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ emitfy/__init__.py
5
+ emitfy.egg-info/PKG-INFO
6
+ emitfy.egg-info/SOURCES.txt
7
+ emitfy.egg-info/dependency_links.txt
8
+ emitfy.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ emitfy
@@ -0,0 +1,23 @@
1
+ [project]
2
+ name = "emitfy"
3
+ version = "0.2.2"
4
+ description = "Official Emitfy API SDK for Python"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ license = { text = "MIT" }
8
+ authors = [{ name = "Emitfy" }]
9
+ keywords = ["emitfy", "nfe", "nfse", "fiscal", "brazil", "sdk"]
10
+ dependencies = []
11
+
12
+ [project.urls]
13
+ Homepage = "https://api.emitfy.com/docs/sdks"
14
+ Documentation = "https://api.emitfy.com/docs"
15
+ Repository = "https://github.com/emitfy/emitfy-python"
16
+
17
+ [build-system]
18
+ requires = ["setuptools>=68"]
19
+ build-backend = "setuptools.build_meta"
20
+
21
+ [tool.setuptools.packages.find]
22
+ where = ["."]
23
+ include = ["emitfy*"]
emitfy-0.2.2/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+