edgebase-core 0.1.3__tar.gz

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,11 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .eggs/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ *.egg
11
+ .venv/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 melodysdreamj
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.
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.4
2
+ Name: edgebase-core
3
+ Version: 0.1.3
4
+ Summary: Shared Python core for EdgeBase table, storage, and HTTP primitives
5
+ Author: EdgeBase Team
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.10
9
+ Requires-Dist: httpx>=0.27
10
+ Description-Content-Type: text/markdown
11
+
12
+ # edgebase-core
13
+
14
+ Shared low-level Python primitives for EdgeBase.
15
+
16
+ `edgebase-core` is the foundation used by `edgebase` and `edgebase-admin`. It contains the HTTP client, table/query builder, storage helpers, push primitives, field operations, and common error types.
17
+
18
+ Most application code should install one of these instead:
19
+
20
+ - `pip install edgebase`
21
+ - `pip install edgebase-admin`
22
+
23
+ Install `edgebase-core` directly only if you are building custom wrappers, generated bindings, or internal integrations on top of the EdgeBase APIs.
24
+
25
+ ## Docs
26
+
27
+ - SDK overview: https://edgebase.fun/docs/sdks
28
+ - Database admin SDK: https://edgebase.fun/docs/database/admin-sdk
29
+ - Storage docs: https://edgebase.fun/docs/storage/upload-download
30
+
31
+ ## Quick Start
32
+
33
+ ```python
34
+ from edgebase_core import HttpClient, StorageClient, TableRef
35
+
36
+ http = HttpClient(
37
+ "https://your-project.edgebase.fun",
38
+ service_key="service-key",
39
+ )
40
+
41
+ posts = (
42
+ TableRef(http, "shared", None, "posts")
43
+ .where("published", "==", True)
44
+ .order_by("createdAt", "desc")
45
+ .limit(20)
46
+ .get_list()
47
+ )
48
+
49
+ bucket = StorageClient(http).bucket("avatars")
50
+ ```
51
+
52
+ ## Included Surfaces
53
+
54
+ - `HttpClient`
55
+ - `TableRef`, `DocRef`, `ListResult`
56
+ - `StorageClient`, `StorageBucket`
57
+ - `PushClient`
58
+ - `FieldOps`, `increment`, `delete_field`
59
+ - `ContextManager`
60
+ - `EdgeBaseError`
61
+
62
+ ## AI Assistant
63
+
64
+ - Package guide: `packages/sdk/python/packages/core/README.md`
65
+ - Assistant reference: `packages/sdk/python/packages/core/llms.txt`
66
+
67
+ ## Requirements
68
+
69
+ - Python `3.10+`
70
+ - `httpx>=0.27`
@@ -0,0 +1,59 @@
1
+ # edgebase-core
2
+
3
+ Shared low-level Python primitives for EdgeBase.
4
+
5
+ `edgebase-core` is the foundation used by `edgebase` and `edgebase-admin`. It contains the HTTP client, table/query builder, storage helpers, push primitives, field operations, and common error types.
6
+
7
+ Most application code should install one of these instead:
8
+
9
+ - `pip install edgebase`
10
+ - `pip install edgebase-admin`
11
+
12
+ Install `edgebase-core` directly only if you are building custom wrappers, generated bindings, or internal integrations on top of the EdgeBase APIs.
13
+
14
+ ## Docs
15
+
16
+ - SDK overview: https://edgebase.fun/docs/sdks
17
+ - Database admin SDK: https://edgebase.fun/docs/database/admin-sdk
18
+ - Storage docs: https://edgebase.fun/docs/storage/upload-download
19
+
20
+ ## Quick Start
21
+
22
+ ```python
23
+ from edgebase_core import HttpClient, StorageClient, TableRef
24
+
25
+ http = HttpClient(
26
+ "https://your-project.edgebase.fun",
27
+ service_key="service-key",
28
+ )
29
+
30
+ posts = (
31
+ TableRef(http, "shared", None, "posts")
32
+ .where("published", "==", True)
33
+ .order_by("createdAt", "desc")
34
+ .limit(20)
35
+ .get_list()
36
+ )
37
+
38
+ bucket = StorageClient(http).bucket("avatars")
39
+ ```
40
+
41
+ ## Included Surfaces
42
+
43
+ - `HttpClient`
44
+ - `TableRef`, `DocRef`, `ListResult`
45
+ - `StorageClient`, `StorageBucket`
46
+ - `PushClient`
47
+ - `FieldOps`, `increment`, `delete_field`
48
+ - `ContextManager`
49
+ - `EdgeBaseError`
50
+
51
+ ## AI Assistant
52
+
53
+ - Package guide: `packages/sdk/python/packages/core/README.md`
54
+ - Assistant reference: `packages/sdk/python/packages/core/llms.txt`
55
+
56
+ ## Requirements
57
+
58
+ - Python `3.10+`
59
+ - `httpx>=0.27`
@@ -0,0 +1,86 @@
1
+ # edgebase-core
2
+
3
+ Use this file as a quick-reference contract for AI coding assistants working with the `edgebase-core` Python package.
4
+
5
+ ## Package Boundary
6
+
7
+ Use `edgebase-core` for low-level EdgeBase building blocks.
8
+
9
+ This package is shared infrastructure for `edgebase` and `edgebase-admin`. Most app code should install one of those higher-level packages instead of using `edgebase-core` directly.
10
+
11
+ `edgebase-core` does not provide a top-level server client, auth convenience helpers, or package-level factories like `create_admin_client(...)`.
12
+
13
+ ## Source Of Truth
14
+
15
+ - Package README: https://github.com/edge-base/edgebase/blob/main/packages/sdk/python/packages/core/README.md
16
+ - SDK overview: https://edgebase.fun/docs/sdks
17
+ - Database admin SDK: https://edgebase.fun/docs/database/admin-sdk
18
+ - Storage docs: https://edgebase.fun/docs/storage/upload-download
19
+
20
+ If docs, snippets, and assumptions disagree, prefer the current package API over guessed patterns from another runtime.
21
+
22
+ ## Canonical Examples
23
+
24
+ ### Build a table reference from a custom HTTP client
25
+
26
+ ```python
27
+ from edgebase_core import HttpClient, TableRef
28
+
29
+ http = HttpClient(
30
+ "https://your-project.edgebase.fun",
31
+ service_key="service-key",
32
+ )
33
+
34
+ posts = TableRef(http, "shared", None, "posts").where("published", "==", True).get_list()
35
+ ```
36
+
37
+ ### Use document helpers
38
+
39
+ ```python
40
+ table = TableRef(http, "shared", None, "posts")
41
+ post = table.doc("post-1").get()
42
+ ```
43
+
44
+ ### Work with storage directly
45
+
46
+ ```python
47
+ from edgebase_core import StorageClient
48
+
49
+ storage = StorageClient(http)
50
+ bucket = storage.bucket("avatars")
51
+ bucket.upload("user-1.jpg", file_bytes, content_type="image/jpeg")
52
+ ```
53
+
54
+ ## Common Mistakes
55
+
56
+ - do not expect a top-level `EdgeBaseServer` or `AdminClient` here; those live in higher-level packages
57
+ - `TableRef(http, namespace, instance_id, table_name)` requires the low-level HTTP client as its first argument
58
+ - `table.get()` returns a `ListResult`, not a single record
59
+ - use `table.get_one(id)` or `table.doc(id).get()` for a single record
60
+ - `StorageClient` requires an initialized `HttpClient`
61
+ - `PushClient` exists in this package, but most applications should access push through `edgebase-admin` or `edgebase`
62
+ - `increment` and `delete_field` are aliases from `FieldOps`
63
+
64
+ ## Quick Reference
65
+
66
+ ```python
67
+ http = HttpClient(base_url, service_key=service_key)
68
+
69
+ table = TableRef(http, "shared", None, "posts")
70
+ table.where("published", "==", True).order_by("createdAt", "desc").limit(20).get_list()
71
+ table.get_one("id-1")
72
+ table.insert({"title": "Hello"})
73
+ table.update("id-1", {"title": "Updated"})
74
+ table.delete("id-1")
75
+
76
+ doc = DocRef(http, "shared", None, "posts", "id-1")
77
+ doc.get()
78
+
79
+ storage = StorageClient(http)
80
+ bucket = storage.bucket("avatars")
81
+ bucket.upload("user-1.jpg", file_bytes, content_type="image/jpeg")
82
+ bucket.create_signed_upload_url("large.zip", expires_in=600)
83
+
84
+ increment(1)
85
+ delete_field()
86
+ ```
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "edgebase-core"
7
+ version = "0.1.3"
8
+ description = "Shared Python core for EdgeBase table, storage, and HTTP primitives"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "EdgeBase Team" }
14
+ ]
15
+ dependencies = ["httpx>=0.27"]
16
+
17
+ [tool.hatch.build.targets.sdist]
18
+ include = ["src/edgebase_core", "README.md", "llms.txt"]
19
+
20
+ [tool.hatch.build.targets.wheel]
21
+ packages = ["src/edgebase_core"]
22
+
23
+ [tool.hatch.build.targets.wheel.force-include]
24
+ "llms.txt" = "edgebase_core/llms.txt"
@@ -0,0 +1,13 @@
1
+ """EdgeBase Core SDK — shared types, HTTP client, table, storage."""
2
+
3
+ from edgebase_core.http_client import HttpClient
4
+ from edgebase_core.table import TableRef, DocRef, ListResult
5
+ from edgebase_core.storage import StorageClient, StorageBucket
6
+ from edgebase_core.field_ops import FieldOps
7
+ from edgebase_core.context_manager import ContextManager
8
+ from edgebase_core.errors import EdgeBaseError
9
+ from edgebase_core.push import PushClient
10
+
11
+ # Convenience aliases
12
+ increment = FieldOps.increment
13
+ delete_field = FieldOps.delete_field
@@ -0,0 +1,27 @@
1
+ """Context manager for legacy isolateBy compatibility state.
2
+
3
+ : auth.id isolation uses JWT extraction server-side.
4
+ The 'auth.id' key is silently filtered from context to prevent
5
+ client-side override attempts.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+
12
+
13
+ class ContextManager:
14
+ """Thread-safe context storage retained for compatibility helpers."""
15
+
16
+ def __init__(self) -> None:
17
+ self._context: dict[str, Any] = {}
18
+
19
+ def set_context(self, context: dict[str, Any]) -> None:
20
+ # Filter out auth.id — server extracts from JWT only
21
+ self._context = {k: v for k, v in context.items() if k != "auth.id"}
22
+
23
+ def get_context(self) -> dict[str, Any]:
24
+ return dict(self._context)
25
+
26
+ def clear_context(self) -> None:
27
+ self._context = {}
@@ -0,0 +1,40 @@
1
+ """EdgeBase error types."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from typing import Any
7
+
8
+
9
+ @dataclass
10
+ class EdgeBaseError(Exception):
11
+ """Base error for all EdgeBase API errors."""
12
+
13
+ status_code: int
14
+ message: str
15
+ details: dict[str, list[str]] | None = field(default=None)
16
+
17
+ def __str__(self) -> str:
18
+ parts = [f"EdgeBaseError({self.status_code}): {self.message}"]
19
+ if self.details:
20
+ for k, v in self.details.items():
21
+ rendered = ", ".join(str(item) for item in v) if isinstance(v, list) else str(v)
22
+ parts.append(f" {k}: {rendered}")
23
+ return "\n".join(parts)
24
+
25
+ @classmethod
26
+ def from_json(cls, data: dict[str, Any], status_code: int) -> EdgeBaseError:
27
+ """Create from API JSON response."""
28
+ return cls(
29
+ status_code=status_code,
30
+ message=data.get("message", "Unknown error"),
31
+ details=data.get("details"),
32
+ )
33
+
34
+
35
+ @dataclass
36
+ class EdgeBaseAuthError(EdgeBaseError):
37
+ """Authentication-specific error."""
38
+
39
+ def __str__(self) -> str:
40
+ return f"EdgeBaseAuthError({self.status_code}): {self.message}"
@@ -0,0 +1,51 @@
1
+ """Field operation helpers for atomic updates."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+
8
+ class FieldOps:
9
+ """Atomic field operation markers ($op pattern — mirrors JS SDK, server op-parser.ts)."""
10
+
11
+ @staticmethod
12
+ def increment(value: int | float = 1) -> dict[str, Any]:
13
+ """Increment a numeric field atomically.
14
+
15
+ Usage::
16
+
17
+ doc_ref.update({"views": FieldOps.increment(1)})
18
+ doc_ref.update({"score": FieldOps.increment(-5)})
19
+ """
20
+ return {"$op": "increment", "value": value}
21
+
22
+ @staticmethod
23
+ def delete_field() -> dict[str, str]:
24
+ """Delete a field from a document.
25
+
26
+ Usage::
27
+
28
+ doc_ref.update({"oldField": FieldOps.delete_field()})
29
+ """
30
+ return {"$op": "deleteField"}
31
+
32
+
33
+ # Standalone module-level functions — enable `from edgebase_core.field_ops import increment, delete_field`
34
+ def increment(value: int | float = 1) -> dict[str, Any]:
35
+ """Increment a numeric field atomically. See :meth:`FieldOps.increment`."""
36
+ return FieldOps.increment(value)
37
+
38
+
39
+ def delete_field() -> dict[str, str]:
40
+ """Delete a field from a document. See :meth:`FieldOps.delete_field`."""
41
+ return FieldOps.delete_field()
42
+
43
+
44
+ def serialize_field_ops(data: dict[str, Any]) -> dict[str, Any]:
45
+ """Pass through data dict, preserving field-op markers as-is.
46
+
47
+ Field ops (``increment()``, ``delete_field()``) already produce the
48
+ ``{"$op": ...}`` dict that the server expects, so this function simply
49
+ returns a shallow copy.
50
+ """
51
+ return {k: v for k, v in data.items()}