pyvar-client 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.
@@ -0,0 +1,34 @@
1
+ """pyvar_client — Python SDK for pyvar.com's REST API.
2
+
3
+ >>> from pyvar_client import Client
4
+ >>> client = Client(api_key="eyJ...")
5
+ >>> client.market_risk.historical_simulation_var(...)
6
+
7
+ See Client's own docstring for auth/usage, and pyvar_client._generated's
8
+ module docstring for how the 385 per-domain methods are produced.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from pyvar_client._client import Client
14
+ from pyvar_client.exceptions import (
15
+ PyvarAuthError,
16
+ PyvarComputeError,
17
+ PyvarError,
18
+ PyvarRateLimitError,
19
+ PyvarTimeoutError,
20
+ PyvarValidationError,
21
+ )
22
+
23
+ __version__ = "0.1.0"
24
+
25
+ __all__ = [
26
+ "Client",
27
+ "PyvarAuthError",
28
+ "PyvarComputeError",
29
+ "PyvarError",
30
+ "PyvarRateLimitError",
31
+ "PyvarTimeoutError",
32
+ "PyvarValidationError",
33
+ "__version__",
34
+ ]
@@ -0,0 +1,120 @@
1
+ """pyvar_client._client — the Client entry point.
2
+
3
+ Reasoning:
4
+ - One Client, one httpx.Client (connection pooling/keep-alive reused
5
+ across every call), one token. Per-domain namespaces
6
+ (client.market_risk, client.credit_risk, ...) are generated from the
7
+ live OpenAPI schema by codegen/generate.py -- see pyvar_client/
8
+ _generated/'s own module docstring for what "generated" means here and
9
+ why it isn't hand-maintained.
10
+ - Auth is a token the caller already has (register/verify is a one-time
11
+ human step via the portal's email-verification flow -- POST
12
+ /api/v1/auth/register + clicking the emailed link). This client has no
13
+ register()/verify() methods and doesn't automate that flow.
14
+ - base_url defaults to prod. Point it at http://localhost:8000 for local
15
+ dev against `uvicorn main:app --reload`, or https://dev.pyvar.com
16
+ against the dev deployment.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ from types import TracebackType
22
+
23
+ import httpx
24
+
25
+ from pyvar_client._generated.alm import AlmNamespace
26
+ from pyvar_client._generated.credit_risk import CreditRiskNamespace
27
+ from pyvar_client._generated.derivatives import DerivativesNamespace
28
+ from pyvar_client._generated.liquidity import LiquidityNamespace
29
+ from pyvar_client._generated.market_risk import MarketRiskNamespace
30
+ from pyvar_client._generated.operational import OperationalNamespace
31
+ from pyvar_client._generated.portfolio import PortfolioNamespace
32
+ from pyvar_client._generated.regulatory import RegulatoryNamespace
33
+ from pyvar_client._transport import send_request
34
+ from pyvar_client._var import VarNamespace
35
+
36
+ DEFAULT_BASE_URL = "https://www.pyvar.com"
37
+ DEFAULT_TIMEOUT_SECONDS = 30.0
38
+
39
+
40
+ class Client:
41
+ """pyvar.com API client.
42
+
43
+ Example:
44
+ >>> client = Client(api_key="eyJ...")
45
+ >>> result = client.market_risk.historical_simulation_var(
46
+ ... returns=[...], portfolio_value=1_000_000, confidence_level=0.99,
47
+ ... )
48
+ >>> var_result = client.var.compute(
49
+ ... returns=[...], portfolio_value=1_000_000, n_simulations=100_000,
50
+ ... ) # blocks: submits, polls, returns the finished VaRResult
51
+
52
+ Args:
53
+ api_key: Bearer JWT obtained via the portal's registration/
54
+ verification flow. Required -- this client has no
55
+ registration flow of its own.
56
+ base_url: API base URL. Defaults to production.
57
+ timeout: Per-request timeout in seconds, passed straight to httpx.
58
+ transport: An httpx transport override. Not needed for real usage
59
+ -- exists so tests can swap in an httpx.MockTransport instead
60
+ of making real HTTP calls (see tests/conftest.py), the same
61
+ "never hit a real service in tests" rule the main pyvar repo
62
+ applies to AWS.
63
+ """
64
+
65
+ def __init__(
66
+ self,
67
+ api_key: str,
68
+ *,
69
+ base_url: str = DEFAULT_BASE_URL,
70
+ timeout: float = DEFAULT_TIMEOUT_SECONDS,
71
+ transport: httpx.BaseTransport | None = None,
72
+ ) -> None:
73
+ if not api_key:
74
+ raise ValueError("api_key is required")
75
+
76
+ self._api_key = api_key
77
+ self._http = httpx.Client(base_url=base_url, timeout=timeout, transport=transport)
78
+
79
+ self.market_risk = MarketRiskNamespace(self)
80
+ self.derivatives = DerivativesNamespace(self)
81
+ self.credit_risk = CreditRiskNamespace(self)
82
+ self.portfolio = PortfolioNamespace(self)
83
+ self.operational_risk = OperationalNamespace(self)
84
+ self.liquidity_risk = LiquidityNamespace(self)
85
+ self.alm = AlmNamespace(self)
86
+ self.regulatory = RegulatoryNamespace(self)
87
+ self.var = VarNamespace(self)
88
+
89
+ def _request(
90
+ self,
91
+ method: str,
92
+ path: str,
93
+ *,
94
+ json_body: dict | None = None,
95
+ params: dict | None = None,
96
+ idempotent: bool = True,
97
+ ) -> dict:
98
+ return send_request(
99
+ self._http,
100
+ method,
101
+ path,
102
+ token=self._api_key,
103
+ json_body=json_body,
104
+ params=params,
105
+ idempotent=idempotent,
106
+ )
107
+
108
+ def close(self) -> None:
109
+ self._http.close()
110
+
111
+ def __enter__(self) -> "Client":
112
+ return self
113
+
114
+ def __exit__(
115
+ self,
116
+ exc_type: type[BaseException] | None,
117
+ exc: BaseException | None,
118
+ tb: TracebackType | None,
119
+ ) -> None:
120
+ self.close()
@@ -0,0 +1,21 @@
1
+ """Generated per-domain namespaces -- see codegen/generate.py."""
2
+
3
+ from pyvar_client._generated.alm import AlmNamespace
4
+ from pyvar_client._generated.credit_risk import CreditRiskNamespace
5
+ from pyvar_client._generated.derivatives import DerivativesNamespace
6
+ from pyvar_client._generated.liquidity import LiquidityNamespace
7
+ from pyvar_client._generated.market_risk import MarketRiskNamespace
8
+ from pyvar_client._generated.operational import OperationalNamespace
9
+ from pyvar_client._generated.portfolio import PortfolioNamespace
10
+ from pyvar_client._generated.regulatory import RegulatoryNamespace
11
+
12
+ __all__ = [
13
+ "AlmNamespace",
14
+ "CreditRiskNamespace",
15
+ "DerivativesNamespace",
16
+ "LiquidityNamespace",
17
+ "MarketRiskNamespace",
18
+ "OperationalNamespace",
19
+ "PortfolioNamespace",
20
+ "RegulatoryNamespace",
21
+ ]