stract-api 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.
Files changed (61) hide show
  1. stract_api/__init__.py +141 -0
  2. stract_api/api/__init__.py +16 -0
  3. stract_api/api/account_api.py +1098 -0
  4. stract_api/api/account_credit_ledger_api.py +286 -0
  5. stract_api/api/api_key_api.py +286 -0
  6. stract_api/api/catalog_api.py +837 -0
  7. stract_api/api/credits_api.py +534 -0
  8. stract_api/api/document_api.py +2799 -0
  9. stract_api/api/field_api.py +1168 -0
  10. stract_api/api/job_api.py +2857 -0
  11. stract_api/api/job_document_api.py +575 -0
  12. stract_api/api/llm_model_api.py +286 -0
  13. stract_api/api/struct_api.py +837 -0
  14. stract_api/api/user_api.py +572 -0
  15. stract_api/api_client.py +866 -0
  16. stract_api/api_response.py +21 -0
  17. stract_api/configuration.py +655 -0
  18. stract_api/exceptions.py +219 -0
  19. stract_api/models/__init__.py +52 -0
  20. stract_api/models/account.py +130 -0
  21. stract_api/models/account_credit_cache.py +112 -0
  22. stract_api/models/account_credit_ledger.py +125 -0
  23. stract_api/models/account_user.py +104 -0
  24. stract_api/models/account_user_role.py +38 -0
  25. stract_api/models/api_key.py +102 -0
  26. stract_api/models/catalog.py +100 -0
  27. stract_api/models/create_account_user_request.py +97 -0
  28. stract_api/models/create_catalog_request.py +90 -0
  29. stract_api/models/create_field_request.py +102 -0
  30. stract_api/models/create_job_request.py +109 -0
  31. stract_api/models/create_struct_request.py +90 -0
  32. stract_api/models/deleted_document.py +91 -0
  33. stract_api/models/deleted_field.py +91 -0
  34. stract_api/models/document.py +107 -0
  35. stract_api/models/document_link.py +90 -0
  36. stract_api/models/document_processing_status.py +39 -0
  37. stract_api/models/document_text.py +95 -0
  38. stract_api/models/edit_account_request.py +90 -0
  39. stract_api/models/edit_field_request.py +102 -0
  40. stract_api/models/edit_my_user_request.py +92 -0
  41. stract_api/models/field_type.py +42 -0
  42. stract_api/models/job.py +129 -0
  43. stract_api/models/job_document.py +123 -0
  44. stract_api/models/job_output.py +98 -0
  45. stract_api/models/job_output_record.py +103 -0
  46. stract_api/models/job_status.py +41 -0
  47. stract_api/models/llm_model.py +126 -0
  48. stract_api/models/login_request.py +92 -0
  49. stract_api/models/login_response.py +90 -0
  50. stract_api/models/model_field.py +110 -0
  51. stract_api/models/struct.py +100 -0
  52. stract_api/models/sync_text_job_request.py +118 -0
  53. stract_api/models/upload_text_document_request.py +93 -0
  54. stract_api/models/user.py +102 -0
  55. stract_api/py.typed +0 -0
  56. stract_api/rest.py +335 -0
  57. stract_api-0.1.0.dist-info/METADATA +266 -0
  58. stract_api-0.1.0.dist-info/RECORD +61 -0
  59. stract_api-0.1.0.dist-info/WHEEL +5 -0
  60. stract_api-0.1.0.dist-info/licenses/LICENSE +21 -0
  61. stract_api-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,95 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Stract API
5
+
6
+ Get structured output from unstructured inputs ## Machine authentication Programmatic access to the API is authenticated with an API key. Include the API key in every request as a bearer token in the `authorization` header: ``` authorization: bearer [apiKey] ``` ## SDKs Official SDKs are available for the following languages: - **Node (JavaScript / TypeScript)**: [`stract-api` on npm](https://www.npmjs.com/package/stract-api) - **Java (17+)**: [`com.stract-api:stract-api` on Maven Central](https://central.sonatype.com/artifact/com.stract-api/stract-api)
7
+
8
+ The version of the OpenAPI document: 0.9.4
9
+ Contact: matt@stract-api.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing import Any, ClassVar, Dict, List, Optional
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+ from pydantic_core import to_jsonable_python
26
+ from pydantic import field_validator as _coerce_field_validator
27
+
28
+ class DocumentText(BaseModel):
29
+ """
30
+ DocumentText
31
+ """ # noqa: E501
32
+ text: Optional[StrictStr] = Field(description="Extracted text content of the document")
33
+ __properties: ClassVar[List[str]] = ["text"]
34
+
35
+ model_config = ConfigDict(
36
+ validate_by_name=True,
37
+ validate_by_alias=True,
38
+ validate_assignment=True,
39
+ protected_namespaces=(),
40
+ )
41
+
42
+
43
+ def to_str(self) -> str:
44
+ """Returns the string representation of the model using alias"""
45
+ return pprint.pformat(self.model_dump(by_alias=True))
46
+
47
+ def to_json(self) -> str:
48
+ """Returns the JSON representation of the model using alias"""
49
+ return json.dumps(to_jsonable_python(self.to_dict()))
50
+
51
+ @classmethod
52
+ def from_json(cls, json_str: str) -> Optional[Self]:
53
+ """Create an instance of DocumentText from a JSON string"""
54
+ return cls.from_dict(json.loads(json_str))
55
+
56
+ def to_dict(self) -> Dict[str, Any]:
57
+ """Return the dictionary representation of the model using alias.
58
+
59
+ This has the following differences from calling pydantic's
60
+ `self.model_dump(by_alias=True)`:
61
+
62
+ * `None` is only added to the output dict for nullable fields that
63
+ were set at model initialization. Other fields with value `None`
64
+ are ignored.
65
+ """
66
+ excluded_fields: Set[str] = set([
67
+ ])
68
+
69
+ _dict = self.model_dump(
70
+ by_alias=True,
71
+ exclude=excluded_fields,
72
+ exclude_none=True,
73
+ )
74
+ # set to None if text (nullable) is None
75
+ # and model_fields_set contains the field
76
+ if self.text is None and "text" in self.model_fields_set:
77
+ _dict['text'] = None
78
+
79
+ return _dict
80
+
81
+ @classmethod
82
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
83
+ """Create an instance of DocumentText from a dict"""
84
+ if obj is None:
85
+ return None
86
+
87
+ if not isinstance(obj, dict):
88
+ return cls.model_validate(obj)
89
+
90
+ _obj = cls.model_validate({
91
+ "text": obj.get("text")
92
+ })
93
+ return _obj
94
+
95
+
@@ -0,0 +1,90 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Stract API
5
+
6
+ Get structured output from unstructured inputs ## Machine authentication Programmatic access to the API is authenticated with an API key. Include the API key in every request as a bearer token in the `authorization` header: ``` authorization: bearer [apiKey] ``` ## SDKs Official SDKs are available for the following languages: - **Node (JavaScript / TypeScript)**: [`stract-api` on npm](https://www.npmjs.com/package/stract-api) - **Java (17+)**: [`com.stract-api:stract-api` on Maven Central](https://central.sonatype.com/artifact/com.stract-api/stract-api)
7
+
8
+ The version of the OpenAPI document: 0.9.4
9
+ Contact: matt@stract-api.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing import Any, ClassVar, Dict, List
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+ from pydantic_core import to_jsonable_python
26
+ from pydantic import field_validator as _coerce_field_validator
27
+
28
+ class EditAccountRequest(BaseModel):
29
+ """
30
+ EditAccountRequest
31
+ """ # noqa: E501
32
+ name: StrictStr = Field(description="Name of the account", json_schema_extra={"examples": ["Acme Inc"]})
33
+ __properties: ClassVar[List[str]] = ["name"]
34
+
35
+ model_config = ConfigDict(
36
+ validate_by_name=True,
37
+ validate_by_alias=True,
38
+ validate_assignment=True,
39
+ protected_namespaces=(),
40
+ )
41
+
42
+
43
+ def to_str(self) -> str:
44
+ """Returns the string representation of the model using alias"""
45
+ return pprint.pformat(self.model_dump(by_alias=True))
46
+
47
+ def to_json(self) -> str:
48
+ """Returns the JSON representation of the model using alias"""
49
+ return json.dumps(to_jsonable_python(self.to_dict()))
50
+
51
+ @classmethod
52
+ def from_json(cls, json_str: str) -> Optional[Self]:
53
+ """Create an instance of EditAccountRequest from a JSON string"""
54
+ return cls.from_dict(json.loads(json_str))
55
+
56
+ def to_dict(self) -> Dict[str, Any]:
57
+ """Return the dictionary representation of the model using alias.
58
+
59
+ This has the following differences from calling pydantic's
60
+ `self.model_dump(by_alias=True)`:
61
+
62
+ * `None` is only added to the output dict for nullable fields that
63
+ were set at model initialization. Other fields with value `None`
64
+ are ignored.
65
+ """
66
+ excluded_fields: Set[str] = set([
67
+ ])
68
+
69
+ _dict = self.model_dump(
70
+ by_alias=True,
71
+ exclude=excluded_fields,
72
+ exclude_none=True,
73
+ )
74
+ return _dict
75
+
76
+ @classmethod
77
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
78
+ """Create an instance of EditAccountRequest from a dict"""
79
+ if obj is None:
80
+ return None
81
+
82
+ if not isinstance(obj, dict):
83
+ return cls.model_validate(obj)
84
+
85
+ _obj = cls.model_validate({
86
+ "name": obj.get("name")
87
+ })
88
+ return _obj
89
+
90
+
@@ -0,0 +1,102 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Stract API
5
+
6
+ Get structured output from unstructured inputs ## Machine authentication Programmatic access to the API is authenticated with an API key. Include the API key in every request as a bearer token in the `authorization` header: ``` authorization: bearer [apiKey] ``` ## SDKs Official SDKs are available for the following languages: - **Node (JavaScript / TypeScript)**: [`stract-api` on npm](https://www.npmjs.com/package/stract-api) - **Java (17+)**: [`com.stract-api:stract-api` on Maven Central](https://central.sonatype.com/artifact/com.stract-api/stract-api)
7
+
8
+ The version of the OpenAPI document: 0.9.4
9
+ Contact: matt@stract-api.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing import Any, ClassVar, Dict, List, Optional
23
+ from stract_api.models.field_type import FieldType
24
+ from typing import Optional, Set
25
+ from typing_extensions import Self
26
+ from pydantic_core import to_jsonable_python
27
+ from pydantic import field_validator as _coerce_field_validator
28
+
29
+ class EditFieldRequest(BaseModel):
30
+ """
31
+ EditFieldRequest
32
+ """ # noqa: E501
33
+ name: Optional[StrictStr] = Field(default=None, description="Name of the field", json_schema_extra={"examples": ["email"]})
34
+ description: Optional[StrictStr] = Field(default=None, description="Description of the field", json_schema_extra={"examples": ["Customer's email address"]})
35
+ type: Optional[FieldType] = None
36
+ enum_values: Optional[List[StrictStr]] = Field(default=None, description="Allowed values for the field, required if type is enum")
37
+ __properties: ClassVar[List[str]] = ["name", "description", "type", "enum_values"]
38
+
39
+ model_config = ConfigDict(
40
+ validate_by_name=True,
41
+ validate_by_alias=True,
42
+ validate_assignment=True,
43
+ protected_namespaces=(),
44
+ )
45
+
46
+
47
+ def to_str(self) -> str:
48
+ """Returns the string representation of the model using alias"""
49
+ return pprint.pformat(self.model_dump(by_alias=True))
50
+
51
+ def to_json(self) -> str:
52
+ """Returns the JSON representation of the model using alias"""
53
+ return json.dumps(to_jsonable_python(self.to_dict()))
54
+
55
+ @classmethod
56
+ def from_json(cls, json_str: str) -> Optional[Self]:
57
+ """Create an instance of EditFieldRequest from a JSON string"""
58
+ return cls.from_dict(json.loads(json_str))
59
+
60
+ def to_dict(self) -> Dict[str, Any]:
61
+ """Return the dictionary representation of the model using alias.
62
+
63
+ This has the following differences from calling pydantic's
64
+ `self.model_dump(by_alias=True)`:
65
+
66
+ * `None` is only added to the output dict for nullable fields that
67
+ were set at model initialization. Other fields with value `None`
68
+ are ignored.
69
+ """
70
+ excluded_fields: Set[str] = set([
71
+ ])
72
+
73
+ _dict = self.model_dump(
74
+ by_alias=True,
75
+ exclude=excluded_fields,
76
+ exclude_none=True,
77
+ )
78
+ # set to None if enum_values (nullable) is None
79
+ # and model_fields_set contains the field
80
+ if self.enum_values is None and "enum_values" in self.model_fields_set:
81
+ _dict['enum_values'] = None
82
+
83
+ return _dict
84
+
85
+ @classmethod
86
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
87
+ """Create an instance of EditFieldRequest from a dict"""
88
+ if obj is None:
89
+ return None
90
+
91
+ if not isinstance(obj, dict):
92
+ return cls.model_validate(obj)
93
+
94
+ _obj = cls.model_validate({
95
+ "name": obj.get("name"),
96
+ "description": obj.get("description"),
97
+ "type": obj.get("type"),
98
+ "enum_values": obj.get("enum_values")
99
+ })
100
+ return _obj
101
+
102
+
@@ -0,0 +1,92 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Stract API
5
+
6
+ Get structured output from unstructured inputs ## Machine authentication Programmatic access to the API is authenticated with an API key. Include the API key in every request as a bearer token in the `authorization` header: ``` authorization: bearer [apiKey] ``` ## SDKs Official SDKs are available for the following languages: - **Node (JavaScript / TypeScript)**: [`stract-api` on npm](https://www.npmjs.com/package/stract-api) - **Java (17+)**: [`com.stract-api:stract-api` on Maven Central](https://central.sonatype.com/artifact/com.stract-api/stract-api)
7
+
8
+ The version of the OpenAPI document: 0.9.4
9
+ Contact: matt@stract-api.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing import Any, ClassVar, Dict, List, Optional
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+ from pydantic_core import to_jsonable_python
26
+ from pydantic import field_validator as _coerce_field_validator
27
+
28
+ class EditMyUserRequest(BaseModel):
29
+ """
30
+ EditMyUserRequest
31
+ """ # noqa: E501
32
+ first_name: Optional[StrictStr] = Field(default=None, description="User's first name")
33
+ last_name: Optional[StrictStr] = Field(default=None, description="User's last name")
34
+ __properties: ClassVar[List[str]] = ["first_name", "last_name"]
35
+
36
+ model_config = ConfigDict(
37
+ validate_by_name=True,
38
+ validate_by_alias=True,
39
+ validate_assignment=True,
40
+ protected_namespaces=(),
41
+ )
42
+
43
+
44
+ def to_str(self) -> str:
45
+ """Returns the string representation of the model using alias"""
46
+ return pprint.pformat(self.model_dump(by_alias=True))
47
+
48
+ def to_json(self) -> str:
49
+ """Returns the JSON representation of the model using alias"""
50
+ return json.dumps(to_jsonable_python(self.to_dict()))
51
+
52
+ @classmethod
53
+ def from_json(cls, json_str: str) -> Optional[Self]:
54
+ """Create an instance of EditMyUserRequest from a JSON string"""
55
+ return cls.from_dict(json.loads(json_str))
56
+
57
+ def to_dict(self) -> Dict[str, Any]:
58
+ """Return the dictionary representation of the model using alias.
59
+
60
+ This has the following differences from calling pydantic's
61
+ `self.model_dump(by_alias=True)`:
62
+
63
+ * `None` is only added to the output dict for nullable fields that
64
+ were set at model initialization. Other fields with value `None`
65
+ are ignored.
66
+ """
67
+ excluded_fields: Set[str] = set([
68
+ ])
69
+
70
+ _dict = self.model_dump(
71
+ by_alias=True,
72
+ exclude=excluded_fields,
73
+ exclude_none=True,
74
+ )
75
+ return _dict
76
+
77
+ @classmethod
78
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
79
+ """Create an instance of EditMyUserRequest from a dict"""
80
+ if obj is None:
81
+ return None
82
+
83
+ if not isinstance(obj, dict):
84
+ return cls.model_validate(obj)
85
+
86
+ _obj = cls.model_validate({
87
+ "first_name": obj.get("first_name"),
88
+ "last_name": obj.get("last_name")
89
+ })
90
+ return _obj
91
+
92
+
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Stract API
5
+
6
+ Get structured output from unstructured inputs ## Machine authentication Programmatic access to the API is authenticated with an API key. Include the API key in every request as a bearer token in the `authorization` header: ``` authorization: bearer [apiKey] ``` ## SDKs Official SDKs are available for the following languages: - **Node (JavaScript / TypeScript)**: [`stract-api` on npm](https://www.npmjs.com/package/stract-api) - **Java (17+)**: [`com.stract-api:stract-api` on Maven Central](https://central.sonatype.com/artifact/com.stract-api/stract-api)
7
+
8
+ The version of the OpenAPI document: 0.9.4
9
+ Contact: matt@stract-api.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import json
18
+ from enum import Enum
19
+ from typing_extensions import Self
20
+
21
+
22
+ class FieldType(str, Enum):
23
+ """
24
+ The data type of the field
25
+ """
26
+
27
+ """
28
+ allowed enum values
29
+ """
30
+ STRING = 'string'
31
+ BOOLEAN = 'boolean'
32
+ NUMBER = 'number'
33
+ DATE = 'date'
34
+ DATETIME = 'datetime'
35
+ ENUM = 'enum'
36
+
37
+ @classmethod
38
+ def from_json(cls, json_str: str) -> Self:
39
+ """Create an instance of FieldType from a JSON string"""
40
+ return cls(json.loads(json_str))
41
+
42
+
@@ -0,0 +1,129 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Stract API
5
+
6
+ Get structured output from unstructured inputs ## Machine authentication Programmatic access to the API is authenticated with an API key. Include the API key in every request as a bearer token in the `authorization` header: ``` authorization: bearer [apiKey] ``` ## SDKs Official SDKs are available for the following languages: - **Node (JavaScript / TypeScript)**: [`stract-api` on npm](https://www.npmjs.com/package/stract-api) - **Java (17+)**: [`com.stract-api:stract-api` on Maven Central](https://central.sonatype.com/artifact/com.stract-api/stract-api)
7
+
8
+ The version of the OpenAPI document: 0.9.4
9
+ Contact: matt@stract-api.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from datetime import datetime
22
+ from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
23
+ from typing import Any, ClassVar, Dict, List, Optional, Union
24
+ from uuid import UUID
25
+ from stract_api.models.job_status import JobStatus
26
+ from typing import Optional, Set
27
+ from typing_extensions import Self
28
+ from pydantic_core import to_jsonable_python
29
+ from pydantic import field_validator as _coerce_field_validator
30
+
31
+ class Job(BaseModel):
32
+ """
33
+ Job
34
+ """ # noqa: E501
35
+ id: UUID = Field(description="Unique identifier of the job")
36
+ status: JobStatus
37
+ struct_id: UUID = Field(description="ID of the struct this job belongs to")
38
+ struct_name: StrictStr = Field(description="Name of the struct this job belongs to")
39
+ is_complete: StrictBool = Field(description="Whether the job has completed")
40
+ dt_created: datetime = Field(description="Timestamp when the job was created")
41
+ dt_completed: Optional[datetime] = Field(default=None, description="Timestamp when the job completed")
42
+ catalog_id: Optional[UUID] = Field(default=None, description="ID of the catalog this job was run against, if applicable")
43
+ catalog_name: Optional[StrictStr] = Field(default=None, description="Name of the catalog this job was run against, if applicable")
44
+ document_ids: Optional[List[UUID]] = Field(default=None, description="IDs of the documents this job was run against, if applicable")
45
+ notes: Optional[StrictStr] = Field(default=None, description="Notes about the job, e.g. an error message if the job failed")
46
+ credits_used: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Number of credits consumed by this job")
47
+ instructions: Optional[StrictStr] = Field(default=None, description="Additional instructions provided to guide the data extraction")
48
+ llm_model_id: Optional[StrictStr] = Field(default=None, description="ID of the LLM model used for this job", json_schema_extra={"examples": ["google.gemma-3-27b-it"]})
49
+ __properties: ClassVar[List[str]] = ["id", "status", "struct_id", "struct_name", "is_complete", "dt_created", "dt_completed", "catalog_id", "catalog_name", "document_ids", "notes", "credits_used", "instructions", "llm_model_id"]
50
+
51
+ @_coerce_field_validator('credits_used', mode="before")
52
+ def credits_used_coerce_numeric_string(cls, value):
53
+ """The API sends numbers as strings (e.g. '29532'); convert them before strict validation"""
54
+ if isinstance(value, str):
55
+ try:
56
+ return int(value)
57
+ except ValueError:
58
+ return float(value)
59
+ return value
60
+
61
+ model_config = ConfigDict(
62
+ validate_by_name=True,
63
+ validate_by_alias=True,
64
+ validate_assignment=True,
65
+ protected_namespaces=(),
66
+ )
67
+
68
+
69
+ def to_str(self) -> str:
70
+ """Returns the string representation of the model using alias"""
71
+ return pprint.pformat(self.model_dump(by_alias=True))
72
+
73
+ def to_json(self) -> str:
74
+ """Returns the JSON representation of the model using alias"""
75
+ return json.dumps(to_jsonable_python(self.to_dict()))
76
+
77
+ @classmethod
78
+ def from_json(cls, json_str: str) -> Optional[Self]:
79
+ """Create an instance of Job from a JSON string"""
80
+ return cls.from_dict(json.loads(json_str))
81
+
82
+ def to_dict(self) -> Dict[str, Any]:
83
+ """Return the dictionary representation of the model using alias.
84
+
85
+ This has the following differences from calling pydantic's
86
+ `self.model_dump(by_alias=True)`:
87
+
88
+ * `None` is only added to the output dict for nullable fields that
89
+ were set at model initialization. Other fields with value `None`
90
+ are ignored.
91
+ """
92
+ excluded_fields: Set[str] = set([
93
+ ])
94
+
95
+ _dict = self.model_dump(
96
+ by_alias=True,
97
+ exclude=excluded_fields,
98
+ exclude_none=True,
99
+ )
100
+ return _dict
101
+
102
+ @classmethod
103
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
104
+ """Create an instance of Job from a dict"""
105
+ if obj is None:
106
+ return None
107
+
108
+ if not isinstance(obj, dict):
109
+ return cls.model_validate(obj)
110
+
111
+ _obj = cls.model_validate({
112
+ "id": obj.get("id"),
113
+ "status": obj.get("status"),
114
+ "struct_id": obj.get("struct_id"),
115
+ "struct_name": obj.get("struct_name"),
116
+ "is_complete": obj.get("is_complete"),
117
+ "dt_created": obj.get("dt_created"),
118
+ "dt_completed": obj.get("dt_completed"),
119
+ "catalog_id": obj.get("catalog_id"),
120
+ "catalog_name": obj.get("catalog_name"),
121
+ "document_ids": obj.get("document_ids"),
122
+ "notes": obj.get("notes"),
123
+ "credits_used": obj.get("credits_used"),
124
+ "instructions": obj.get("instructions"),
125
+ "llm_model_id": obj.get("llm_model_id")
126
+ })
127
+ return _obj
128
+
129
+
@@ -0,0 +1,123 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Stract API
5
+
6
+ Get structured output from unstructured inputs ## Machine authentication Programmatic access to the API is authenticated with an API key. Include the API key in every request as a bearer token in the `authorization` header: ``` authorization: bearer [apiKey] ``` ## SDKs Official SDKs are available for the following languages: - **Node (JavaScript / TypeScript)**: [`stract-api` on npm](https://www.npmjs.com/package/stract-api) - **Java (17+)**: [`com.stract-api:stract-api` on Maven Central](https://central.sonatype.com/artifact/com.stract-api/stract-api)
7
+
8
+ The version of the OpenAPI document: 0.9.4
9
+ Contact: matt@stract-api.com
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ from __future__ import annotations
17
+ import pprint
18
+ import re # noqa: F401
19
+ import json
20
+
21
+ from datetime import datetime
22
+ from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
23
+ from typing import Any, ClassVar, Dict, List, Optional, Union
24
+ from uuid import UUID
25
+ from stract_api.models.job_status import JobStatus
26
+ from typing import Optional, Set
27
+ from typing_extensions import Self
28
+ from pydantic_core import to_jsonable_python
29
+ from pydantic import field_validator as _coerce_field_validator
30
+
31
+ class JobDocument(BaseModel):
32
+ """
33
+ JobDocument
34
+ """ # noqa: E501
35
+ id: UUID = Field(description="Unique identifier of the job document")
36
+ job_id: UUID = Field(description="ID of the job this record belongs to")
37
+ document_id: UUID = Field(description="ID of the document this record belongs to")
38
+ document_name: StrictStr = Field(description="Name of the document this record belongs to")
39
+ notes: Optional[StrictStr] = Field(default=None, description="Notes about the job document, e.g. an error message if processing failed")
40
+ status: JobStatus
41
+ is_complete: StrictBool = Field(description="Whether processing of this document has completed")
42
+ error_description: Optional[StrictStr] = Field(default=None, description="Description of the error, if processing this document failed")
43
+ credits_used: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Number of credits consumed processing this document")
44
+ dt_started: Optional[datetime] = Field(default=None, description="Timestamp when processing of this document started")
45
+ dt_completed: Optional[datetime] = Field(default=None, description="Timestamp when processing of this document completed")
46
+ __properties: ClassVar[List[str]] = ["id", "job_id", "document_id", "document_name", "notes", "status", "is_complete", "error_description", "credits_used", "dt_started", "dt_completed"]
47
+
48
+ @_coerce_field_validator('credits_used', mode="before")
49
+ def credits_used_coerce_numeric_string(cls, value):
50
+ """The API sends numbers as strings (e.g. '29532'); convert them before strict validation"""
51
+ if isinstance(value, str):
52
+ try:
53
+ return int(value)
54
+ except ValueError:
55
+ return float(value)
56
+ return value
57
+
58
+ model_config = ConfigDict(
59
+ validate_by_name=True,
60
+ validate_by_alias=True,
61
+ validate_assignment=True,
62
+ protected_namespaces=(),
63
+ )
64
+
65
+
66
+ def to_str(self) -> str:
67
+ """Returns the string representation of the model using alias"""
68
+ return pprint.pformat(self.model_dump(by_alias=True))
69
+
70
+ def to_json(self) -> str:
71
+ """Returns the JSON representation of the model using alias"""
72
+ return json.dumps(to_jsonable_python(self.to_dict()))
73
+
74
+ @classmethod
75
+ def from_json(cls, json_str: str) -> Optional[Self]:
76
+ """Create an instance of JobDocument from a JSON string"""
77
+ return cls.from_dict(json.loads(json_str))
78
+
79
+ def to_dict(self) -> Dict[str, Any]:
80
+ """Return the dictionary representation of the model using alias.
81
+
82
+ This has the following differences from calling pydantic's
83
+ `self.model_dump(by_alias=True)`:
84
+
85
+ * `None` is only added to the output dict for nullable fields that
86
+ were set at model initialization. Other fields with value `None`
87
+ are ignored.
88
+ """
89
+ excluded_fields: Set[str] = set([
90
+ ])
91
+
92
+ _dict = self.model_dump(
93
+ by_alias=True,
94
+ exclude=excluded_fields,
95
+ exclude_none=True,
96
+ )
97
+ return _dict
98
+
99
+ @classmethod
100
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
101
+ """Create an instance of JobDocument from a dict"""
102
+ if obj is None:
103
+ return None
104
+
105
+ if not isinstance(obj, dict):
106
+ return cls.model_validate(obj)
107
+
108
+ _obj = cls.model_validate({
109
+ "id": obj.get("id"),
110
+ "job_id": obj.get("job_id"),
111
+ "document_id": obj.get("document_id"),
112
+ "document_name": obj.get("document_name"),
113
+ "notes": obj.get("notes"),
114
+ "status": obj.get("status"),
115
+ "is_complete": obj.get("is_complete"),
116
+ "error_description": obj.get("error_description"),
117
+ "credits_used": obj.get("credits_used"),
118
+ "dt_started": obj.get("dt_started"),
119
+ "dt_completed": obj.get("dt_completed")
120
+ })
121
+ return _obj
122
+
123
+