Skip to content

Rename Base -> Collection #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ruff: noqa: T201
from contiguity import Base
from contiguity import Collection

# Create a Base instance.
db = Base("my-base")
# Create a Collection instance.
db = Collection("my-collection")

# Put an item with a specific key.
put_result = db.put({"key": "foo", "value": "Hello world!"})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ruff: noqa: T201
from pydantic import BaseModel

from contiguity import Base
from contiguity import Collection


# Create a Pydantic model for the item.
Expand All @@ -12,9 +12,9 @@ class MyItem(BaseModel):
interests: list[str] = []


# Create a Base instance.
# Create a Collection instance.
# Static type checking will work with the Pydantic model.
db = Base("members", item_type=MyItem)
db = Collection("members", item_type=MyItem)

# Put an item with a specific key.
put_result = db.put(
Expand Down
15 changes: 13 additions & 2 deletions src/contiguity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from ._client import ApiClient
from .analytics import EmailAnalytics
from .base import AsyncBase, Base, BaseItem, InvalidKeyError, ItemConflictError, ItemNotFoundError, QueryResponse
from .collections import (
AsyncCollection,
BaseItem,
Collection,
InvalidKeyError,
ItemConflictError,
ItemNotFoundError,
QueryResponse,
)
from .collections.compatibility import AsyncBase, Base
from .otp import OTP
from .quota import Quota
from .send import Send
Expand Down Expand Up @@ -48,14 +57,16 @@ def login(token: str, /, *, debug: bool = False) -> Contiguity:

__all__ = (
"AsyncBase",
"AsyncCollection",
"Base",
"Contiguity",
"Send",
"Verify",
"EmailAnalytics",
"Quota",
"OTP",
"Template",
"Base",
"Collection",
"BaseItem",
"InvalidKeyError",
"ItemConflictError",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .async_base import AsyncBase
from .base import Base
from .async_collection import AsyncCollection
from .collection import Collection
from .common import BaseItem, QueryResponse
from .exceptions import InvalidKeyError, ItemConflictError, ItemNotFoundError

__all__ = (
"AsyncBase",
"Base",
"AsyncCollection",
"Collection",
"BaseItem",
"InvalidKeyError",
"ItemConflictError",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from typing_extensions import Self


class AsyncBase(Generic[ItemT]):
class AsyncCollection(Generic[ItemT]):
EXPIRES_ATTRIBUTE = "__expires"
PUT_LIMIT = 30

Expand Down Expand Up @@ -83,14 +83,14 @@ def __init__( # noqa: PLR0913
json_decoder: type[json.JSONDecoder] = json.JSONDecoder, # Only used when item_type is not a Pydantic model.
) -> None:
if not name:
msg = f"invalid Base name '{name}'"
msg = f"invalid Collection name '{name}'"
raise ValueError(msg)

self.name = name
self.item_type = item_type
self.data_key = data_key or project_key or get_data_key()
self.project_id = project_id or get_project_id()
self.host = host or os.getenv("CONTIGUITY_BASE_HOST") or "api.base.contiguity.co"
self.host = host or os.getenv("CONTIGUITY_COLLECTIONS_HOST") or "api.base.contiguity.co"
self.api_version = api_version
self.json_decoder = json_decoder
self.util = Updates()
Expand Down Expand Up @@ -190,7 +190,7 @@ async def get(
return self._response_as_item_type(response, sequence=False)

async def delete(self: Self, key: str, /) -> None:
"""Delete an item from the Base."""
"""Delete an item from the Collection."""
key = check_key(key)
response = await self._client.delete(f"/items/{key}")
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from typing_extensions import Self


class Base(Generic[ItemT]):
class Collection(Generic[ItemT]):
EXPIRES_ATTRIBUTE = "__expires"
PUT_LIMIT = 30

Expand Down Expand Up @@ -92,14 +92,14 @@ def __init__( # noqa: PLR0913
json_decoder: type[json.JSONDecoder] = json.JSONDecoder, # Only used when item_type is not a Pydantic model.
) -> None:
if not name:
msg = f"invalid Base name '{name}'"
msg = f"invalid Collection name '{name}'"
raise ValueError(msg)

self.name = name
self.item_type = item_type
self.data_key = data_key or project_key or get_data_key()
self.project_id = project_id or get_project_id()
self.host = host or os.getenv("CONTIGUITY_BASE_HOST") or "api.base.contiguity.co"
self.host = host or os.getenv("CONTIGUITY_COLLECTIONS_HOST") or "api.base.contiguity.co"
self.api_version = api_version
self.json_decoder = json_decoder
self.util = Updates()
Expand Down Expand Up @@ -199,7 +199,7 @@ def get(
return self._response_as_item_type(response, sequence=False)

def delete(self: Self, key: str, /) -> None:
"""Delete an item from the Base."""
"""Delete an item from the Collection."""
key = check_key(key)
response = self._client.delete(f"/items/{key}")
try:
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions src/contiguity/collections/compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing_extensions import deprecated

from .async_collection import AsyncCollection
from .collection import Collection
from .common import ItemT


@deprecated("This class has been renamed to `Collection` and will be removed in a future release.")
class Base(Collection[ItemT]):
pass


@deprecated("This class has been renamed to `AsyncCollection` and will be removed in a future release.")
class AsyncBase(AsyncCollection[ItemT]):
pass
156 changes: 0 additions & 156 deletions tests/base/test_async_base_model.py

This file was deleted.

Loading
Loading