vantage-python 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.
- vantage/__init__.py +78 -0
- vantage/_async/__init__.py +5 -0
- vantage/_base.py +74 -0
- vantage/_sync/__init__.py +5 -0
- vantage/py.typed +0 -0
- vantage_python-0.1.0.dist-info/METADATA +111 -0
- vantage_python-0.1.0.dist-info/RECORD +9 -0
- vantage_python-0.1.0.dist-info/WHEEL +4 -0
- vantage_python-0.1.0.dist-info/licenses/LICENSE +21 -0
vantage/__init__.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Vantage API Python SDK.
|
|
3
|
+
|
|
4
|
+
This package provides both synchronous and asynchronous clients for the Vantage API.
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
# Synchronous client
|
|
8
|
+
from vantage import Client
|
|
9
|
+
|
|
10
|
+
client = Client("your-api-token")
|
|
11
|
+
folders = client.folders.list()
|
|
12
|
+
|
|
13
|
+
# Async client
|
|
14
|
+
from vantage import AsyncClient
|
|
15
|
+
|
|
16
|
+
async def main():
|
|
17
|
+
async with AsyncClient("your-api-token") as client:
|
|
18
|
+
folders = await client.folders.list()
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
from typing import TYPE_CHECKING
|
|
24
|
+
|
|
25
|
+
from ._base import VantageAPIError, DEFAULT_BASE_URL
|
|
26
|
+
from ._types import *
|
|
27
|
+
|
|
28
|
+
if TYPE_CHECKING:
|
|
29
|
+
from ._sync.client import SyncClient as _SyncClient
|
|
30
|
+
from ._async.client import AsyncClient as _AsyncClient
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def Client(
|
|
34
|
+
bearer_token: str,
|
|
35
|
+
*,
|
|
36
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
37
|
+
) -> "_SyncClient":
|
|
38
|
+
"""
|
|
39
|
+
Create a synchronous Vantage API client.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
bearer_token: Your Vantage API bearer token.
|
|
43
|
+
base_url: Base URL for the API (default: https://api.vantage.sh).
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
A synchronous client instance.
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
client = Client("your-token")
|
|
50
|
+
folders = client.folders.list()
|
|
51
|
+
"""
|
|
52
|
+
from ._sync.client import SyncClient
|
|
53
|
+
|
|
54
|
+
return SyncClient(bearer_token, base_url=base_url)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def AsyncClient(
|
|
58
|
+
bearer_token: str,
|
|
59
|
+
*,
|
|
60
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
61
|
+
) -> "_AsyncClient":
|
|
62
|
+
"""
|
|
63
|
+
Create an asynchronous Vantage API client.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
bearer_token: Your Vantage API bearer token.
|
|
67
|
+
base_url: Base URL for the API (default: https://api.vantage.sh).
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
An asynchronous client instance.
|
|
71
|
+
|
|
72
|
+
Example:
|
|
73
|
+
async with AsyncClient("your-token") as client:
|
|
74
|
+
folders = await client.folders.list()
|
|
75
|
+
"""
|
|
76
|
+
from ._async.client import AsyncClient as _AsyncClientImpl
|
|
77
|
+
|
|
78
|
+
return _AsyncClientImpl(bearer_token, base_url=base_url)
|
vantage/_base.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Base client implementation for Vantage API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Optional, List, Dict, Set
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from urllib.parse import quote
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class VantageAPIError(Exception):
|
|
12
|
+
"""Error returned from the Vantage API."""
|
|
13
|
+
|
|
14
|
+
status: Optional[int]
|
|
15
|
+
status_text: Optional[str]
|
|
16
|
+
body: str
|
|
17
|
+
errors: Optional[List[str]] = None
|
|
18
|
+
|
|
19
|
+
def __post_init__(self) -> None:
|
|
20
|
+
super().__init__(f"VantageAPIError: {self.status} {self.status_text}")
|
|
21
|
+
# Try to parse errors from JSON body
|
|
22
|
+
if self.body:
|
|
23
|
+
try:
|
|
24
|
+
import json
|
|
25
|
+
|
|
26
|
+
parsed = json.loads(self.body)
|
|
27
|
+
if isinstance(parsed, dict) and "errors" in parsed:
|
|
28
|
+
self.errors = parsed["errors"]
|
|
29
|
+
except (json.JSONDecodeError, KeyError):
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# Multipart edge cases - routes that use multipart/form-data
|
|
34
|
+
MULTIPART_ROUTES: Dict[str, Set[str]] = {
|
|
35
|
+
"/v2/exchange_rates/csv": {"POST"},
|
|
36
|
+
"/v2/business_metrics/{business_metric_token}/values.csv": {"PUT"},
|
|
37
|
+
"/v2/integrations/{integration_token}/costs.csv": {"POST"},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def is_multipart_route(path: str, method: str) -> bool:
|
|
42
|
+
"""Check if a route uses multipart/form-data."""
|
|
43
|
+
import re
|
|
44
|
+
|
|
45
|
+
for pattern, methods in MULTIPART_ROUTES.items():
|
|
46
|
+
if method.upper() not in methods:
|
|
47
|
+
continue
|
|
48
|
+
# Convert path pattern to regex
|
|
49
|
+
regex_pattern = re.sub(r"\{[^}]+\}", r"[^/]+", pattern)
|
|
50
|
+
if re.fullmatch(regex_pattern, path):
|
|
51
|
+
return True
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def build_query_string(params: Dict[str, Any]) -> str:
|
|
56
|
+
"""Build a URL-safe query string from parameters."""
|
|
57
|
+
if not params:
|
|
58
|
+
return ""
|
|
59
|
+
parts = []
|
|
60
|
+
for key, value in params.items():
|
|
61
|
+
if value is None:
|
|
62
|
+
continue
|
|
63
|
+
enc_key = quote(str(key), safe="")
|
|
64
|
+
if isinstance(value, bool):
|
|
65
|
+
parts.append(f"{enc_key}={str(value).lower()}")
|
|
66
|
+
elif isinstance(value, list):
|
|
67
|
+
joined = ",".join(quote(str(v), safe="") for v in value)
|
|
68
|
+
parts.append(f"{enc_key}={joined}")
|
|
69
|
+
else:
|
|
70
|
+
parts.append(f"{enc_key}={quote(str(value), safe='')}")
|
|
71
|
+
return "?" + "&".join(parts) if parts else ""
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
DEFAULT_BASE_URL = "https://api.vantage.sh/v2"
|
vantage/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vantage-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the Vantage API
|
|
5
|
+
Project-URL: Homepage, https://github.com/vantage-sh/vantage-python
|
|
6
|
+
Project-URL: Repository, https://github.com/vantage-sh/vantage-python
|
|
7
|
+
Author: Vantage
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: api,client,cloud,cost,sdk,vantage
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Requires-Dist: httpx>=0.27.0
|
|
13
|
+
Requires-Dist: pydantic>=2.0.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: build>=1.0.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
18
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
19
|
+
Requires-Dist: twine>=6.0.0; extra == 'dev'
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# vantage-python
|
|
23
|
+
|
|
24
|
+
A Python SDK for the [Vantage](https://vantage.sh) API. Types and client methods are auto-generated from the official OpenAPI specification.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install vantage-python
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Synchronous Client
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from vantage import Client
|
|
38
|
+
|
|
39
|
+
client = Client("your-api-token")
|
|
40
|
+
|
|
41
|
+
# List resources with query parameters
|
|
42
|
+
reports = client.cost_reports.list(page=1)
|
|
43
|
+
|
|
44
|
+
# Get a specific resource by token
|
|
45
|
+
report = client.cost_reports.get("rprt_abc123")
|
|
46
|
+
|
|
47
|
+
# Create a new resource
|
|
48
|
+
folder = client.folders.create(CreateFolder(
|
|
49
|
+
title="Production Costs",
|
|
50
|
+
workspace_token="wrkspc_123",
|
|
51
|
+
))
|
|
52
|
+
|
|
53
|
+
# Update a resource
|
|
54
|
+
client.folders.update("fldr_abc123", UpdateFolder(
|
|
55
|
+
title="Updated Title",
|
|
56
|
+
))
|
|
57
|
+
|
|
58
|
+
# Delete a resource
|
|
59
|
+
client.folders.delete("fldr_abc123")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Async Client
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from vantage import AsyncClient
|
|
66
|
+
|
|
67
|
+
async with AsyncClient("your-api-token") as client:
|
|
68
|
+
folders = await client.folders.list()
|
|
69
|
+
|
|
70
|
+
folder = await client.folders.create(CreateFolder(
|
|
71
|
+
title="Production Costs",
|
|
72
|
+
workspace_token="wrkspc_123",
|
|
73
|
+
))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Error Handling
|
|
77
|
+
|
|
78
|
+
API errors are raised as `VantageAPIError` with structured error information:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from vantage import Client, VantageAPIError
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
client.cost_reports.get("invalid_token")
|
|
85
|
+
except VantageAPIError as e:
|
|
86
|
+
print(e.status) # 404
|
|
87
|
+
print(e.status_text) # "Not Found"
|
|
88
|
+
print(e.errors) # ["Resource not found"] or None
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Development
|
|
92
|
+
|
|
93
|
+
### Building
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
make install
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This fetches the latest OpenAPI schema from the Vantage API and generates Pydantic models, sync client, and async client. Your pip version will need to be up to date for this.
|
|
100
|
+
|
|
101
|
+
### Testing
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pytest
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Publishing
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
make publish
|
|
111
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
vantage/__init__.py,sha256=AxqtGdcmrLPuD-yJwhwBDls-dMHT9JWGuqIcSLnW_2I,1878
|
|
2
|
+
vantage/_base.py,sha256=QOUS-DydVywWggHJeY_scW9c1i0Ft7smr7CVGs6aOCE,2320
|
|
3
|
+
vantage/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
vantage/_async/__init__.py,sha256=AWPpWgtKwQEBaUC4HUfYPBHCk07FpSmRveX9LVbP_iU,99
|
|
5
|
+
vantage/_sync/__init__.py,sha256=xAhyswjC5T4Ixf-JCojiJ7Gd-0qhbuQtqZzXJFf1WbQ,96
|
|
6
|
+
vantage_python-0.1.0.dist-info/METADATA,sha256=sJYp8AuHdk0mcgue8f_TeulX1w1B0s4Y8nBjJaKBvt0,2477
|
|
7
|
+
vantage_python-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
8
|
+
vantage_python-0.1.0.dist-info/licenses/LICENSE,sha256=2kez_4bOCWppfBc8dBA81bTWHoa_bKXKjWhBRSy6oeI,1064
|
|
9
|
+
vantage_python-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vantage
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|