stackin-python-sdk 0.3.0__py3-none-any.whl → 0.3.1__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.
- stackin/__init__.py +3 -2
- stackin/br/product.py +4 -1
- stackin/core/client.py +58 -3
- stackin/core/exceptions.py +1 -1
- stackin/core/types.py +10 -1
- {stackin_python_sdk-0.3.0.dist-info → stackin_python_sdk-0.3.1.dist-info}/METADATA +36 -2
- stackin_python_sdk-0.3.1.dist-info/RECORD +13 -0
- stackin_python_sdk-0.3.0.dist-info/RECORD +0 -13
- {stackin_python_sdk-0.3.0.dist-info → stackin_python_sdk-0.3.1.dist-info}/WHEEL +0 -0
- {stackin_python_sdk-0.3.0.dist-info → stackin_python_sdk-0.3.1.dist-info}/licenses/LICENSE +0 -0
stackin/__init__.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Invoice __init__ module."""
|
|
2
2
|
|
|
3
|
-
__version__ = "0.3.
|
|
3
|
+
__version__ = "0.3.1"
|
|
4
4
|
__description__ = (
|
|
5
5
|
"Python SDK for issuing, consulting and cancelling electronic invoices."
|
|
6
6
|
)
|
|
@@ -8,12 +8,13 @@ __description__ = (
|
|
|
8
8
|
from .core.address import Address
|
|
9
9
|
from .core.client import Invoice
|
|
10
10
|
from .core.exceptions import APIError, ConnectionFailedError, InvoiceError
|
|
11
|
-
from .core.types import DocumentType, Environment
|
|
11
|
+
from .core.types import DocumentType, Environment, Manifestation
|
|
12
12
|
|
|
13
13
|
__all__ = [
|
|
14
14
|
"Invoice",
|
|
15
15
|
"DocumentType",
|
|
16
16
|
"Environment",
|
|
17
|
+
"Manifestation",
|
|
17
18
|
"Address",
|
|
18
19
|
"InvoiceError",
|
|
19
20
|
"APIError",
|
stackin/br/product.py
CHANGED
|
@@ -67,7 +67,10 @@ class Product(BaseModel):
|
|
|
67
67
|
ex_tipi: str | None = Field(default=None, pattern=r"^\d{2,3}$")
|
|
68
68
|
import_content_control_number: str | None = Field(
|
|
69
69
|
default=None,
|
|
70
|
-
pattern=
|
|
70
|
+
pattern=(
|
|
71
|
+
r"^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}"
|
|
72
|
+
r"-[A-F0-9]{4}-[A-F0-9]{12}$"
|
|
73
|
+
),
|
|
71
74
|
)
|
|
72
75
|
recopi_number: str | None = Field(default=None, pattern=r"^\d{20}$")
|
|
73
76
|
extra_groups: dict[str, Any] | None = Field(default=None)
|
stackin/core/client.py
CHANGED
|
@@ -9,7 +9,7 @@ import requests
|
|
|
9
9
|
from stackin.br.product import Product
|
|
10
10
|
from stackin.core.address import Address
|
|
11
11
|
from stackin.core.exceptions import APIError, ConnectionFailedError
|
|
12
|
-
from stackin.core.types import DocumentType, Environment
|
|
12
|
+
from stackin.core.types import DocumentType, Environment, Manifestation
|
|
13
13
|
|
|
14
14
|
DEFAULT_BASE_URL = "https://sdk.stackin.io"
|
|
15
15
|
|
|
@@ -23,7 +23,7 @@ _ENVIRONMENT_URLS = {
|
|
|
23
23
|
def _resolve_base_url(
|
|
24
24
|
base_url: str | None, environment: Environment | str | None
|
|
25
25
|
) -> str:
|
|
26
|
-
"""
|
|
26
|
+
"""Explicit param, then env var, then the environment's default."""
|
|
27
27
|
if base_url:
|
|
28
28
|
return base_url
|
|
29
29
|
if url := os.environ.get("STACKIN_BASE_URL"):
|
|
@@ -48,7 +48,7 @@ _NFE_ADDRESS_FIELDS = (
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
def _validate_nfe_address(address: Address | None) -> None:
|
|
51
|
-
"""NFE needs the
|
|
51
|
+
"""NFE needs the full address — a partial one the SEFAZ rejects."""
|
|
52
52
|
if address is None:
|
|
53
53
|
raise ValueError("recipient_address is required for NFE")
|
|
54
54
|
|
|
@@ -224,6 +224,61 @@ class Invoice:
|
|
|
224
224
|
)
|
|
225
225
|
return response.content
|
|
226
226
|
|
|
227
|
+
def received(
|
|
228
|
+
self,
|
|
229
|
+
*,
|
|
230
|
+
limit: int | None = None,
|
|
231
|
+
offset: int | None = None,
|
|
232
|
+
) -> dict:
|
|
233
|
+
"""Documents other companies issued against this one.
|
|
234
|
+
|
|
235
|
+
Reads what the API already collected; it does not call the
|
|
236
|
+
authorizer. Collecting runs on a schedule there, because the
|
|
237
|
+
SEFAZ caps how many times a CNPJ may ask per day.
|
|
238
|
+
"""
|
|
239
|
+
params = {}
|
|
240
|
+
if limit is not None:
|
|
241
|
+
params["limit"] = limit
|
|
242
|
+
if offset is not None:
|
|
243
|
+
params["offset"] = offset
|
|
244
|
+
|
|
245
|
+
return self._request("GET", "/received-invoices", params=params)
|
|
246
|
+
|
|
247
|
+
def manifest(
|
|
248
|
+
self,
|
|
249
|
+
access_key: str,
|
|
250
|
+
*,
|
|
251
|
+
manifestation: Manifestation,
|
|
252
|
+
reason: str | None = None,
|
|
253
|
+
) -> dict:
|
|
254
|
+
"""The recipient's formal answer to a received document.
|
|
255
|
+
|
|
256
|
+
Only `OPERACAO_NAO_REALIZADA` takes a reason, and it requires
|
|
257
|
+
one. Both are fixed rules, so they are checked here rather than
|
|
258
|
+
spending a round trip to be told.
|
|
259
|
+
"""
|
|
260
|
+
needs_reason = manifestation is Manifestation.OPERACAO_NAO_REALIZADA
|
|
261
|
+
if needs_reason and not reason:
|
|
262
|
+
raise ValueError(
|
|
263
|
+
"manifestation 210240 (operação não realizada) requires "
|
|
264
|
+
"a reason"
|
|
265
|
+
)
|
|
266
|
+
if not needs_reason and reason:
|
|
267
|
+
raise ValueError(
|
|
268
|
+
f"manifestation {manifestation.value} does not take a "
|
|
269
|
+
"reason"
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
payload = {"manifestation": manifestation.value}
|
|
273
|
+
if reason:
|
|
274
|
+
payload["reason"] = reason
|
|
275
|
+
|
|
276
|
+
return self._request(
|
|
277
|
+
"POST",
|
|
278
|
+
f"/received-invoices/{access_key}/manifestation",
|
|
279
|
+
json=payload,
|
|
280
|
+
)
|
|
281
|
+
|
|
227
282
|
def _headers(self, idempotency_key: str | None = None) -> dict:
|
|
228
283
|
headers = {}
|
|
229
284
|
if self.api_key:
|
stackin/core/exceptions.py
CHANGED
stackin/core/types.py
CHANGED
|
@@ -13,8 +13,17 @@ class DocumentType(str, Enum):
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class Environment(str, Enum):
|
|
16
|
-
"""Which host to talk to
|
|
16
|
+
"""Which host to talk to, instead of a raw `base_url`."""
|
|
17
17
|
|
|
18
18
|
LOCAL = "local"
|
|
19
19
|
TEST = "test"
|
|
20
20
|
PRODUCTION = "production"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Manifestation(str, Enum):
|
|
24
|
+
"""The recipient's four possible answers to a received document."""
|
|
25
|
+
|
|
26
|
+
CONFIRMACAO = "210200"
|
|
27
|
+
CIENCIA = "210210"
|
|
28
|
+
DESCONHECIMENTO = "210220"
|
|
29
|
+
OPERACAO_NAO_REALIZADA = "210240"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stackin-python-sdk
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Python SDK for issuing, consulting and cancelling electronic invoices.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -47,7 +47,7 @@ Description-Content-Type: text/markdown
|
|
|
47
47
|
|
|
48
48
|
Python SDK for fiscal document issuance — a handful of business fields, nothing about certificates, XML, XSD, signing or SOAP. The API resolves all of that from the issuer's own configuration, identified by `api_key`.
|
|
49
49
|
|
|
50
|
-
**One class, `Invoice`** — `issue()`/`consult()`/`cancel()`/`reissue()`/`correct()`/`invalidate()`/`pdf()`, nothing else to instantiate. Each line item is a `Product` (`stackin.br`) — `description`/`amount` are universal, everything else (`ncm`/`cfop`/`cest`/tax groups...) is Brazil-specific and only required for NFE; NFSE ignores it.
|
|
50
|
+
**One class, `Invoice`** — `issue()`/`consult()`/`cancel()`/`reissue()`/`correct()`/`invalidate()`/`pdf()`/`received()`/`manifest()`, nothing else to instantiate. Each line item is a `Product` (`stackin.br`) — `description`/`amount` are universal, everything else (`ncm`/`cfop`/`cest`/tax groups...) is Brazil-specific and only required for NFE; NFSE ignores it.
|
|
51
51
|
|
|
52
52
|
## Install
|
|
53
53
|
|
|
@@ -200,6 +200,40 @@ round trip — and the authorizer checks again for what we can't see from here.
|
|
|
200
200
|
|
|
201
201
|
**NF-e only**, and it takes no access key: there is no document to point at.
|
|
202
202
|
|
|
203
|
+
## Documents issued against you
|
|
204
|
+
|
|
205
|
+
Everything above serves the **issuer**. These two serve the **recipient**: what
|
|
206
|
+
suppliers billed to this CNPJ, and the formal answer to it.
|
|
207
|
+
|
|
208
|
+
Reading the list never calls the SEFAZ. The authorizer caps how many times a CNPJ
|
|
209
|
+
may ask for its distribution per day, so collecting runs on a schedule on the API
|
|
210
|
+
side and a page refresh cannot spend that allowance.
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from stackin import Manifestation
|
|
214
|
+
|
|
215
|
+
page = client.received(limit=20)
|
|
216
|
+
for document in page["data"]:
|
|
217
|
+
print(document["access_key"], document["issuer_name"], document["amount"])
|
|
218
|
+
|
|
219
|
+
client.manifest(access_key, manifestation=Manifestation.CIENCIA)
|
|
220
|
+
client.manifest(
|
|
221
|
+
access_key,
|
|
222
|
+
manifestation=Manifestation.OPERACAO_NAO_REALIZADA,
|
|
223
|
+
reason="Mercadoria nunca chegou ao endereco",
|
|
224
|
+
)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Before you answer a document the SEFAZ sends only a **summary** (`resNFe`): access
|
|
228
|
+
key, issuer, amount, date. The **full document** (`nfeProc`) arrives after a
|
|
229
|
+
manifestation, and the `schema` field on each row says which one you hold.
|
|
230
|
+
|
|
231
|
+
The four answers are `210200` Confirmação da Operação, `210210` Ciência da
|
|
232
|
+
Operação, `210220` Desconhecimento da Operação and `210240` Operação não
|
|
233
|
+
Realizada. Only the last one takes a reason, and it requires one — both rules are
|
|
234
|
+
checked locally, before the request goes out, because a round trip to be told a
|
|
235
|
+
fixed rule is a round trip wasted.
|
|
236
|
+
|
|
203
237
|
## Errors
|
|
204
238
|
|
|
205
239
|
- `stackin.APIError` — the API responded with a non-2xx status (`status_code`, `detail`) — a 401 here means `api_key` is missing, wrong, or was rotated.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
stackin/__init__.py,sha256=Ga5d3L7QT2WwhVNA1_PAC_NIBpaF6h-hyZtO7lqkkbM,531
|
|
2
|
+
stackin/br/__init__.py,sha256=Nw5VyeoFFJPqweZI60uADtBrxilXqkpzpkYtR5WZ630,656
|
|
3
|
+
stackin/br/product.py,sha256=877FGYgVZ8iBIJFecsDRbbnEiKmbMY5WBuVtHoEoia4,4044
|
|
4
|
+
stackin/br/tax.py,sha256=PdUkg5JdNKy7AHlt5ZpM9svvilZA93FPMr2QNi0SRlw,7716
|
|
5
|
+
stackin/core/__init__.py,sha256=dxtOP1DopMSNFYGh3Hf12RVcs58R9xwLn-gqfKFo-HE,19
|
|
6
|
+
stackin/core/address.py,sha256=-w5R3nzfU5T3VoxIeygu5Dq4DRb_lJHAGc0lmSMwEMU,616
|
|
7
|
+
stackin/core/client.py,sha256=GqWWxDdOeiSfLMJ2iqm_-xWA6zvwUM-387bSqR5eA2Y,10232
|
|
8
|
+
stackin/core/exceptions.py,sha256=ELn-uL8rwjAFsD1PgM8Zr-1if3Z5yOWU81chUs4k6tU,505
|
|
9
|
+
stackin/core/types.py,sha256=NpfYVN58Ug9fEY7VYeQ2TC1eekoFGHZq_habvrqEeTY,604
|
|
10
|
+
stackin_python_sdk-0.3.1.dist-info/METADATA,sha256=zgjUSIk67gBeZj_YY70TUhgxcaBnlBgVN6HKXsKLlKg,11041
|
|
11
|
+
stackin_python_sdk-0.3.1.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
|
|
12
|
+
stackin_python_sdk-0.3.1.dist-info/licenses/LICENSE,sha256=D-XHDcKFFhzEo9C5Dp4QPvt00pb_u__hi4Bc08zpxyU,1072
|
|
13
|
+
stackin_python_sdk-0.3.1.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
stackin/__init__.py,sha256=rsEjE3iiFCRB4EySvHJiK8B-OTrtB35teC6LHX9uo-Y,495
|
|
2
|
-
stackin/br/__init__.py,sha256=Nw5VyeoFFJPqweZI60uADtBrxilXqkpzpkYtR5WZ630,656
|
|
3
|
-
stackin/br/product.py,sha256=nuHQkWMz0eRmWYWPoduwmAfibBQvrcajEMxerwHGa9E,4004
|
|
4
|
-
stackin/br/tax.py,sha256=PdUkg5JdNKy7AHlt5ZpM9svvilZA93FPMr2QNi0SRlw,7716
|
|
5
|
-
stackin/core/__init__.py,sha256=dxtOP1DopMSNFYGh3Hf12RVcs58R9xwLn-gqfKFo-HE,19
|
|
6
|
-
stackin/core/address.py,sha256=-w5R3nzfU5T3VoxIeygu5Dq4DRb_lJHAGc0lmSMwEMU,616
|
|
7
|
-
stackin/core/client.py,sha256=u8Q14sF844Pd0oMWy8AA0F4ry78p_s17mYprE2E8NNY,8486
|
|
8
|
-
stackin/core/exceptions.py,sha256=enl8GS_WlDV6PyH1M_KTxzLG9Qdr-9MJrMXB_AlCtYg,521
|
|
9
|
-
stackin/core/types.py,sha256=SYpLS2EnqKcudm7wFwCTOVAQe1IYT5T0TGSD0E6z8bo,416
|
|
10
|
-
stackin_python_sdk-0.3.0.dist-info/METADATA,sha256=pvDErFOVR0AphHcoXLuIU-cYwsHSgWvgEZLwwbctohI,9628
|
|
11
|
-
stackin_python_sdk-0.3.0.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
|
|
12
|
-
stackin_python_sdk-0.3.0.dist-info/licenses/LICENSE,sha256=D-XHDcKFFhzEo9C5Dp4QPvt00pb_u__hi4Bc08zpxyU,1072
|
|
13
|
-
stackin_python_sdk-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|