plotwork 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.
- plotwork/__init__.py +90 -0
- plotwork/_generated.py +2201 -0
- plotwork/_request.py +187 -0
- plotwork/_version.py +3 -0
- plotwork/py.typed +0 -0
- plotwork-0.1.0.dist-info/METADATA +141 -0
- plotwork-0.1.0.dist-info/RECORD +9 -0
- plotwork-0.1.0.dist-info/WHEEL +4 -0
- plotwork-0.1.0.dist-info/licenses/LICENSE +21 -0
plotwork/__init__.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""``plotwork``: the hosted Plotwork API from Python, on the standard library alone.
|
|
2
|
+
|
|
3
|
+
Every ``/v1`` operation is a typed method generated from ``spec/openapi.json``::
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from plotwork import Plotwork
|
|
7
|
+
|
|
8
|
+
plotwork = Plotwork(api_key=os.environ["PLOTWORK_API_KEY"])
|
|
9
|
+
checked = plotwork.diagrams.validate(source=source)
|
|
10
|
+
published = plotwork.diagrams.publish(source=source, alias="checkout-flow")
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from typing import Any, Callable, Dict, Optional
|
|
16
|
+
|
|
17
|
+
from ._generated import OPERATION_PATHS, Operations
|
|
18
|
+
from ._request import Opener, PlotworkApiError, Transport, retry_delay
|
|
19
|
+
from ._version import __version__
|
|
20
|
+
|
|
21
|
+
__all__ = ["DEFAULT_BASE_URL", "OPERATION_PATHS", "Plotwork", "PlotworkApiError", "Transport", "__version__", "retry_delay"]
|
|
22
|
+
|
|
23
|
+
#: The production API.
|
|
24
|
+
DEFAULT_BASE_URL = "https://api.plotwork.dev"
|
|
25
|
+
|
|
26
|
+
_UNSET: Any = object()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Plotwork(Operations):
|
|
30
|
+
"""The Plotwork API client.
|
|
31
|
+
|
|
32
|
+
:param api_key: An account or organisation API key, sent as ``X-API-Key``. Keep it in an environment variable or a secret store.
|
|
33
|
+
:param access_token: An OAuth access token, sent as ``Authorization: Bearer``, in place of a key.
|
|
34
|
+
:param base_url: The API's address: production by default, ``https://api-preview.plotwork.dev`` for preview, or a self-hosted engine.
|
|
35
|
+
:param timeout: Seconds before a call counts as failed: 60 by default.
|
|
36
|
+
:param max_retries: How many times a safe call is tried again on 429 or 503: 2 by default, 0 to never retry.
|
|
37
|
+
:param opener: Opens each request, called like ``urllib.request.urlopen``; a proxy or a test passes its own.
|
|
38
|
+
:param sleep: Waits the given seconds before a retry; ``time.sleep`` by default.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
*,
|
|
44
|
+
api_key: Optional[str] = None,
|
|
45
|
+
access_token: Optional[str] = None,
|
|
46
|
+
base_url: Optional[str] = None,
|
|
47
|
+
timeout: float = 60.0,
|
|
48
|
+
max_retries: int = 2,
|
|
49
|
+
opener: Optional[Opener] = None,
|
|
50
|
+
sleep: Optional[Callable[[float], Any]] = None,
|
|
51
|
+
) -> None:
|
|
52
|
+
headers: Dict[str, str] = {}
|
|
53
|
+
if api_key:
|
|
54
|
+
headers["X-API-Key"] = api_key
|
|
55
|
+
if access_token:
|
|
56
|
+
headers["Authorization"] = f"Bearer {access_token}"
|
|
57
|
+
self._options: Dict[str, Any] = {
|
|
58
|
+
"api_key": api_key,
|
|
59
|
+
"access_token": access_token,
|
|
60
|
+
"base_url": base_url,
|
|
61
|
+
"timeout": timeout,
|
|
62
|
+
"max_retries": max_retries,
|
|
63
|
+
"opener": opener,
|
|
64
|
+
"sleep": sleep,
|
|
65
|
+
}
|
|
66
|
+
super().__init__(
|
|
67
|
+
Transport(
|
|
68
|
+
base_url=base_url or DEFAULT_BASE_URL,
|
|
69
|
+
headers=headers,
|
|
70
|
+
timeout=timeout,
|
|
71
|
+
max_retries=max_retries,
|
|
72
|
+
opener=opener,
|
|
73
|
+
sleep=sleep,
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
def with_options(self, *, timeout: float = _UNSET, max_retries: int = _UNSET) -> "Plotwork":
|
|
78
|
+
"""A copy of this client with another timeout or number of retries, for one call or a few:
|
|
79
|
+
|
|
80
|
+
``plotwork.with_options(timeout=120).import_source(format="terraform", text=text)``
|
|
81
|
+
"""
|
|
82
|
+
options = dict(self._options)
|
|
83
|
+
if timeout is not _UNSET:
|
|
84
|
+
options["timeout"] = timeout
|
|
85
|
+
if max_retries is not _UNSET:
|
|
86
|
+
options["max_retries"] = max_retries
|
|
87
|
+
return Plotwork(**options)
|
|
88
|
+
|
|
89
|
+
def __repr__(self) -> str:
|
|
90
|
+
return f"Plotwork(base_url={self._transport.base_url!r})"
|