kos-cloud 1.0.0b1__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.
- kos_cloud/__init__.py +79 -0
- kos_cloud/_client.py +792 -0
- kos_cloud/_errors.py +179 -0
- kos_cloud/_http.py +330 -0
- kos_cloud/_types.py +253 -0
- kos_cloud/py.typed +0 -0
- kos_cloud-1.0.0b1.dist-info/METADATA +173 -0
- kos_cloud-1.0.0b1.dist-info/RECORD +12 -0
- kos_cloud-1.0.0b1.dist-info/WHEEL +5 -0
- kos_cloud-1.0.0b1.dist-info/licenses/LICENSE +201 -0
- kos_cloud-1.0.0b1.dist-info/licenses/NOTICE +4 -0
- kos_cloud-1.0.0b1.dist-info/top_level.txt +1 -0
kos_cloud/__init__.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""kos-cloud: solve LP and MIP models on KOS Cloud from Python.
|
|
2
|
+
|
|
3
|
+
Example::
|
|
4
|
+
|
|
5
|
+
import kos_cloud
|
|
6
|
+
r = kos_cloud.solve("model.mps", tier="medium", time_limit=600)
|
|
7
|
+
print(r.status, r.objective)
|
|
8
|
+
print(r.values["x"])
|
|
9
|
+
|
|
10
|
+
The API key comes from the ``KOS_API_KEY`` environment variable (or ``Client(api_key=...)``); the API from
|
|
11
|
+
``KOS_CLOUD_URL`` (or ``Client(base_url=...)``), by default ``https://katsenia.com/api/v1/``. The functions of this
|
|
12
|
+
module use a client made from those variables; `Client` gives one of your own.
|
|
13
|
+
|
|
14
|
+
While a call waits for a job, Ctrl+C cancels the job and raises ``KeyboardInterrupt`` again.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import hashlib
|
|
18
|
+
import inspect
|
|
19
|
+
import os
|
|
20
|
+
import threading
|
|
21
|
+
|
|
22
|
+
__version__ = "1.0.0b1"
|
|
23
|
+
|
|
24
|
+
from ._client import DEFAULT_BASE_URL, Client # noqa: E402
|
|
25
|
+
from ._errors import (AuthenticationError, EmailNotVerifiedError, InsufficientBalanceError, # noqa: E402
|
|
26
|
+
JobCancelledError, JobFailedError, JobModelTooLargeError, KosCloudError, LimitError,
|
|
27
|
+
MachineNotAvailableError, ModelTooLargeError, NetworkError, PreviewGateError, RateLimitError,
|
|
28
|
+
TimeLimitError, WaitTimeoutError)
|
|
29
|
+
from ._types import Balance, Billing, Catalog, Job, MachineClass, Result # noqa: E402
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"Client", "DEFAULT_BASE_URL",
|
|
33
|
+
"solve", "submit", "wait", "result", "jobs", "job", "cancel", "balance", "classes",
|
|
34
|
+
"Job", "Result", "Billing", "Balance", "Catalog", "MachineClass",
|
|
35
|
+
"KosCloudError", "AuthenticationError", "PreviewGateError", "InsufficientBalanceError", "EmailNotVerifiedError",
|
|
36
|
+
"LimitError", "ModelTooLargeError", "TimeLimitError", "MachineNotAvailableError", "RateLimitError",
|
|
37
|
+
"NetworkError", "WaitTimeoutError", "JobFailedError", "JobModelTooLargeError", "JobCancelledError",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
# El cliente de las funciones del módulo: se rehace si cambian KOS_API_KEY o KOS_CLOUD_URL (se guarda la huella de la
|
|
41
|
+
# clave, no la clave).
|
|
42
|
+
_cerrojo = threading.Lock()
|
|
43
|
+
_cliente = None
|
|
44
|
+
_huella = None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _por_omision() -> Client:
|
|
48
|
+
global _cliente, _huella
|
|
49
|
+
clave = os.environ.get("KOS_API_KEY") or ""
|
|
50
|
+
huella = (hashlib.sha256(clave.encode("utf-8", "replace")).hexdigest(), os.environ.get("KOS_CLOUD_URL") or "")
|
|
51
|
+
with _cerrojo:
|
|
52
|
+
if _cliente is None or _huella != huella:
|
|
53
|
+
_cliente, _huella = Client(), huella
|
|
54
|
+
return _cliente
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _del_modulo(nombre):
|
|
58
|
+
metodo = getattr(Client, nombre)
|
|
59
|
+
|
|
60
|
+
def funcion(*args, **kwargs):
|
|
61
|
+
return getattr(_por_omision(), nombre)(*args, **kwargs)
|
|
62
|
+
|
|
63
|
+
funcion.__name__ = funcion.__qualname__ = nombre
|
|
64
|
+
funcion.__doc__ = metodo.__doc__
|
|
65
|
+
firma = inspect.signature(metodo)
|
|
66
|
+
funcion.__signature__ = firma.replace(parameters=list(firma.parameters.values())[1:])
|
|
67
|
+
funcion.__module__ = __name__
|
|
68
|
+
return funcion
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
solve = _del_modulo("solve")
|
|
72
|
+
submit = _del_modulo("submit")
|
|
73
|
+
wait = _del_modulo("wait")
|
|
74
|
+
result = _del_modulo("result")
|
|
75
|
+
jobs = _del_modulo("jobs")
|
|
76
|
+
job = _del_modulo("job")
|
|
77
|
+
cancel = _del_modulo("cancel")
|
|
78
|
+
balance = _del_modulo("balance")
|
|
79
|
+
classes = _del_modulo("classes")
|