diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index da758a4..39b8e70 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] defaults: run: diff --git a/pyproject.toml b/pyproject.toml index 586d919..af4dc76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,11 +9,11 @@ description = "Python client for Replicate" readme = "README.md" license = { file = "LICENSE" } authors = [{ name = "Replicate, Inc." }] -requires-python = ">=3.8" +requires-python = ">=3.9" dependencies = [ "httpx>=0.21.0,<1", "packaging", - "pydantic>1.10.7", + "pydantic>=2.0", "typing_extensions>=4.5.0", ] diff --git a/replicate/account.py b/replicate/account.py index fdcdca6..15a1707 100644 --- a/replicate/account.py +++ b/replicate/account.py @@ -17,7 +17,7 @@ class Account(Resource): name: str """The name of the account.""" - github_url: Optional[str] + github_url: Optional[str] = None """The GitHub URL of the account.""" diff --git a/replicate/deployment.py b/replicate/deployment.py index 21fc990..ebd27e2 100644 --- a/replicate/deployment.py +++ b/replicate/deployment.py @@ -13,10 +13,7 @@ ) from replicate.resource import Namespace, Resource -try: - from pydantic import v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore +import pydantic if TYPE_CHECKING: @@ -66,7 +63,7 @@ class Release(Resource): The time the release was created. """ - created_by: Optional[Account] + created_by: Optional[Account] = None """ The account that created the release. """ @@ -96,7 +93,7 @@ class Configuration(Resource): The deployment configuration. """ - current_release: Optional[Release] + current_release: Optional[Release] = None """ The current release of the deployment. """ diff --git a/replicate/exceptions.py b/replicate/exceptions.py index f52f9fb..50c40ca 100644 --- a/replicate/exceptions.py +++ b/replicate/exceptions.py @@ -27,19 +27,19 @@ class ReplicateError(ReplicateException): This class represents a problem details response as defined in RFC 7807. """ - type: Optional[str] + type: Optional[str] = None """A URI that identifies the error type.""" - title: Optional[str] + title: Optional[str] = None """A short, human-readable summary of the error.""" - status: Optional[int] + status: Optional[int] = None """The HTTP status code.""" - detail: Optional[str] + detail: Optional[str] = None """A human-readable explanation specific to this occurrence of the error.""" - instance: Optional[str] + instance: Optional[str] = None """A URI that identifies the specific occurrence of the error.""" def __init__( # pylint: disable=too-many-arguments diff --git a/replicate/file.py b/replicate/file.py index bb3ff86..cc20041 100644 --- a/replicate/file.py +++ b/replicate/file.py @@ -41,7 +41,7 @@ class File(Resource): created_at: str """The time the file was created.""" - expires_at: Optional[str] + expires_at: Optional[str] = None """The time the file will expire.""" urls: Dict[str, str] diff --git a/replicate/model.py b/replicate/model.py index a52459e..7600634 100644 --- a/replicate/model.py +++ b/replicate/model.py @@ -15,10 +15,7 @@ from replicate.resource import Namespace, Resource from replicate.version import Version, Versions -try: - from pydantic import v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore +import pydantic if TYPE_CHECKING: @@ -48,7 +45,7 @@ class Model(Resource): The name of the model. """ - description: Optional[str] + description: Optional[str] = None """ The description of the model. """ @@ -58,17 +55,17 @@ class Model(Resource): The visibility of the model. Can be 'public' or 'private'. """ - github_url: Optional[str] + github_url: Optional[str] = None """ The GitHub URL of the model. """ - paper_url: Optional[str] + paper_url: Optional[str] = None """ The URL of the paper related to the model. """ - license_url: Optional[str] + license_url: Optional[str] = None """ The URL of the license for the model. """ @@ -78,17 +75,17 @@ class Model(Resource): The number of runs of the model. """ - cover_image_url: Optional[str] + cover_image_url: Optional[str] = None """ The URL of the cover image for the model. """ - default_example: Optional[Prediction] + default_example: Optional[Prediction] = None """ The default example of the model. """ - latest_version: Optional[Version] + latest_version: Optional[Version] = None """ The latest version of the model. """ @@ -137,7 +134,7 @@ def reload(self) -> None: """ obj = self._client.models.get(f"{self.owner}/{self.name}") - for name, value in obj.dict().items(): + for name, value in obj.model_dump().items(): setattr(self, name, value) diff --git a/replicate/pagination.py b/replicate/pagination.py index 8ddebcf..1b4b5b4 100644 --- a/replicate/pagination.py +++ b/replicate/pagination.py @@ -11,10 +11,7 @@ Union, ) -try: - from pydantic import v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore +import pydantic from replicate.resource import Resource diff --git a/replicate/prediction.py b/replicate/prediction.py index b4ff047..1d988b5 100644 --- a/replicate/prediction.py +++ b/replicate/prediction.py @@ -27,10 +27,7 @@ from replicate.stream import EventSource from replicate.version import Version -try: - from pydantic import v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore +import pydantic if TYPE_CHECKING: from replicate.client import Client @@ -58,31 +55,31 @@ class Prediction(Resource): status: Literal["starting", "processing", "succeeded", "failed", "canceled"] """The status of the prediction.""" - input: Optional[Dict[str, Any]] + input: Optional[Dict[str, Any]] = None """The input to the prediction.""" - output: Optional[Any] + output: Optional[Any] = None """The output of the prediction.""" - logs: Optional[str] + logs: Optional[str] = None """The logs of the prediction.""" - error: Optional[str] + error: Optional[str] = None """The error encountered during the prediction, if any.""" - metrics: Optional[Dict[str, Any]] + metrics: Optional[Dict[str, Any]] = None """Metrics for the prediction.""" - created_at: Optional[str] + created_at: Optional[str] = None """When the prediction was created.""" - started_at: Optional[str] + started_at: Optional[str] = None """When the prediction was started.""" - completed_at: Optional[str] + completed_at: Optional[str] = None """When the prediction was completed, if finished.""" - urls: Optional[Dict[str, str]] + urls: Optional[Dict[str, str]] = None """ URLs associated with the prediction. @@ -214,7 +211,7 @@ def cancel(self) -> None: """ canceled = self._client.predictions.cancel(self.id) - for name, value in canceled.dict().items(): + for name, value in canceled.model_dump().items(): setattr(self, name, value) async def async_cancel(self) -> None: @@ -223,7 +220,7 @@ async def async_cancel(self) -> None: """ canceled = await self._client.predictions.async_cancel(self.id) - for name, value in canceled.dict().items(): + for name, value in canceled.model_dump().items(): setattr(self, name, value) def reload(self) -> None: @@ -232,7 +229,7 @@ def reload(self) -> None: """ updated = self._client.predictions.get(self.id) - for name, value in updated.dict().items(): + for name, value in updated.model_dump().items(): setattr(self, name, value) async def async_reload(self) -> None: @@ -241,7 +238,7 @@ async def async_reload(self) -> None: """ updated = await self._client.predictions.async_get(self.id) - for name, value in updated.dict().items(): + for name, value in updated.model_dump().items(): setattr(self, name, value) def output_iterator(self) -> Iterator[Any]: diff --git a/replicate/resource.py b/replicate/resource.py index a350826..0715cf1 100644 --- a/replicate/resource.py +++ b/replicate/resource.py @@ -1,10 +1,7 @@ import abc from typing import TYPE_CHECKING -try: - from pydantic import v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore +import pydantic if TYPE_CHECKING: from replicate.client import Client diff --git a/replicate/stream.py b/replicate/stream.py index e837abd..efd5307 100644 --- a/replicate/stream.py +++ b/replicate/stream.py @@ -17,10 +17,7 @@ from replicate.exceptions import ReplicateError from replicate.helpers import transform_output -try: - from pydantic import v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore +import pydantic if TYPE_CHECKING: @@ -49,7 +46,7 @@ class EventType(Enum): event: EventType data: str id: str - retry: Optional[int] + retry: Optional[int] = None def __str__(self) -> str: if self.event == ServerSentEvent.EventType.OUTPUT: @@ -89,10 +86,10 @@ class Decoder: A decoder for server-sent events. """ - event: Optional["ServerSentEvent.EventType"] + event: Optional["ServerSentEvent.EventType"] = None data: List[str] - last_event_id: Optional[str] - retry: Optional[int] + last_event_id: Optional[str] = None + retry: Optional[int] = None def __init__(self) -> None: self.event = None diff --git a/replicate/training.py b/replicate/training.py index 28e28b4..87b87be 100644 --- a/replicate/training.py +++ b/replicate/training.py @@ -20,10 +20,7 @@ from replicate.resource import Namespace, Resource from replicate.version import Version -try: - from pydantic import v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore +import pydantic if TYPE_CHECKING: from replicate.client import Client @@ -46,34 +43,34 @@ class Training(Resource): version: Union[str, Version] """The version of the model used to create the training.""" - destination: Optional[str] + destination: Optional[str] = None """The model destination of the training.""" status: Literal["starting", "processing", "succeeded", "failed", "canceled"] """The status of the training.""" - input: Optional[Dict[str, Any]] + input: Optional[Dict[str, Any]] = None """The input to the training.""" - output: Optional[Any] + output: Optional[Any] = None """The output of the training.""" - logs: Optional[str] + logs: Optional[str] = None """The logs of the training.""" - error: Optional[str] + error: Optional[str] = None """The error encountered during the training, if any.""" - created_at: Optional[str] + created_at: Optional[str] = None """When the training was created.""" - started_at: Optional[str] + started_at: Optional[str] = None """When the training was started.""" - completed_at: Optional[str] + completed_at: Optional[str] = None """When the training was completed, if finished.""" - urls: Optional[Dict[str, str]] + urls: Optional[Dict[str, str]] = None """ URLs associated with the training. @@ -88,7 +85,7 @@ def cancel(self) -> None: """ canceled = self._client.trainings.cancel(self.id) - for name, value in canceled.dict().items(): + for name, value in canceled.model_dump().items(): setattr(self, name, value) async def async_cancel(self) -> None: @@ -97,7 +94,7 @@ async def async_cancel(self) -> None: """ canceled = await self._client.trainings.async_cancel(self.id) - for name, value in canceled.dict().items(): + for name, value in canceled.model_dump().items(): setattr(self, name, value) def reload(self) -> None: @@ -106,7 +103,7 @@ def reload(self) -> None: """ updated = self._client.trainings.get(self.id) - for name, value in updated.dict().items(): + for name, value in updated.model_dump().items(): setattr(self, name, value) async def async_reload(self) -> None: @@ -115,7 +112,7 @@ async def async_reload(self) -> None: """ updated = await self._client.trainings.async_get(self.id) - for name, value in updated.dict().items(): + for name, value in updated.model_dump().items(): setattr(self, name, value)