pyspiral 0.6.6__cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.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.
Files changed (102) hide show
  1. pyspiral-0.6.6.dist-info/METADATA +51 -0
  2. pyspiral-0.6.6.dist-info/RECORD +102 -0
  3. pyspiral-0.6.6.dist-info/WHEEL +4 -0
  4. pyspiral-0.6.6.dist-info/entry_points.txt +2 -0
  5. spiral/__init__.py +35 -0
  6. spiral/_lib.abi3.so +0 -0
  7. spiral/adbc.py +411 -0
  8. spiral/api/__init__.py +78 -0
  9. spiral/api/admin.py +15 -0
  10. spiral/api/client.py +164 -0
  11. spiral/api/filesystems.py +134 -0
  12. spiral/api/key_space_indexes.py +23 -0
  13. spiral/api/organizations.py +77 -0
  14. spiral/api/projects.py +219 -0
  15. spiral/api/telemetry.py +19 -0
  16. spiral/api/text_indexes.py +56 -0
  17. spiral/api/types.py +22 -0
  18. spiral/api/workers.py +40 -0
  19. spiral/api/workloads.py +52 -0
  20. spiral/arrow_.py +216 -0
  21. spiral/cli/__init__.py +88 -0
  22. spiral/cli/__main__.py +4 -0
  23. spiral/cli/admin.py +14 -0
  24. spiral/cli/app.py +104 -0
  25. spiral/cli/console.py +95 -0
  26. spiral/cli/fs.py +76 -0
  27. spiral/cli/iceberg.py +97 -0
  28. spiral/cli/key_spaces.py +89 -0
  29. spiral/cli/login.py +24 -0
  30. spiral/cli/orgs.py +89 -0
  31. spiral/cli/printer.py +53 -0
  32. spiral/cli/projects.py +147 -0
  33. spiral/cli/state.py +5 -0
  34. spiral/cli/tables.py +174 -0
  35. spiral/cli/telemetry.py +17 -0
  36. spiral/cli/text.py +115 -0
  37. spiral/cli/types.py +50 -0
  38. spiral/cli/workloads.py +58 -0
  39. spiral/client.py +178 -0
  40. spiral/core/__init__.pyi +0 -0
  41. spiral/core/_tools/__init__.pyi +5 -0
  42. spiral/core/authn/__init__.pyi +27 -0
  43. spiral/core/client/__init__.pyi +237 -0
  44. spiral/core/table/__init__.pyi +101 -0
  45. spiral/core/table/manifests/__init__.pyi +35 -0
  46. spiral/core/table/metastore/__init__.pyi +58 -0
  47. spiral/core/table/spec/__init__.pyi +213 -0
  48. spiral/dataloader.py +285 -0
  49. spiral/dataset.py +255 -0
  50. spiral/datetime_.py +27 -0
  51. spiral/debug/__init__.py +0 -0
  52. spiral/debug/manifests.py +87 -0
  53. spiral/debug/metrics.py +56 -0
  54. spiral/debug/scan.py +266 -0
  55. spiral/expressions/__init__.py +276 -0
  56. spiral/expressions/base.py +157 -0
  57. spiral/expressions/http.py +86 -0
  58. spiral/expressions/io.py +100 -0
  59. spiral/expressions/list_.py +68 -0
  60. spiral/expressions/mp4.py +62 -0
  61. spiral/expressions/png.py +18 -0
  62. spiral/expressions/qoi.py +18 -0
  63. spiral/expressions/refs.py +58 -0
  64. spiral/expressions/str_.py +39 -0
  65. spiral/expressions/struct.py +59 -0
  66. spiral/expressions/text.py +62 -0
  67. spiral/expressions/tiff.py +223 -0
  68. spiral/expressions/udf.py +46 -0
  69. spiral/grpc_.py +32 -0
  70. spiral/iceberg.py +31 -0
  71. spiral/iterable_dataset.py +106 -0
  72. spiral/key_space_index.py +44 -0
  73. spiral/project.py +199 -0
  74. spiral/protogen/_/__init__.py +0 -0
  75. spiral/protogen/_/arrow/__init__.py +0 -0
  76. spiral/protogen/_/arrow/flight/__init__.py +0 -0
  77. spiral/protogen/_/arrow/flight/protocol/__init__.py +0 -0
  78. spiral/protogen/_/arrow/flight/protocol/sql/__init__.py +2548 -0
  79. spiral/protogen/_/google/__init__.py +0 -0
  80. spiral/protogen/_/google/protobuf/__init__.py +2310 -0
  81. spiral/protogen/_/message_pool.py +3 -0
  82. spiral/protogen/_/py.typed +0 -0
  83. spiral/protogen/_/scandal/__init__.py +190 -0
  84. spiral/protogen/_/spfs/__init__.py +72 -0
  85. spiral/protogen/_/spql/__init__.py +61 -0
  86. spiral/protogen/_/substrait/__init__.py +6196 -0
  87. spiral/protogen/_/substrait/extensions/__init__.py +169 -0
  88. spiral/protogen/__init__.py +0 -0
  89. spiral/protogen/util.py +41 -0
  90. spiral/py.typed +0 -0
  91. spiral/scan.py +285 -0
  92. spiral/server.py +17 -0
  93. spiral/settings.py +114 -0
  94. spiral/snapshot.py +56 -0
  95. spiral/streaming_/__init__.py +3 -0
  96. spiral/streaming_/reader.py +133 -0
  97. spiral/streaming_/stream.py +157 -0
  98. spiral/substrait_.py +274 -0
  99. spiral/table.py +293 -0
  100. spiral/text_index.py +17 -0
  101. spiral/transaction.py +58 -0
  102. spiral/types_.py +6 -0
spiral/api/__init__.py ADDED
@@ -0,0 +1,78 @@
1
+ import os
2
+ from typing import TYPE_CHECKING
3
+
4
+ import httpx
5
+
6
+ from .client import _Client
7
+
8
+ if TYPE_CHECKING:
9
+ from spiral.core.client import Authn
10
+
11
+ from .admin import AdminService
12
+ from .filesystems import FileSystemService
13
+ from .key_space_indexes import KeySpaceIndexesService
14
+ from .organizations import OrganizationService
15
+ from .projects import ProjectService
16
+ from .telemetry import TelemetryService
17
+ from .text_indexes import TextIndexesService
18
+ from .workloads import WorkloadService
19
+
20
+
21
+ class SpiralAPI:
22
+ def __init__(self, authn: "Authn", base_url: str | None = None):
23
+ self.base_url = base_url or os.environ.get("SPIRAL_URL", "https://api.spiraldb.com")
24
+ self.client = _Client(
25
+ httpx.Client(
26
+ base_url=self.base_url,
27
+ timeout=None if ("PYTEST_VERSION" in os.environ or bool(os.environ.get("SPIRAL_DEV", None))) else 60,
28
+ ),
29
+ authn,
30
+ )
31
+
32
+ @property
33
+ def _admin(self) -> "AdminService":
34
+ from .admin import AdminService
35
+
36
+ return AdminService(self.client)
37
+
38
+ @property
39
+ def organization(self) -> "OrganizationService":
40
+ from .organizations import OrganizationService
41
+
42
+ return OrganizationService(self.client)
43
+
44
+ @property
45
+ def project(self) -> "ProjectService":
46
+ from .projects import ProjectService
47
+
48
+ return ProjectService(self.client)
49
+
50
+ @property
51
+ def file_system(self) -> "FileSystemService":
52
+ from .filesystems import FileSystemService
53
+
54
+ return FileSystemService(self.client)
55
+
56
+ @property
57
+ def workload(self) -> "WorkloadService":
58
+ from .workloads import WorkloadService
59
+
60
+ return WorkloadService(self.client)
61
+
62
+ @property
63
+ def text_indexes(self) -> "TextIndexesService":
64
+ from .text_indexes import TextIndexesService
65
+
66
+ return TextIndexesService(self.client)
67
+
68
+ @property
69
+ def key_space_indexes(self) -> "KeySpaceIndexesService":
70
+ from .key_space_indexes import KeySpaceIndexesService
71
+
72
+ return KeySpaceIndexesService(self.client)
73
+
74
+ @property
75
+ def telemetry(self) -> "TelemetryService":
76
+ from .telemetry import TelemetryService
77
+
78
+ return TelemetryService(self.client)
spiral/api/admin.py ADDED
@@ -0,0 +1,15 @@
1
+ from .client import Paged, PagedResponse, ServiceBase
2
+ from .organizations import OrgMembership
3
+ from .types import OrgId
4
+
5
+
6
+ class AdminService(ServiceBase):
7
+ def sync_memberships(self, org_id: OrgId | None = None) -> Paged[OrgMembership]:
8
+ params = {}
9
+ if org_id:
10
+ params["org_id"] = str(org_id)
11
+ return self.client.paged("/v1/admin/sync-memberships", PagedResponse[OrgMembership], params=params)
12
+
13
+ def sync_orgs(self) -> Paged[OrgId]:
14
+ params = {}
15
+ return self.client.paged("/v1/admin/sync-orgs", PagedResponse[OrgId], params=params)
spiral/api/client.py ADDED
@@ -0,0 +1,164 @@
1
+ import logging
2
+ from collections.abc import Iterable, Iterator, Mapping
3
+ from typing import Any, TypeVar
4
+
5
+ import httpx
6
+ from httpx import HTTPStatusError
7
+ from pydantic import BaseModel, Field, TypeAdapter
8
+
9
+ from spiral.core.authn import Authn
10
+
11
+ log = logging.getLogger(__name__)
12
+
13
+
14
+ E = TypeVar("E")
15
+
16
+
17
+ class PagedRequest(BaseModel):
18
+ page_token: str | None = None
19
+ page_size: int = 50
20
+
21
+
22
+ class PagedResponse[E](BaseModel):
23
+ items: list[E] = Field(default_factory=list)
24
+ next_page_token: str | None = None
25
+
26
+
27
+ PagedReqT = TypeVar("PagedReqT", bound=PagedRequest)
28
+
29
+
30
+ class Paged[E](Iterable[E]):
31
+ def __init__(
32
+ self,
33
+ client: "_Client",
34
+ path: str,
35
+ page_token: str | None,
36
+ page_size: int,
37
+ response_cls: type[PagedResponse[E]],
38
+ params: Mapping[str, str] | None = None,
39
+ ):
40
+ self._client = client
41
+ self._path = path
42
+ self._response_cls = response_cls
43
+
44
+ self._page_size = page_size
45
+
46
+ self._params = params or {}
47
+ if page_token is not None:
48
+ self._params["page_token"] = str(page_token)
49
+ # TODO(marko): Support paging.
50
+ # if page_size is not None:
51
+ # self._params["page_size"] = str(page_size)
52
+
53
+ self._response: PagedResponse[E] = client.get(path, response_cls, params=self._params)
54
+
55
+ @property
56
+ def page(self) -> PagedResponse[E]:
57
+ return self._response
58
+
59
+ def __iter__(self) -> Iterator[E]:
60
+ while True:
61
+ yield from self._response.items
62
+
63
+ if self._response.next_page_token is None:
64
+ break
65
+
66
+ params = self._params.copy()
67
+ params["page_token"] = self._response.next_page_token
68
+ self._response = self._client.get(self._path, self._response_cls, params=params)
69
+
70
+
71
+ class ServiceBase:
72
+ def __init__(self, client: "_Client"):
73
+ self.client = client
74
+
75
+
76
+ class SpiralHTTPError(Exception):
77
+ def __init__(self, body: str, code: int):
78
+ super().__init__(body)
79
+ self.body = body
80
+ self.code = code
81
+
82
+
83
+ class _Client:
84
+ RequestT = TypeVar("RequestT")
85
+ ResponseT = TypeVar("ResponseT")
86
+
87
+ def __init__(self, http: httpx.Client, authn: Authn):
88
+ self.http = http
89
+ self.authn = authn
90
+
91
+ def get(
92
+ self, path: str, response_cls: type[ResponseT], *, params: Mapping[str, str | list[str]] | None = None
93
+ ) -> ResponseT:
94
+ return self.request("GET", path, None, response_cls, params=params)
95
+
96
+ def post(
97
+ self,
98
+ path: str,
99
+ req: RequestT,
100
+ response_cls: type[ResponseT],
101
+ *,
102
+ params: Mapping[str, str | list[str]] | None = None,
103
+ ) -> ResponseT:
104
+ return self.request("POST", path, req, response_cls, params=params)
105
+
106
+ def put(
107
+ self,
108
+ path: str,
109
+ req: RequestT,
110
+ response_cls: type[ResponseT],
111
+ *,
112
+ params: Mapping[str, str | list[str]] | None = None,
113
+ ) -> ResponseT:
114
+ return self.request("PUT", path, req, response_cls, params=params)
115
+
116
+ def delete(
117
+ self, path: str, response_cls: type[ResponseT], *, params: Mapping[str, str | list[str]] | None = None
118
+ ) -> ResponseT:
119
+ return self.request("DELETE", path, None, response_cls, params=params)
120
+
121
+ def request(
122
+ self,
123
+ method: str,
124
+ path: str,
125
+ req: RequestT | None,
126
+ response_cls: type[ResponseT],
127
+ *,
128
+ params: Mapping[str, str | list[str]] | None = None,
129
+ ) -> ResponseT:
130
+ req_data: dict[str, Any] = {}
131
+ if req is not None:
132
+ req_data = dict(json=TypeAdapter(req.__class__).dump_python(req, mode="json", exclude_none=True))
133
+
134
+ token = self.authn.token()
135
+ resp = self.http.request(
136
+ method,
137
+ path,
138
+ params=params or {},
139
+ headers={"authorization": f"Bearer {token.expose_secret()}"} if token else None,
140
+ **req_data,
141
+ )
142
+
143
+ try:
144
+ resp.raise_for_status()
145
+ except HTTPStatusError as e:
146
+ # Enrich the exception with the response body
147
+ raise SpiralHTTPError(body=resp.text, code=resp.status_code) from e
148
+
149
+ if response_cls == type[None]:
150
+ assert resp.text == ""
151
+ return None
152
+
153
+ return TypeAdapter(response_cls).validate_python(resp.json())
154
+
155
+ def paged(
156
+ self,
157
+ path: str,
158
+ response_cls: type[PagedResponse[E]],
159
+ *,
160
+ page_token: str | None = None,
161
+ page_size: int = 50,
162
+ params: Mapping[str, str] | None = None,
163
+ ) -> Paged[E]:
164
+ return Paged(self, path, page_token, page_size, response_cls, params)
@@ -0,0 +1,134 @@
1
+ from enum import Enum
2
+ from types import NoneType
3
+ from typing import Annotated, Literal
4
+
5
+ from pydantic import AfterValidator, BaseModel, Field
6
+
7
+ from .client import Paged, PagedResponse, ServiceBase
8
+ from .types import ProjectId
9
+
10
+
11
+ def _validate_directory_path(path: str) -> str:
12
+ if not path.startswith("/"):
13
+ raise ValueError("Directory path must start with a slash.")
14
+ if not path.endswith("/"):
15
+ raise ValueError("Directory path must not end with a slash.")
16
+ return path
17
+
18
+
19
+ DirectoryPath = Annotated[str, AfterValidator(_validate_directory_path)]
20
+ FilePath = str # Path or directory
21
+ FsLoc = str
22
+
23
+
24
+ class BuiltinFileSystem(BaseModel):
25
+ """Spiral supports several builtin file systems in different cloud provider regions."""
26
+
27
+ type: Literal["builtin"] = "builtin"
28
+ provider: str
29
+
30
+
31
+ class UpstreamFileSystem(BaseModel):
32
+ """File system that points to another project, usually a "file system" project.
33
+
34
+ Upstream project must have an external file system configured,
35
+ and not a builtin file system or another upstream file system.
36
+ """
37
+
38
+ type: Literal["upstream"] = "upstream"
39
+ project_id: ProjectId
40
+
41
+
42
+ class S3FileSystem(BaseModel):
43
+ """File system backed by an S3-compatible bucket."""
44
+
45
+ type: Literal["s3"] = "s3"
46
+ endpoint: str | None = None
47
+ region: str
48
+ bucket: str
49
+ directory: DirectoryPath | None = None
50
+ # ARN of the role to assume when accessing the bucket https://docs.spiraldb.com/filesystems#aws
51
+ # role_arn: str | None = None
52
+ role_arn: str # TODO(marko): Make optional once we support third-party S3-compatible storage.
53
+
54
+
55
+ class GCSFileSystem(BaseModel):
56
+ """File system backed by a Google Cloud Storage bucket."""
57
+
58
+ type: Literal["gcs"] = "gcs"
59
+ region: str
60
+ bucket: str
61
+ directory: DirectoryPath | None = None
62
+
63
+
64
+ FileSystem = Annotated[
65
+ BuiltinFileSystem | UpstreamFileSystem | S3FileSystem | GCSFileSystem, Field(discriminator="type")
66
+ ]
67
+
68
+
69
+ class Mode(str, Enum):
70
+ READ_ONLY = "ro"
71
+ READ_WRITE = "rw"
72
+
73
+
74
+ class Mount(BaseModel):
75
+ """Mount grants permission to a Spiral resource to use a specific directory within the file system."""
76
+
77
+ id: str
78
+ project_id: ProjectId
79
+ directory: DirectoryPath
80
+ mode: Mode
81
+ principal: str
82
+
83
+
84
+ class CreateMountRequest(BaseModel):
85
+ directory: DirectoryPath
86
+ mode: Mode
87
+ principal: str
88
+
89
+
90
+ class CreateMountResponse(BaseModel):
91
+ mount: Mount
92
+
93
+
94
+ class GetMountAndFileSystemResponse(BaseModel):
95
+ mount: Mount
96
+ file_system: FileSystem
97
+ fs_loc: FsLoc
98
+
99
+
100
+ class FileSystemService(ServiceBase):
101
+ """Service for file system operations."""
102
+
103
+ def list_providers(self) -> list[str]:
104
+ """List builtin providers."""
105
+ response = self.client.get("/v1/file-systems/builtin-providers", dict)
106
+ return response.get("providers", [])
107
+
108
+ def update_file_system(self, project_id: ProjectId, request: FileSystem) -> FileSystem:
109
+ """Update project's default file system."""
110
+ return self.client.post(f"/v1/file-systems/{project_id}", request, FileSystem)
111
+
112
+ def get_file_system(self, project_id: ProjectId) -> FileSystem:
113
+ """Get project's default file system."""
114
+ return self.client.get(f"/v1/file-systems/{project_id}", FileSystem)
115
+
116
+ def create_mount(self, project_id: ProjectId, request: CreateMountRequest) -> CreateMountResponse:
117
+ """Create a mount."""
118
+ return self.client.post(f"/v1/file-systems/{project_id}/mounts", request, CreateMountResponse)
119
+
120
+ def list_mounts(self, project_id: ProjectId) -> Paged[Mount]:
121
+ """List active mounts in project's file system."""
122
+ return self.client.paged(f"/v1/file-systems/{project_id}/mounts", PagedResponse[Mount])
123
+
124
+ def get_mount(self, mount_id: str) -> Mount:
125
+ """Get a mount."""
126
+ return self.client.get(f"/v1/mounts/{mount_id}", Mount)
127
+
128
+ def get_mount_and_file_system(self, mount_id: str) -> GetMountAndFileSystemResponse:
129
+ """Get the mount and its associated file system."""
130
+ return self.client.get(f"/v1/mounts/{mount_id}/with-filesystem", GetMountAndFileSystemResponse)
131
+
132
+ def remove_mount(self, mount_id: str) -> None:
133
+ """Remove mount."""
134
+ return self.client.delete(f"/v1/mounts/{mount_id}", NoneType)
@@ -0,0 +1,23 @@
1
+ from pydantic import BaseModel
2
+
3
+ from .client import ServiceBase
4
+ from .types import IndexId, WorkerId
5
+ from .workers import ResourceClass
6
+
7
+
8
+ class SyncIndexRequest(BaseModel):
9
+ """Request to sync a text index."""
10
+
11
+ resources: ResourceClass
12
+
13
+
14
+ class SyncIndexResponse(BaseModel):
15
+ worker_id: WorkerId
16
+
17
+
18
+ class KeySpaceIndexesService(ServiceBase):
19
+ """Service for key space index operations."""
20
+
21
+ def sync_index(self, index_id: IndexId, request: SyncIndexRequest) -> SyncIndexResponse:
22
+ """Start a job to sync an index."""
23
+ return self.client.post(f"/v1/key-space-indexes/{index_id}/sync", request, SyncIndexResponse)
@@ -0,0 +1,77 @@
1
+ from enum import Enum
2
+
3
+ from pydantic import BaseModel
4
+
5
+ from .client import Paged, PagedResponse, ServiceBase
6
+ from .types import OrgId
7
+
8
+
9
+ class OrgRole(str, Enum):
10
+ OWNER = "owner"
11
+ MEMBER = "member"
12
+ GUEST = "guest"
13
+
14
+
15
+ class Org(BaseModel):
16
+ id: OrgId
17
+ name: str | None = None
18
+
19
+
20
+ class OrgMembership(BaseModel):
21
+ user_id: str
22
+ org: Org
23
+ role: str
24
+
25
+
26
+ class CreateOrgRequest(BaseModel):
27
+ name: str | None = None
28
+
29
+
30
+ class CreateOrgResponse(BaseModel):
31
+ org: Org
32
+
33
+
34
+ class PortalLinkIntent(str, Enum):
35
+ SSO = "sso"
36
+ DIRECTORY_SYNC = "directory-sync"
37
+ AUDIT_LOGS = "audit-logs"
38
+ LOG_STREAMS = "log-streams"
39
+ DOMAIN_VERIFICATION = "domain-verification"
40
+
41
+
42
+ class PortalLinkRequest(BaseModel):
43
+ intent: PortalLinkIntent
44
+
45
+
46
+ class PortalLinkResponse(BaseModel):
47
+ url: str
48
+
49
+
50
+ class InviteUserRequest(BaseModel):
51
+ email: str
52
+ role: OrgRole
53
+ expires_in_days: int | None = 7
54
+
55
+
56
+ class InviteUserResponse(BaseModel):
57
+ invite_id: str
58
+
59
+
60
+ class OrganizationService(ServiceBase):
61
+ """Service for organization operations."""
62
+
63
+ def create(self, request: CreateOrgRequest) -> CreateOrgResponse:
64
+ """Create a new organization."""
65
+ return self.client.post("/v1/organizations", request, CreateOrgResponse)
66
+
67
+ def list_memberships(self) -> Paged[OrgMembership]:
68
+ """List organization memberships."""
69
+ return self.client.paged("/v1/organizations", PagedResponse[OrgMembership])
70
+
71
+ def invite_user(self, request: InviteUserRequest) -> InviteUserResponse:
72
+ """Invite a user to the organization."""
73
+ return self.client.post("/v1/organizations/invite-user", request, InviteUserResponse)
74
+
75
+ def portal_link(self, request: PortalLinkRequest) -> PortalLinkResponse:
76
+ """Get configuration portal link for the organization."""
77
+ return self.client.put("/v1/organizations/portal-link", request, PortalLinkResponse)