viclix-vault 0.1.0__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.
Files changed (39) hide show
  1. viclix_vault-0.1.0/PKG-INFO +141 -0
  2. viclix_vault-0.1.0/README.md +124 -0
  3. viclix_vault-0.1.0/pyproject.toml +26 -0
  4. viclix_vault-0.1.0/viclix_vault/__init__.py +8 -0
  5. viclix_vault-0.1.0/viclix_vault/client.py +284 -0
  6. viclix_vault-0.1.0/viclix_vault/d3c/__init__.py +1 -0
  7. viclix_vault-0.1.0/viclix_vault/d3c/decrypt_file_api_v1_decrypt_post.py +193 -0
  8. viclix_vault-0.1.0/viclix_vault/d3c/encrypt_file_api_v1_encrypt_post.py +193 -0
  9. viclix_vault-0.1.0/viclix_vault/errors.py +16 -0
  10. viclix_vault-0.1.0/viclix_vault/models/__init__.py +39 -0
  11. viclix_vault-0.1.0/viclix_vault/models/analysis_data_schema.py +147 -0
  12. viclix_vault-0.1.0/viclix_vault/models/analysis_data_schema_graph_edges_item.py +47 -0
  13. viclix_vault-0.1.0/viclix_vault/models/analysis_request.py +61 -0
  14. viclix_vault-0.1.0/viclix_vault/models/analysis_response.py +177 -0
  15. viclix_vault-0.1.0/viclix_vault/models/ascii_request.py +99 -0
  16. viclix_vault-0.1.0/viclix_vault/models/body_decrypt_file_api_v1_decrypt_post.py +85 -0
  17. viclix_vault-0.1.0/viclix_vault/models/body_encrypt_file_api_v1_encrypt_post.py +85 -0
  18. viclix_vault-0.1.0/viclix_vault/models/body_process_analysis_analyze_post.py +61 -0
  19. viclix_vault-0.1.0/viclix_vault/models/endpoint_schema.py +93 -0
  20. viclix_vault-0.1.0/viclix_vault/models/frontend_call_schema.py +93 -0
  21. viclix_vault-0.1.0/viclix_vault/models/http_validation_error.py +79 -0
  22. viclix_vault-0.1.0/viclix_vault/models/n14_validation_error.py +90 -0
  23. viclix_vault-0.1.0/viclix_vault/models/n14http_validation_error.py +79 -0
  24. viclix_vault-0.1.0/viclix_vault/models/preview_request.py +105 -0
  25. viclix_vault-0.1.0/viclix_vault/models/t2a_validation_error.py +90 -0
  26. viclix_vault-0.1.0/viclix_vault/models/t2ahttp_validation_error.py +79 -0
  27. viclix_vault-0.1.0/viclix_vault/models/validation_error.py +90 -0
  28. viclix_vault-0.1.0/viclix_vault/n14/__init__.py +1 -0
  29. viclix_vault-0.1.0/viclix_vault/n14/api_analyze_api_v1_analyze_post.py +197 -0
  30. viclix_vault-0.1.0/viclix_vault/n14/get_analysis_api_v1_analysis_result_id_get.py +195 -0
  31. viclix_vault-0.1.0/viclix_vault/n14/process_analysis_analyze_post.py +164 -0
  32. viclix_vault-0.1.0/viclix_vault/n14/view_results_results_result_id_get.py +159 -0
  33. viclix_vault-0.1.0/viclix_vault/py.typed +1 -0
  34. viclix_vault-0.1.0/viclix_vault/t2a/__init__.py +1 -0
  35. viclix_vault-0.1.0/viclix_vault/t2a/create_ascii_ascii_generate_post.py +164 -0
  36. viclix_vault-0.1.0/viclix_vault/t2a/create_preview_ascii_preview_post.py +164 -0
  37. viclix_vault-0.1.0/viclix_vault/t2a/get_fonts_ascii_fonts_get.py +81 -0
  38. viclix_vault-0.1.0/viclix_vault/t2a/get_promotional_preview_ascii_preview_t2a_get.py +164 -0
  39. viclix_vault-0.1.0/viclix_vault/types.py +54 -0
@@ -0,0 +1,141 @@
1
+ Metadata-Version: 2.4
2
+ Name: viclix-vault
3
+ Version: 0.1.0
4
+ Summary: A client library for accessing Viclix Microservices API
5
+ Requires-Python: >=3.10,<4.0
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3.10
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Classifier: Programming Language :: Python :: 3.14
12
+ Requires-Dist: attrs (>=22.2.0)
13
+ Requires-Dist: httpx (>=0.23.0,<0.29.0)
14
+ Requires-Dist: python-dateutil (>=2.8.0,<3.0.0)
15
+ Description-Content-Type: text/markdown
16
+
17
+ # viclix-vault
18
+ A client library for accessing Viclix Microservices API
19
+
20
+ ## Usage
21
+ First, create a client:
22
+
23
+ ```python
24
+ from viclix_vault import Client
25
+
26
+ client = Client(base_url="https://api.example.com")
27
+ ```
28
+
29
+ If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead:
30
+
31
+ ```python
32
+ from viclix_vault import AuthenticatedClient
33
+
34
+ client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
35
+ ```
36
+
37
+ Now call your endpoint and use your models:
38
+
39
+ ```python
40
+ from viclix_vault.models import MyDataModel
41
+ from viclix_vault.api.my_tag import get_my_data_model
42
+ from viclix_vault.types import Response
43
+
44
+ with client as client:
45
+ my_data: MyDataModel = get_my_data_model.sync(client=client)
46
+ # or if you need more info (e.g. status_code)
47
+ response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
48
+ ```
49
+
50
+ Or do the same thing with an async version:
51
+
52
+ ```python
53
+ from viclix_vault.models import MyDataModel
54
+ from viclix_vault.api.my_tag import get_my_data_model
55
+ from viclix_vault.types import Response
56
+
57
+ async with client as client:
58
+ my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
59
+ response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
60
+ ```
61
+
62
+ By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
63
+
64
+ ```python
65
+ client = AuthenticatedClient(
66
+ base_url="https://internal_api.example.com",
67
+ token="SuperSecretToken",
68
+ verify_ssl="/path/to/certificate_bundle.pem",
69
+ )
70
+ ```
71
+
72
+ You can also disable certificate validation altogether, but beware that **this is a security risk**.
73
+
74
+ ```python
75
+ client = AuthenticatedClient(
76
+ base_url="https://internal_api.example.com",
77
+ token="SuperSecretToken",
78
+ verify_ssl=False
79
+ )
80
+ ```
81
+
82
+ Things to know:
83
+ 1. Every path/method combo becomes a Python module with four functions:
84
+ 1. `sync`: Blocking request that returns parsed data (if successful) or `None`
85
+ 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
86
+ 1. `asyncio`: Like `sync` but async instead of blocking
87
+ 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
88
+
89
+ 1. All path/query params, and bodies become method arguments.
90
+ 1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
91
+ 1. Any endpoint which did not have a tag will be in `viclix_vault.api.default`
92
+
93
+ ## Advanced customizations
94
+
95
+ There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case):
96
+
97
+ ```python
98
+ from viclix_vault import Client
99
+
100
+ def log_request(request):
101
+ print(f"Request event hook: {request.method} {request.url} - Waiting for response")
102
+
103
+ def log_response(response):
104
+ request = response.request
105
+ print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
106
+
107
+ client = Client(
108
+ base_url="https://api.example.com",
109
+ httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
110
+ )
111
+
112
+ # Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
113
+ ```
114
+
115
+ You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
116
+
117
+ ```python
118
+ import httpx
119
+ from viclix_vault import Client
120
+
121
+ client = Client(
122
+ base_url="https://api.example.com",
123
+ )
124
+ # Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
125
+ client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
126
+ ```
127
+
128
+ ## Building / publishing this package
129
+ This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
130
+ 1. Update the metadata in pyproject.toml (e.g. authors, version)
131
+ 1. If you're using a private repository, configure it with Poetry
132
+ 1. `poetry config repositories.<your-repository-name> <url-to-your-repository>`
133
+ 1. `poetry config http-basic.<your-repository-name> <username> <password>`
134
+ 1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build`
135
+
136
+ If you want to install this client into another project without publishing it (e.g. for development) then:
137
+ 1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project
138
+ 1. If that project is not using Poetry:
139
+ 1. Build a wheel with `poetry build -f wheel`
140
+ 1. Install that wheel from the other project `pip install <path-to-wheel>`
141
+
@@ -0,0 +1,124 @@
1
+ # viclix-vault
2
+ A client library for accessing Viclix Microservices API
3
+
4
+ ## Usage
5
+ First, create a client:
6
+
7
+ ```python
8
+ from viclix_vault import Client
9
+
10
+ client = Client(base_url="https://api.example.com")
11
+ ```
12
+
13
+ If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead:
14
+
15
+ ```python
16
+ from viclix_vault import AuthenticatedClient
17
+
18
+ client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
19
+ ```
20
+
21
+ Now call your endpoint and use your models:
22
+
23
+ ```python
24
+ from viclix_vault.models import MyDataModel
25
+ from viclix_vault.api.my_tag import get_my_data_model
26
+ from viclix_vault.types import Response
27
+
28
+ with client as client:
29
+ my_data: MyDataModel = get_my_data_model.sync(client=client)
30
+ # or if you need more info (e.g. status_code)
31
+ response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
32
+ ```
33
+
34
+ Or do the same thing with an async version:
35
+
36
+ ```python
37
+ from viclix_vault.models import MyDataModel
38
+ from viclix_vault.api.my_tag import get_my_data_model
39
+ from viclix_vault.types import Response
40
+
41
+ async with client as client:
42
+ my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
43
+ response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
44
+ ```
45
+
46
+ By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
47
+
48
+ ```python
49
+ client = AuthenticatedClient(
50
+ base_url="https://internal_api.example.com",
51
+ token="SuperSecretToken",
52
+ verify_ssl="/path/to/certificate_bundle.pem",
53
+ )
54
+ ```
55
+
56
+ You can also disable certificate validation altogether, but beware that **this is a security risk**.
57
+
58
+ ```python
59
+ client = AuthenticatedClient(
60
+ base_url="https://internal_api.example.com",
61
+ token="SuperSecretToken",
62
+ verify_ssl=False
63
+ )
64
+ ```
65
+
66
+ Things to know:
67
+ 1. Every path/method combo becomes a Python module with four functions:
68
+ 1. `sync`: Blocking request that returns parsed data (if successful) or `None`
69
+ 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
70
+ 1. `asyncio`: Like `sync` but async instead of blocking
71
+ 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
72
+
73
+ 1. All path/query params, and bodies become method arguments.
74
+ 1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
75
+ 1. Any endpoint which did not have a tag will be in `viclix_vault.api.default`
76
+
77
+ ## Advanced customizations
78
+
79
+ There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case):
80
+
81
+ ```python
82
+ from viclix_vault import Client
83
+
84
+ def log_request(request):
85
+ print(f"Request event hook: {request.method} {request.url} - Waiting for response")
86
+
87
+ def log_response(response):
88
+ request = response.request
89
+ print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
90
+
91
+ client = Client(
92
+ base_url="https://api.example.com",
93
+ httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
94
+ )
95
+
96
+ # Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
97
+ ```
98
+
99
+ You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
100
+
101
+ ```python
102
+ import httpx
103
+ from viclix_vault import Client
104
+
105
+ client = Client(
106
+ base_url="https://api.example.com",
107
+ )
108
+ # Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
109
+ client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
110
+ ```
111
+
112
+ ## Building / publishing this package
113
+ This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
114
+ 1. Update the metadata in pyproject.toml (e.g. authors, version)
115
+ 1. If you're using a private repository, configure it with Poetry
116
+ 1. `poetry config repositories.<your-repository-name> <url-to-your-repository>`
117
+ 1. `poetry config http-basic.<your-repository-name> <username> <password>`
118
+ 1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build`
119
+
120
+ If you want to install this client into another project without publishing it (e.g. for development) then:
121
+ 1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project
122
+ 1. If that project is not using Poetry:
123
+ 1. Build a wheel with `poetry build -f wheel`
124
+ 1. Install that wheel from the other project `pip install <path-to-wheel>`
@@ -0,0 +1,26 @@
1
+ [tool.poetry]
2
+ name = "viclix-vault"
3
+ version = "0.1.0"
4
+ description = "A client library for accessing Viclix Microservices API"
5
+ authors = []
6
+ readme = "README.md"
7
+ packages = [
8
+ { include = "viclix_vault" },
9
+ ]
10
+ include = ["viclix_vault/py.typed"]
11
+
12
+ [tool.poetry.dependencies]
13
+ python = "^3.10"
14
+ httpx = ">=0.23.0,<0.29.0"
15
+ attrs = ">=22.2.0"
16
+ python-dateutil = "^2.8.0"
17
+
18
+ [build-system]
19
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
20
+ build-backend = "poetry.core.masonry.api"
21
+
22
+ [tool.ruff]
23
+ line-length = 120
24
+
25
+ [tool.ruff.lint]
26
+ select = ["F", "I", "UP"]
@@ -0,0 +1,8 @@
1
+ """A client library for accessing Viclix Microservices API"""
2
+
3
+ from .client import AuthenticatedClient, Client
4
+
5
+ __all__ = (
6
+ "AuthenticatedClient",
7
+ "Client",
8
+ )
@@ -0,0 +1,284 @@
1
+ import ssl
2
+ from typing import Any
3
+
4
+ import httpx
5
+ from attrs import define, evolve, field
6
+
7
+
8
+ @define
9
+ class Client:
10
+ """A class for keeping track of data related to the API
11
+
12
+ The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
13
+
14
+ ``base_url``: The base URL for the API, all requests are made to a relative path to this URL
15
+
16
+ ``cookies``: A dictionary of cookies to be sent with every request
17
+
18
+ ``headers``: A dictionary of headers to be sent with every request
19
+
20
+ ``timeout``: The maximum amount of a time a request can take. API functions will raise
21
+ httpx.TimeoutException if this is exceeded.
22
+
23
+ ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
24
+ but can be set to False for testing purposes.
25
+
26
+ ``follow_redirects``: Whether or not to follow redirects. Default value is False.
27
+
28
+ ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
29
+
30
+
31
+ Attributes:
32
+ raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
33
+ status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
34
+ argument to the constructor.
35
+ """
36
+
37
+ raise_on_unexpected_status: bool = field(default=False, kw_only=True)
38
+ service: str = field(default=None, kw_only=True)
39
+ _base_url: str = field(alias="base_url", default="")
40
+
41
+ def __attrs_post_init__(self):
42
+ if self.service:
43
+ PREFIX = "jp-" # Cambiar a "" para producción
44
+ self._base_url = f"https://{PREFIX}{self.service}.viclix.com"
45
+ elif not self._base_url:
46
+ raise ValueError("Debes proveer 'service' o 'base_url'")
47
+ _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
48
+ _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
49
+ _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
50
+ _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
51
+ _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
52
+ _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
53
+ _client: httpx.Client | None = field(default=None, init=False)
54
+ _async_client: httpx.AsyncClient | None = field(default=None, init=False)
55
+
56
+ def with_headers(self, headers: dict[str, str]) -> "Client":
57
+ """Get a new client matching this one with additional headers"""
58
+ if self._client is not None:
59
+ self._client.headers.update(headers)
60
+ if self._async_client is not None:
61
+ self._async_client.headers.update(headers)
62
+ return evolve(self, headers={**self._headers, **headers})
63
+
64
+ def with_cookies(self, cookies: dict[str, str]) -> "Client":
65
+ """Get a new client matching this one with additional cookies"""
66
+ if self._client is not None:
67
+ self._client.cookies.update(cookies)
68
+ if self._async_client is not None:
69
+ self._async_client.cookies.update(cookies)
70
+ return evolve(self, cookies={**self._cookies, **cookies})
71
+
72
+ def with_timeout(self, timeout: httpx.Timeout) -> "Client":
73
+ """Get a new client matching this one with a new timeout configuration"""
74
+ if self._client is not None:
75
+ self._client.timeout = timeout
76
+ if self._async_client is not None:
77
+ self._async_client.timeout = timeout
78
+ return evolve(self, timeout=timeout)
79
+
80
+ def set_httpx_client(self, client: httpx.Client) -> "Client":
81
+ """Manually set the underlying httpx.Client
82
+
83
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
84
+ """
85
+ self._client = client
86
+ return self
87
+
88
+ def get_httpx_client(self) -> httpx.Client:
89
+ """Get the underlying httpx.Client, constructing a new one if not previously set"""
90
+ if self._client is None:
91
+ self._client = httpx.Client(
92
+ base_url=self._base_url,
93
+ cookies=self._cookies,
94
+ headers=self._headers,
95
+ timeout=self._timeout,
96
+ verify=self._verify_ssl,
97
+ follow_redirects=self._follow_redirects,
98
+ **self._httpx_args,
99
+ )
100
+ return self._client
101
+
102
+ def __enter__(self) -> "Client":
103
+ """Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
104
+ self.get_httpx_client().__enter__()
105
+ return self
106
+
107
+ def __exit__(self, *args: Any, **kwargs: Any) -> None:
108
+ """Exit a context manager for internal httpx.Client (see httpx docs)"""
109
+ self.get_httpx_client().__exit__(*args, **kwargs)
110
+
111
+ def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client":
112
+ """Manually set the underlying httpx.AsyncClient
113
+
114
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
115
+ """
116
+ self._async_client = async_client
117
+ return self
118
+
119
+ def get_async_httpx_client(self) -> httpx.AsyncClient:
120
+ """Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
121
+ if self._async_client is None:
122
+ self._async_client = httpx.AsyncClient(
123
+ base_url=self._base_url,
124
+ cookies=self._cookies,
125
+ headers=self._headers,
126
+ timeout=self._timeout,
127
+ verify=self._verify_ssl,
128
+ follow_redirects=self._follow_redirects,
129
+ **self._httpx_args,
130
+ )
131
+ return self._async_client
132
+
133
+ async def __aenter__(self) -> "Client":
134
+ """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
135
+ await self.get_async_httpx_client().__aenter__()
136
+ return self
137
+
138
+ async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
139
+ """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
140
+ await self.get_async_httpx_client().__aexit__(*args, **kwargs)
141
+
142
+
143
+ @define
144
+ class AuthenticatedClient:
145
+ """A Client which has been authenticated for use on secured endpoints
146
+
147
+ The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
148
+
149
+ ``base_url``: The base URL for the API, all requests are made to a relative path to this URL
150
+
151
+ ``cookies``: A dictionary of cookies to be sent with every request
152
+
153
+ ``headers``: A dictionary of headers to be sent with every request
154
+
155
+ ``timeout``: The maximum amount of a time a request can take. API functions will raise
156
+ httpx.TimeoutException if this is exceeded.
157
+
158
+ ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
159
+ but can be set to False for testing purposes.
160
+
161
+ ``follow_redirects``: Whether or not to follow redirects. Default value is False.
162
+
163
+ ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
164
+
165
+
166
+ Attributes:
167
+ raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
168
+ status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
169
+ argument to the constructor.
170
+ token: The token to use for authentication
171
+ prefix: The prefix to use for the Authorization header
172
+ auth_header_name: The name of the Authorization header
173
+ """
174
+
175
+ raise_on_unexpected_status: bool = field(default=False, kw_only=True)
176
+ service: str = field(default=None, kw_only=True)
177
+ _base_url: str = field(alias="base_url", default="")
178
+
179
+ def __attrs_post_init__(self):
180
+ if self.service:
181
+ PREFIX = "jp-" # Cambiar a "" para producción
182
+ self._base_url = f"https://{PREFIX}{self.service}.viclix.com"
183
+ elif not self._base_url:
184
+ raise ValueError("Debes proveer 'service' o 'base_url'")
185
+ _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
186
+ _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
187
+ _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
188
+ _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
189
+ _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
190
+ _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
191
+ _client: httpx.Client | None = field(default=None, init=False)
192
+ _async_client: httpx.AsyncClient | None = field(default=None, init=False)
193
+
194
+ token: str
195
+ prefix: str = "Bearer"
196
+ auth_header_name: str = "Authorization"
197
+
198
+ def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient":
199
+ """Get a new client matching this one with additional headers"""
200
+ if self._client is not None:
201
+ self._client.headers.update(headers)
202
+ if self._async_client is not None:
203
+ self._async_client.headers.update(headers)
204
+ return evolve(self, headers={**self._headers, **headers})
205
+
206
+ def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient":
207
+ """Get a new client matching this one with additional cookies"""
208
+ if self._client is not None:
209
+ self._client.cookies.update(cookies)
210
+ if self._async_client is not None:
211
+ self._async_client.cookies.update(cookies)
212
+ return evolve(self, cookies={**self._cookies, **cookies})
213
+
214
+ def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
215
+ """Get a new client matching this one with a new timeout configuration"""
216
+ if self._client is not None:
217
+ self._client.timeout = timeout
218
+ if self._async_client is not None:
219
+ self._async_client.timeout = timeout
220
+ return evolve(self, timeout=timeout)
221
+
222
+ def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
223
+ """Manually set the underlying httpx.Client
224
+
225
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
226
+ """
227
+ self._client = client
228
+ return self
229
+
230
+ def get_httpx_client(self) -> httpx.Client:
231
+ """Get the underlying httpx.Client, constructing a new one if not previously set"""
232
+ if self._client is None:
233
+ self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
234
+ self._client = httpx.Client(
235
+ base_url=self._base_url,
236
+ cookies=self._cookies,
237
+ headers=self._headers,
238
+ timeout=self._timeout,
239
+ verify=self._verify_ssl,
240
+ follow_redirects=self._follow_redirects,
241
+ **self._httpx_args,
242
+ )
243
+ return self._client
244
+
245
+ def __enter__(self) -> "AuthenticatedClient":
246
+ """Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
247
+ self.get_httpx_client().__enter__()
248
+ return self
249
+
250
+ def __exit__(self, *args: Any, **kwargs: Any) -> None:
251
+ """Exit a context manager for internal httpx.Client (see httpx docs)"""
252
+ self.get_httpx_client().__exit__(*args, **kwargs)
253
+
254
+ def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient":
255
+ """Manually set the underlying httpx.AsyncClient
256
+
257
+ **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
258
+ """
259
+ self._async_client = async_client
260
+ return self
261
+
262
+ def get_async_httpx_client(self) -> httpx.AsyncClient:
263
+ """Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
264
+ if self._async_client is None:
265
+ self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
266
+ self._async_client = httpx.AsyncClient(
267
+ base_url=self._base_url,
268
+ cookies=self._cookies,
269
+ headers=self._headers,
270
+ timeout=self._timeout,
271
+ verify=self._verify_ssl,
272
+ follow_redirects=self._follow_redirects,
273
+ **self._httpx_args,
274
+ )
275
+ return self._async_client
276
+
277
+ async def __aenter__(self) -> "AuthenticatedClient":
278
+ """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
279
+ await self.get_async_httpx_client().__aenter__()
280
+ return self
281
+
282
+ async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
283
+ """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
284
+ await self.get_async_httpx_client().__aexit__(*args, **kwargs)
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""