Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v0.3.0 (2025-07-22)

### Feat

- **src/resources/metadata**: implement metadata endpoints

## v0.2.3 (2025-07-21)

### Fix
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Jan-David Wiederstein

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions examples/metadata/get_datacenters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import asyncio
import pprint
from codesphere import CodesphereSDK


async def main():
"""Fetches datacenters."""
async with CodesphereSDK() as sdk:
datacenters = await sdk.metadata.datacenters()

for datacenter in datacenters:
pprint.pprint(datacenter.name)
pprint.pprint(datacenter.city)
pprint.pprint(datacenter.countryCode)
pprint.pprint(datacenter.id)

if __name__ == "__main__":
asyncio.run(main())
17 changes: 17 additions & 0 deletions examples/metadata/get_workspace_base_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import asyncio
import pprint
from codesphere import CodesphereSDK


async def main():
"""Fetches base images."""
async with CodesphereSDK() as sdk:
images = await sdk.metadata.images()

for image in images:
pprint.pprint(image.id)
pprint.pprint(image.name)
pprint.pprint(image.supportedUntil)

if __name__ == "__main__":
asyncio.run(main())
26 changes: 26 additions & 0 deletions examples/metadata/get_workspace_plans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import asyncio
import pprint
from codesphere import CodesphereSDK


async def main():
"""Fetches workspace plans."""
async with CodesphereSDK() as sdk:
plans = await sdk.metadata.plans()

for plan in plans:
pprint.pprint(plan.id)
pprint.pprint(plan.title)
pprint.pprint(plan.priceUsd)
pprint.pprint(plan.deprecated)
pprint.pprint(plan.characteristics.id)
pprint.pprint(plan.characteristics.CPU)
pprint.pprint(plan.characteristics.GPU)
pprint.pprint(plan.characteristics.RAM)
pprint.pprint(plan.characteristics.SSD)
pprint.pprint(plan.characteristics.TempStorage)
pprint.pprint(plan.characteristics.onDemand)
pprint.pprint(plan.maxReplicas)

if __name__ == "__main__":
asyncio.run(main())
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "codesphere"

version = "0.2.3"
version = "0.3.0"
description = "Use Codesphere within python scripts."
readme = "README.md"
license = { file="LICENSE" }
Expand Down
2 changes: 2 additions & 0 deletions src/codesphere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .client import APIHttpClient
from .resources.team.resources import TeamsResource
from .resources.workspace.resources import WorkspacesResource
from .resources.metadata.resources import MetadataResource
from .resources.workspace.models import (
Workspace,
WorkspaceCreate,
Expand All @@ -22,6 +23,7 @@ async def __aenter__(self):

self.teams = TeamsResource(self._http_client)
self.workspaces = WorkspacesResource(self._http_client)
self.metadata = MetadataResource(self._http_client)
return self

async def __aexit__(self, exc_type, exc_val, exc_tb):
Expand Down
47 changes: 47 additions & 0 deletions src/codesphere/resources/metadata/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from __future__ import annotations
from pydantic import BaseModel
import datetime
from typing import TYPE_CHECKING

if TYPE_CHECKING:
pass


class Datacenters(BaseModel):
"""Defines the request body for creating a team."""

id: int
name: str
city: str
countryCode: str


class Characteristics(BaseModel):
"""Defines the hardware and service characteristics of a workspace plan."""

id: int
CPU: float
GPU: int
RAM: int
SSD: int
TempStorage: int
onDemand: bool


class WsPlans(BaseModel):
"""Contains all fields that appear in a workspace-plans response."""

id: int
priceUsd: int
title: str
deprecated: bool
characteristics: Characteristics
maxReplicas: int


class Images(BaseModel):
"""Represents a team as it appears in the list response."""

id: str
name: str
supportedUntil: datetime.datetime
28 changes: 28 additions & 0 deletions src/codesphere/resources/metadata/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import List
from ..base import ResourceBase, APIOperation
from .models import Datacenters, WsPlans, Images


class MetadataResource(ResourceBase):
"""Contains all API operations for team ressources."""

datacenters = APIOperation(
method="GET",
endpoint_template="/metadata/datacenters",
input_model=None,
response_model=List[Datacenters],
)

plans = APIOperation(
method="GET",
endpoint_template="/metadata/workspace-plans",
input_model=None,
response_model=List[WsPlans],
)

images = APIOperation(
method="GET",
endpoint_template="/metadata/workspace-base-images",
input_model=None,
response_model=List[Images],
)
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.