Skip to content

Commit 2eecc8b

Browse files
authored
Feature/metadata (#4)
* feat(src/resources/metadata): implement metadata endpoints * bump: version 0.2.3 → 0.3.0 --------- Co-authored-by: JD <>
1 parent f7ab327 commit 2eecc8b

File tree

10 files changed

+167
-2
lines changed

10 files changed

+167
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v0.3.0 (2025-07-22)
2+
3+
### Feat
4+
5+
- **src/resources/metadata**: implement metadata endpoints
6+
17
## v0.2.3 (2025-07-21)
28

39
### Fix

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Jan-David Wiederstein
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.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import asyncio
2+
import pprint
3+
from codesphere import CodesphereSDK
4+
5+
6+
async def main():
7+
"""Fetches datacenters."""
8+
async with CodesphereSDK() as sdk:
9+
datacenters = await sdk.metadata.datacenters()
10+
11+
for datacenter in datacenters:
12+
pprint.pprint(datacenter.name)
13+
pprint.pprint(datacenter.city)
14+
pprint.pprint(datacenter.countryCode)
15+
pprint.pprint(datacenter.id)
16+
17+
if __name__ == "__main__":
18+
asyncio.run(main())
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import asyncio
2+
import pprint
3+
from codesphere import CodesphereSDK
4+
5+
6+
async def main():
7+
"""Fetches base images."""
8+
async with CodesphereSDK() as sdk:
9+
images = await sdk.metadata.images()
10+
11+
for image in images:
12+
pprint.pprint(image.id)
13+
pprint.pprint(image.name)
14+
pprint.pprint(image.supportedUntil)
15+
16+
if __name__ == "__main__":
17+
asyncio.run(main())
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import asyncio
2+
import pprint
3+
from codesphere import CodesphereSDK
4+
5+
6+
async def main():
7+
"""Fetches workspace plans."""
8+
async with CodesphereSDK() as sdk:
9+
plans = await sdk.metadata.plans()
10+
11+
for plan in plans:
12+
pprint.pprint(plan.id)
13+
pprint.pprint(plan.title)
14+
pprint.pprint(plan.priceUsd)
15+
pprint.pprint(plan.deprecated)
16+
pprint.pprint(plan.characteristics.id)
17+
pprint.pprint(plan.characteristics.CPU)
18+
pprint.pprint(plan.characteristics.GPU)
19+
pprint.pprint(plan.characteristics.RAM)
20+
pprint.pprint(plan.characteristics.SSD)
21+
pprint.pprint(plan.characteristics.TempStorage)
22+
pprint.pprint(plan.characteristics.onDemand)
23+
pprint.pprint(plan.maxReplicas)
24+
25+
if __name__ == "__main__":
26+
asyncio.run(main())

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "codesphere"
33

4-
version = "0.2.3"
4+
version = "0.3.0"
55
description = "Use Codesphere within python scripts."
66
readme = "README.md"
77
license = { file="LICENSE" }

src/codesphere/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .client import APIHttpClient
33
from .resources.team.resources import TeamsResource
44
from .resources.workspace.resources import WorkspacesResource
5+
from .resources.metadata.resources import MetadataResource
56
from .resources.workspace.models import (
67
Workspace,
78
WorkspaceCreate,
@@ -22,6 +23,7 @@ async def __aenter__(self):
2223

2324
self.teams = TeamsResource(self._http_client)
2425
self.workspaces = WorkspacesResource(self._http_client)
26+
self.metadata = MetadataResource(self._http_client)
2527
return self
2628

2729
async def __aexit__(self, exc_type, exc_val, exc_tb):
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from __future__ import annotations
2+
from pydantic import BaseModel
3+
import datetime
4+
from typing import TYPE_CHECKING
5+
6+
if TYPE_CHECKING:
7+
pass
8+
9+
10+
class Datacenters(BaseModel):
11+
"""Defines the request body for creating a team."""
12+
13+
id: int
14+
name: str
15+
city: str
16+
countryCode: str
17+
18+
19+
class Characteristics(BaseModel):
20+
"""Defines the hardware and service characteristics of a workspace plan."""
21+
22+
id: int
23+
CPU: float
24+
GPU: int
25+
RAM: int
26+
SSD: int
27+
TempStorage: int
28+
onDemand: bool
29+
30+
31+
class WsPlans(BaseModel):
32+
"""Contains all fields that appear in a workspace-plans response."""
33+
34+
id: int
35+
priceUsd: int
36+
title: str
37+
deprecated: bool
38+
characteristics: Characteristics
39+
maxReplicas: int
40+
41+
42+
class Images(BaseModel):
43+
"""Represents a team as it appears in the list response."""
44+
45+
id: str
46+
name: str
47+
supportedUntil: datetime.datetime
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from typing import List
2+
from ..base import ResourceBase, APIOperation
3+
from .models import Datacenters, WsPlans, Images
4+
5+
6+
class MetadataResource(ResourceBase):
7+
"""Contains all API operations for team ressources."""
8+
9+
datacenters = APIOperation(
10+
method="GET",
11+
endpoint_template="/metadata/datacenters",
12+
input_model=None,
13+
response_model=List[Datacenters],
14+
)
15+
16+
plans = APIOperation(
17+
method="GET",
18+
endpoint_template="/metadata/workspace-plans",
19+
input_model=None,
20+
response_model=List[WsPlans],
21+
)
22+
23+
images = APIOperation(
24+
method="GET",
25+
endpoint_template="/metadata/workspace-base-images",
26+
input_model=None,
27+
response_model=List[Images],
28+
)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)