flaxflow 1.0.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.
flaxflow/__init__.py ADDED
@@ -0,0 +1,43 @@
1
+ """SDK oficial em Python para a FlaxFlow Engine API (processamento de documentos com IA).
2
+
3
+ Quickstart:
4
+ >>> from flaxflow import FlaxFlow
5
+ >>> fx = FlaxFlow(api_key="sk_...")
6
+ >>> job = fx.processing.process_document("invoice.pdf", document_id="<doc_id>")
7
+ >>> print(job.result)
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from ._files import SUPPORTED_DOCUMENT_TYPES
13
+ from .client import FlaxFlow
14
+ from .errors import (
15
+ APIConnectionError,
16
+ APIStatusError,
17
+ AuthenticationError,
18
+ ConflictError,
19
+ FlaxFlowError,
20
+ NotFoundError,
21
+ PermissionDeniedError,
22
+ RateLimitError,
23
+ ServerError,
24
+ UnprocessableEntityError,
25
+ )
26
+
27
+ __version__ = "0.1.0"
28
+
29
+ __all__ = [
30
+ "FlaxFlow",
31
+ "FlaxFlowError",
32
+ "APIConnectionError",
33
+ "APIStatusError",
34
+ "AuthenticationError",
35
+ "PermissionDeniedError",
36
+ "NotFoundError",
37
+ "ConflictError",
38
+ "UnprocessableEntityError",
39
+ "RateLimitError",
40
+ "ServerError",
41
+ "SUPPORTED_DOCUMENT_TYPES",
42
+ "__version__",
43
+ ]
flaxflow/_files.py ADDED
@@ -0,0 +1,78 @@
1
+ """Helpers para transformar arquivos em payloads base64 que a Engine API espera."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ import os
7
+ from pathlib import Path
8
+ from typing import IO, Union
9
+
10
+ # Mapeia extensões de arquivo para o `documentType` aceito pela API.
11
+ _EXT_TO_DOCUMENT_TYPE = {
12
+ ".pdf": "pdf",
13
+ ".png": "png",
14
+ ".jpg": "jpeg",
15
+ ".jpeg": "jpeg",
16
+ ".webp": "webp",
17
+ ".gif": "gif",
18
+ }
19
+
20
+ #: Tipos de arquivo aceitos pela Engine API.
21
+ SUPPORTED_DOCUMENT_TYPES = ("pdf", "png", "jpeg", "webp", "gif")
22
+
23
+ FileInput = Union[str, "os.PathLike[str]", bytes, IO[bytes]]
24
+
25
+
26
+ def detect_document_type(path: Union[str, "os.PathLike[str]"]) -> str:
27
+ """Infere o `documentType` a partir da extensão do caminho.
28
+
29
+ Raises:
30
+ ValueError: se a extensão não for suportada.
31
+ """
32
+ ext = Path(os.fspath(path)).suffix.lower()
33
+ try:
34
+ return _EXT_TO_DOCUMENT_TYPE[ext]
35
+ except KeyError as exc:
36
+ raise ValueError(
37
+ f"Could not infer documentType from extension {ext!r}. "
38
+ f"Pass document_type explicitly (one of {SUPPORTED_DOCUMENT_TYPES})."
39
+ ) from exc
40
+
41
+
42
+ def _read_bytes(file: FileInput) -> bytes:
43
+ if isinstance(file, bytes):
44
+ return file
45
+ if hasattr(file, "read"):
46
+ return file.read() # type: ignore[union-attr]
47
+ with open(os.fspath(file), "rb") as fh: # type: ignore[arg-type]
48
+ return fh.read()
49
+
50
+
51
+ def resolve_file(
52
+ file: FileInput,
53
+ document_type: str | None = None,
54
+ ) -> tuple[str, str]:
55
+ """Resolve uma entrada de arquivo para ``(base64_document, document_type)``.
56
+
57
+ ``file`` pode ser um caminho, ``bytes`` ou um objeto file-like. Quando
58
+ ``document_type`` não é informado, tenta inferir pela extensão (só funciona
59
+ para caminhos).
60
+ """
61
+ resolved_type = document_type
62
+ if resolved_type is None:
63
+ if isinstance(file, (str, os.PathLike)):
64
+ resolved_type = detect_document_type(file)
65
+ else:
66
+ raise ValueError(
67
+ "document_type is required when file is not a path "
68
+ f"(one of {SUPPORTED_DOCUMENT_TYPES})."
69
+ )
70
+
71
+ if resolved_type not in SUPPORTED_DOCUMENT_TYPES:
72
+ raise ValueError(
73
+ f"Unsupported document_type {resolved_type!r}; "
74
+ f"expected one of {SUPPORTED_DOCUMENT_TYPES}."
75
+ )
76
+
77
+ encoded = base64.b64encode(_read_bytes(file)).decode("ascii")
78
+ return encoded, resolved_type
@@ -0,0 +1,5 @@
1
+ """Modelos gerados a partir da spec OpenAPI (`scripts/generate.sh`). Não editar à mão."""
2
+
3
+ from . import models
4
+
5
+ __all__ = ["models"]