diff --git a/Makefile b/Makefile index ff2c6c7..466630b 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ gen-model: fetch-v2-schema - datamodel-codegen --input v2.json --output model.py --use-standard-collections --output models.py \ + datamodel-codegen \ + --input v2.json \ + --collapse-root-models \ + --output neon_client/openapi_models.py \ + --use-standard-collections \ --output-model-type pydantic_v2.BaseModel \ --input-file-type openapi \ --use-standard-collections \ @@ -8,12 +12,17 @@ gen-model: fetch-v2-schema --use-schema-description \ --snake-case-field \ --enable-version-header \ - --enum-field-as-literal one \ --use-double-quotes \ --field-constraints \ --allow-population-by-field-name \ - --strict-nullable \ - --use-title-as-name + --use-title-as-name \ + --reuse-model \ + --field-constraints \ + --disable-appending-item-suffix \ + --allow-extra-fields \ + --use-annotated \ + --capitalise-enum-members \ + --use-unique-items-as-set fetch-v2-schema: curl -O https://neon.tech/api_spec/release/v2.json diff --git a/Pipfile b/Pipfile index 48340cf..6c233c2 100644 --- a/Pipfile +++ b/Pipfile @@ -8,6 +8,7 @@ openapi-python-client = "*" pip = "*" datamodel-code-generator = {extras = ["http"], version = "*"} requests = "*" +fastapi = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 147e705..ef84c0b 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "704bfec6d465cd7b19bf01a611497b98b94d548ae602841c6d6f958663313a07" + "sha256": "1259587fdd4e8600832ae72610bbc1e18db0400b8d4d6cc9ea2c982df34cd285" }, "pipfile-spec": 6, "requires": { @@ -303,6 +303,15 @@ ], "version": "==2.1.0.post1" }, + "fastapi": { + "hashes": [ + "sha256:8c77515984cd8e8cfeb58364f8cc7a28f0692088475e2614f7bf03275eba9093", + "sha256:b978095b9ee01a5cf49b19f4bc1ac9b8ca83aa076e770ef8fd9af09a2b88d191" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==0.109.0" + }, "frozenlist": { "hashes": [ "sha256:04ced3e6a46b4cfffe20f9ae482818e34eba9b5fb0ce4056e4cc9b6e212d09b7", @@ -652,7 +661,7 @@ "sha256:b3ef57c62535b0941697cce638c08900d87fcb67e29cfa99e8a68f747f393f7a", "sha256:d0caf5954bee831b6bfe7e338c32b9e30c85dfe080c843680783ac2b631673b4" ], - "markers": "python_version >= '3.7'", + "markers": "python_version >= '3.12' and python_version < '4.0'", "version": "==2.5.3" }, "pydantic-core": { @@ -886,6 +895,14 @@ "markers": "python_version >= '3.7'", "version": "==1.3.0" }, + "starlette": { + "hashes": [ + "sha256:3e2639dac3520e4f58734ed22553f950d3f3cb1001cd2eaac4d57e8cdc5f66bc", + "sha256:50bbbda9baa098e361f398fda0928062abbaf1f54f4fadcbe17c092a01eb9a25" + ], + "markers": "python_version >= '3.8'", + "version": "==0.35.1" + }, "typer": { "hashes": [ "sha256:50922fd79aea2f4751a8e0408ff10d2662bd0c8bbfa84755a699f3bada2978b2", diff --git a/neon_client/__pycache__/__init__.cpython-311.pyc b/neon_client/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..fc9acc2 Binary files /dev/null and b/neon_client/__pycache__/__init__.cpython-311.pyc differ diff --git a/neon_client/exceptions.py b/neon_client/exceptions.py index 5747844..febda6e 100644 --- a/neon_client/exceptions.py +++ b/neon_client/exceptions.py @@ -5,3 +5,9 @@ class NeonClientException(HTTPError): """Base exception class for all exceptions raised by the Neon Client.""" pass + + +class NeonClientAuthenticationException(NeonClientException): + """Exception raised when authentication fails.""" + + pass diff --git a/neon_client/http_client.py b/neon_client/http_client.py index 6325a20..2f0d1ec 100644 --- a/neon_client/http_client.py +++ b/neon_client/http_client.py @@ -24,7 +24,7 @@ class Neon_API_V2: response_model: BaseModel = None, response_is_array=False, check_status_code=True, - include_pagination=False, + _debug_pagination=False, **kwargs, ): """ @@ -71,9 +71,8 @@ class Neon_API_V2: else: response_parsed = response_model(**r.json()) - if include_pagination: - pagination = PaginationResponse(**r.json()).pagination - response_parsed.pagination = pagination + if _debug_pagination: + print(r.json()) return response_parsed else: diff --git a/neon_client/openapi_models.py b/neon_client/openapi_models.py index 3664677..3bfc846 100644 --- a/neon_client/openapi_models.py +++ b/neon_client/openapi_models.py @@ -1,23 +1,17 @@ # generated by datamodel-codegen: # filename: v2.json +# timestamp: 2024-01-14T23:49:21+00:00 # version: 0.25.2 from __future__ import annotations from enum import Enum -from typing import Literal +from typing import Annotated from uuid import UUID from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, RootModel -class ComputeUnit(RootModel[float]): - model_config = ConfigDict( - populate_by_name=True, - ) - root: float = Field(..., gte=0.25) - - class Provisioner(Enum): """ The Neon compute provisioner. @@ -25,8 +19,8 @@ class Provisioner(Enum): """ - k8s_pod = "k8s-pod" - k8s_neonvm = "k8s-neonvm" + K8S_POD = "k8s-pod" + K8S_NEONVM = "k8s-neonvm" class Pagination(BaseModel): @@ -38,9 +32,10 @@ class Pagination(BaseModel): """ model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - cursor: str = Field(..., min_length=1) + cursor: Annotated[str, Field(min_length=1)] class EmptyResponse(BaseModel): @@ -49,67 +44,81 @@ class EmptyResponse(BaseModel): """ model_config = ConfigDict( + extra="allow", populate_by_name=True, ) class ApiKeyCreateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - key_name: str = Field( - ..., - description="A user-specified API key name. This value is required when creating an API key.", - ) + key_name: Annotated[ + str, + Field( + description="A user-specified API key name. This value is required when creating an API key." + ), + ] class ApiKeyCreateResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - id: int = Field(..., description="The API key ID") - key: str = Field( - ..., description="The generated 64-bit token required to access the Neon API" - ) - name: str = Field(..., description="The user-specified API key name") - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the API key was created" - ) + id: Annotated[int, Field(description="The API key ID")] + key: Annotated[ + str, + Field(description="The generated 64-bit token required to access the Neon API"), + ] + name: Annotated[str, Field(description="The user-specified API key name")] + created_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the API key was created"), + ] class ApiKeyRevokeResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - id: int = Field(..., description="The API key ID") - name: str = Field(..., description="The user-specified API key name") - revoked: bool = Field( - ..., - description="A `true` or `false` value indicating whether the API key is revoked", - ) - last_used_at: AwareDatetime | None = Field( - None, description="A timestamp indicating when the API was last used" - ) - last_used_from_addr: str = Field( - ..., description="The IP address from which the API key was last used" - ) + id: Annotated[int, Field(description="The API key ID")] + name: Annotated[str, Field(description="The user-specified API key name")] + revoked: Annotated[ + bool, + Field( + description="A `true` or `false` value indicating whether the API key is revoked" + ), + ] + last_used_at: Annotated[ + AwareDatetime | None, + Field(None, description="A timestamp indicating when the API was last used"), + ] + last_used_from_addr: Annotated[ + str, Field(description="The IP address from which the API key was last used") + ] class ApiKeysListResponseItem(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - id: int = Field(..., description="The API key ID") - name: str = Field(..., description="The user-specified API key name") - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the API key was created" - ) - last_used_at: AwareDatetime | None = Field( - None, description="A timestamp indicating when the API was last used" - ) - last_used_from_addr: str = Field( - ..., description="The IP address from which the API key was last used" - ) + id: Annotated[int, Field(description="The API key ID")] + name: Annotated[str, Field(description="The user-specified API key name")] + created_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the API key was created"), + ] + last_used_at: Annotated[ + AwareDatetime | None, + Field(None, description="A timestamp indicating when the API was last used"), + ] + last_used_from_addr: Annotated[ + str, Field(description="The IP address from which the API key was last used") + ] class OperationAction(Enum): @@ -117,21 +126,21 @@ class OperationAction(Enum): The action performed by the operation """ - create_compute = "create_compute" - create_timeline = "create_timeline" - start_compute = "start_compute" - suspend_compute = "suspend_compute" - apply_config = "apply_config" - check_availability = "check_availability" - delete_timeline = "delete_timeline" - create_branch = "create_branch" - tenant_ignore = "tenant_ignore" - tenant_attach = "tenant_attach" - tenant_detach = "tenant_detach" - tenant_reattach = "tenant_reattach" - replace_safekeeper = "replace_safekeeper" - disable_maintenance = "disable_maintenance" - apply_storage_config = "apply_storage_config" + CREATE_COMPUTE = "create_compute" + CREATE_TIMELINE = "create_timeline" + START_COMPUTE = "start_compute" + SUSPEND_COMPUTE = "suspend_compute" + APPLY_CONFIG = "apply_config" + CHECK_AVAILABILITY = "check_availability" + DELETE_TIMELINE = "delete_timeline" + CREATE_BRANCH = "create_branch" + TENANT_IGNORE = "tenant_ignore" + TENANT_ATTACH = "tenant_attach" + TENANT_DETACH = "tenant_detach" + TENANT_REATTACH = "tenant_reattach" + REPLACE_SAFEKEEPER = "replace_safekeeper" + DISABLE_MAINTENANCE = "disable_maintenance" + APPLY_STORAGE_CONFIG = "apply_storage_config" class OperationStatus(Enum): @@ -139,109 +148,154 @@ class OperationStatus(Enum): The status of the operation """ - running = "running" - finished = "finished" - failed = "failed" - scheduling = "scheduling" + RUNNING = "running" + FINISHED = "finished" + FAILED = "failed" + SCHEDULING = "scheduling" class Branch(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - name: str | None = Field( - None, - description="The branch name. If not specified, the default branch name will be used.\n", - ) - role_name: str | None = Field( - None, - description="The role name. If not specified, the default role name will be used.\n", - ) - database_name: str | None = Field( - None, - description="The database name. If not specified, the default database name will be used.\n", - ) + name: Annotated[ + str | None, + Field( + None, + description="The branch name. If not specified, the default branch name will be used.\n", + ), + ] + role_name: Annotated[ + str | None, + Field( + None, + description="The role name. If not specified, the default role name will be used.\n", + ), + ] + database_name: Annotated[ + str | None, + Field( + None, + description="The database name. If not specified, the default database name will be used.\n", + ), + ] class ProjectConsumption(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - project_id: str = Field(..., description="The project ID") - period_id: UUID = Field( - ..., - description="The Id of the consumption period, used to reference the `previous_period_id` field.\n", - ) - data_storage_bytes_hour: int = Field( - ..., - description="Bytes-Hour. The amount of storage the project consumed during the billing period. Expect some lag in the reported value.\nThe value is reset at the beginning of each billing period.\n", - ge=0, - ) - data_storage_bytes_hour_updated_at: AwareDatetime | None = Field( - None, - description="The timestamp of the last update of the `data_storage_bytes_hour` field.\n", - ) - synthetic_storage_size: int = Field( - ..., - description="Bytes. The current space occupied by project in storage. Expect some lag in the reported value.\n", - ge=0, - ) - synthetic_storage_size_updated_at: AwareDatetime | None = Field( - None, - description="The timestamp of the last update of the `synthetic_storage_size` field.\n", - ) - data_transfer_bytes: int = Field( - ..., - description="Bytes. The egress traffic from the Neon cloud to the client for the project over the billing period.\nIncludes egress traffic for deleted endpoints. Expect some lag in the reported value. The value is reset at the beginning of each billing period.\n", - ge=0, - ) - data_transfer_bytes_updated_at: AwareDatetime | None = Field( - None, - description="Timestamp of the last update of `data_transfer_bytes` field\n", - ) - written_data_bytes: int = Field( - ..., - description="Bytes. The Amount of WAL that travelled through storage for given project for all branches.\nExpect some lag in the reported value. The value is reset at the beginning of each billing period.\n", - ge=0, - ) - written_data_bytes_updated_at: AwareDatetime | None = Field( - None, - description="The timestamp of the last update of `written_data_bytes` field.\n", - ) - compute_time_seconds: int = Field( - ..., - description="Seconds. The number of CPU seconds used by the project's compute endpoints, including compute endpoints that have been deleted.\nExpect some lag in the reported value. The value is reset at the beginning of each billing period.\nExamples:\n1. An endpoint that uses 1 CPU for 1 second is equal to `compute_time=1`.\n2. An endpoint that uses 2 CPUs simultaneously for 1 second is equal to `compute_time=2`.\n", - ge=0, - ) - compute_time_seconds_updated_at: AwareDatetime | None = Field( - None, - description="The timestamp of the last update of `compute_time_seconds` field.\n", - ) - active_time_seconds: int = Field( - ..., - description="Seconds. The amount of time that compute endpoints in this project have been active.\nExpect some lag in the reported value.\n\nThe value is reset at the beginning of each billing period.\n", - ge=0, - ) - active_time_seconds_updated_at: AwareDatetime | None = Field( - None, - description="The timestamp of the last update of the `active_time_seconds` field.\n", - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the period was last updated.\n" - ) - period_start: AwareDatetime = Field( - ..., description="The start of the consumption period.\n" - ) - period_end: AwareDatetime | None = Field( - ..., description="The end of the consumption period.\n" - ) - previous_period_id: UUID | None = Field( - ..., description="The `period_id` of the previous consumption period.\n" - ) + project_id: Annotated[str, Field(description="The project ID")] + period_id: Annotated[ + UUID, + Field( + description="The Id of the consumption period, used to reference the `previous_period_id` field.\n" + ), + ] + data_storage_bytes_hour: Annotated[ + int, + Field( + description="Bytes-Hour. The amount of storage the project consumed during the billing period. Expect some lag in the reported value.\nThe value is reset at the beginning of each billing period.\n", + ge=0, + ), + ] + data_storage_bytes_hour_updated_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="The timestamp of the last update of the `data_storage_bytes_hour` field.\n", + ), + ] + synthetic_storage_size: Annotated[ + int, + Field( + description="Bytes. The current space occupied by project in storage. Expect some lag in the reported value.\n", + ge=0, + ), + ] + synthetic_storage_size_updated_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="The timestamp of the last update of the `synthetic_storage_size` field.\n", + ), + ] + data_transfer_bytes: Annotated[ + int, + Field( + description="Bytes. The egress traffic from the Neon cloud to the client for the project over the billing period.\nIncludes egress traffic for deleted endpoints. Expect some lag in the reported value. The value is reset at the beginning of each billing period.\n", + ge=0, + ), + ] + data_transfer_bytes_updated_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="Timestamp of the last update of `data_transfer_bytes` field\n", + ), + ] + written_data_bytes: Annotated[ + int, + Field( + description="Bytes. The Amount of WAL that travelled through storage for given project for all branches.\nExpect some lag in the reported value. The value is reset at the beginning of each billing period.\n", + ge=0, + ), + ] + written_data_bytes_updated_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="The timestamp of the last update of `written_data_bytes` field.\n", + ), + ] + compute_time_seconds: Annotated[ + int, + Field( + description="Seconds. The number of CPU seconds used by the project's compute endpoints, including compute endpoints that have been deleted.\nExpect some lag in the reported value. The value is reset at the beginning of each billing period.\nExamples:\n1. An endpoint that uses 1 CPU for 1 second is equal to `compute_time=1`.\n2. An endpoint that uses 2 CPUs simultaneously for 1 second is equal to `compute_time=2`.\n", + ge=0, + ), + ] + compute_time_seconds_updated_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="The timestamp of the last update of `compute_time_seconds` field.\n", + ), + ] + active_time_seconds: Annotated[ + int, + Field( + description="Seconds. The amount of time that compute endpoints in this project have been active.\nExpect some lag in the reported value.\n\nThe value is reset at the beginning of each billing period.\n", + ge=0, + ), + ] + active_time_seconds_updated_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="The timestamp of the last update of the `active_time_seconds` field.\n", + ), + ] + updated_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the period was last updated.\n"), + ] + period_start: Annotated[ + AwareDatetime, Field(description="The start of the consumption period.\n") + ] + period_end: Annotated[ + AwareDatetime, Field(description="The end of the consumption period.\n") + ] + previous_period_id: Annotated[ + UUID, Field(description="The `period_id` of the previous consumption period.\n") + ] class Limits(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) active_time: int @@ -267,31 +321,42 @@ class BranchState(Enum): The branch state """ - init = "init" - ready = "ready" + INIT = "init" + READY = "ready" class Branch2(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - parent_id: str | None = Field( - None, - description="The `branch_id` of the parent branch. If omitted or empty, the branch will be created from the project's primary branch.\n", - ) - name: str | None = Field(None, description="The branch name\n") - parent_lsn: str | None = Field( - None, - description="A Log Sequence Number (LSN) on the parent branch. The branch will be created with data from this LSN.\n", - ) - parent_timestamp: AwareDatetime | None = Field( - None, - description="A timestamp identifying a point in time on the parent branch. The branch will be created with data starting from this point in time.\n", - ) + parent_id: Annotated[ + str | None, + Field( + None, + description="The `branch_id` of the parent branch. If omitted or empty, the branch will be created from the project's primary branch.\n", + ), + ] + name: Annotated[str | None, Field(None, description="The branch name\n")] + parent_lsn: Annotated[ + str | None, + Field( + None, + description="A Log Sequence Number (LSN) on the parent branch. The branch will be created with data from this LSN.\n", + ), + ] + parent_timestamp: Annotated[ + AwareDatetime | None, + Field( + None, + description="A timestamp identifying a point in time on the parent branch. The branch will be created with data starting from this point in time.\n", + ), + ] class Branch3(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) name: str | None = None @@ -299,6 +364,7 @@ class Branch3(BaseModel): class BranchUpdateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) branch: Branch3 @@ -306,23 +372,27 @@ class BranchUpdateRequest(BaseModel): class ConnectionParameters(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - database: str = Field(..., description="Database name.\n") - password: str = Field(..., description="Password for the role.\n") - role: str = Field(..., description="Role name.\n") - host: str = Field(..., description="Host name.\n") - pooler_host: str = Field(..., description="Pooler host name.\n") + database: Annotated[str, Field(description="Database name.\n")] + password: Annotated[str, Field(description="Password for the role.\n")] + role: Annotated[str, Field(description="Role name.\n")] + host: Annotated[str, Field(description="Host name.\n")] + pooler_host: Annotated[str, Field(description="Pooler host name.\n")] class ConnectionDetails(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - connection_uri: str = Field( - ..., - description="Connection URI is same as specified in https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6\nIt is a ready to use string for psql or for DATABASE_URL environment variable.\n", - ) + connection_uri: Annotated[ + str, + Field( + description="Connection URI is same as specified in https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6\nIt is a ready to use string for psql or for DATABASE_URL environment variable.\n" + ), + ] connection_parameters: ConnectionParameters @@ -332,9 +402,9 @@ class EndpointState(Enum): """ - init = "init" - active = "active" - idle = "idle" + INIT = "init" + ACTIVE = "active" + IDLE = "idle" class EndpointType(Enum): @@ -344,30 +414,17 @@ class EndpointType(Enum): """ - read_only = "read_only" - read_write = "read_write" + READ_ONLY = "read_only" + READ_WRITE = "read_write" -class EndpointPoolerMode(RootModel[Literal["transaction"]]): - model_config = ConfigDict( - populate_by_name=True, - ) - root: Literal["transaction"] = Field( - ..., - description="The connection pooler mode. Neon supports PgBouncer in `transaction` mode only.\n", - ) +class EndpointPoolerMode(Enum): + """ + The connection pooler mode. Neon supports PgBouncer in `transaction` mode only. + """ -class SuspendTimeoutSeconds(RootModel[int]): - model_config = ConfigDict( - populate_by_name=True, - ) - root: int = Field( - ..., - description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", - ge=-1, - le=604800, - ) + TRANSACTION = "transaction" class AllowedIps(BaseModel): @@ -379,19 +436,26 @@ class AllowedIps(BaseModel): """ model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - ips: list[str] = Field( - ..., - description="A list of IP addresses that are allowed to connect to the endpoint.", - ) - primary_branch_only: bool = Field( - ..., description="If true, the list will be applied only to the primary branch." - ) + ips: Annotated[ + list[str], + Field( + description="A list of IP addresses that are allowed to connect to the endpoint." + ), + ] + primary_branch_only: Annotated[ + bool, + Field( + description="If true, the list will be applied only to the primary branch." + ), + ] class ConnectionURIsResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) connection_uris: list[ConnectionDetails] @@ -399,6 +463,7 @@ class ConnectionURIsResponse(BaseModel): class ConnectionURIsOptionalResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) connection_uris: list[ConnectionDetails] | None = None @@ -406,6 +471,7 @@ class ConnectionURIsOptionalResponse(BaseModel): class EndpointPasswordlessSessionAuthRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) session_id: str @@ -415,14 +481,17 @@ class Duration(RootModel[int]): model_config = ConfigDict( populate_by_name=True, ) - root: int = Field( - ..., - description="A Duration represents the elapsed time between two instants\nas an int64 nanosecond count. The representation limits the\nlargest representable duration to approximately 290 years.", - ) + root: Annotated[ + int, + Field( + description="A Duration represents the elapsed time between two instants\nas an int64 nanosecond count. The representation limits the\nlargest representable duration to approximately 290 years." + ), + ] class StatementData(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) fields: list[str] | None = None @@ -432,42 +501,49 @@ class StatementData(BaseModel): class ExplainData(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - query_plan: str = Field(..., alias="QUERY PLAN") + query_plan: Annotated[str, Field(alias="QUERY PLAN")] class Role(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - branch_id: str = Field( - ..., description="The ID of the branch to which the role belongs\n" - ) - name: str = Field(..., description="The role name\n") - password: str | None = Field(None, description="The role password\n") - protected: bool | None = Field( - None, description="Whether or not the role is system-protected\n" - ) - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the role was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the role was last updated\n" - ) + branch_id: Annotated[ + str, Field(description="The ID of the branch to which the role belongs\n") + ] + name: Annotated[str, Field(description="The role name\n")] + password: Annotated[str | None, Field(None, description="The role password\n")] + protected: Annotated[ + bool | None, + Field(None, description="Whether or not the role is system-protected\n"), + ] + created_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the role was created\n"), + ] + updated_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the role was last updated\n"), + ] class Role1(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - name: str = Field( - ..., description="The role name. Cannot exceed 63 bytes in length.\n" - ) + name: Annotated[ + str, Field(description="The role name. Cannot exceed 63 bytes in length.\n") + ] class RoleCreateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) role: Role1 @@ -475,6 +551,7 @@ class RoleCreateRequest(BaseModel): class RoleResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) role: Role @@ -482,6 +559,7 @@ class RoleResponse(BaseModel): class RolesResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) roles: list[Role] @@ -489,9 +567,10 @@ class RolesResponse(BaseModel): class RolePasswordResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - password: str = Field(..., description="The role password\n") + password: Annotated[str, Field(description="The role password\n")] class Brand(Enum): @@ -500,46 +579,57 @@ class Brand(Enum): """ - amex = "amex" - diners = "diners" - discover = "discover" - jcb = "jcb" - mastercard = "mastercard" - unionpay = "unionpay" - unknown = "unknown" - visa = "visa" + AMEX = "amex" + DINERS = "diners" + DISCOVER = "discover" + JCB = "jcb" + MASTERCARD = "mastercard" + UNIONPAY = "unionpay" + UNKNOWN = "unknown" + VISA = "visa" class PaymentSourceBankCard(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - last4: str = Field(..., description="Last 4 digits of the card.\n") - brand: Brand | None = Field(None, description="Brand of credit card.\n") - exp_month: int | None = Field(None, description="Credit card expiration month\n") - exp_year: int | None = Field(None, description="Credit card expiration year\n") + last4: Annotated[str, Field(description="Last 4 digits of the card.\n")] + brand: Annotated[Brand | None, Field(None, description="Brand of credit card.\n")] + exp_month: Annotated[ + int | None, Field(None, description="Credit card expiration month\n") + ] + exp_year: Annotated[ + int | None, Field(None, description="Credit card expiration year\n") + ] class PaymentSource(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - type: str = Field(..., description='Type of payment source. E.g. "card".\n') + type: Annotated[str, Field(description='Type of payment source. E.g. "card".\n')] card: PaymentSourceBankCard | None = None class BillingAccount1(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - email: str | None = Field( - None, - description="Billing email, to receive emails related to invoices and subscriptions.\n", - ) + email: Annotated[ + str | None, + Field( + None, + description="Billing email, to receive emails related to invoices and subscriptions.\n", + ), + ] class BillingAccountUpdateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) billing_account: BillingAccount1 @@ -552,45 +642,52 @@ class BillingSubscriptionType(Enum): """ - unknown = "UNKNOWN" - free = "free" - pro = "pro" - direct_sales = "direct_sales" - aws_marketplace = "aws_marketplace" + UNKNOWN = "UNKNOWN" + FREE = "free" + PRO = "pro" + DIRECT_SALES = "direct_sales" + AWS_MARKETPLACE = "aws_marketplace" class Database(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - id: int = Field(..., description="The database ID\n") - branch_id: str = Field( - ..., description="The ID of the branch to which the database belongs\n" - ) - name: str = Field(..., description="The database name\n") - owner_name: str = Field( - ..., description="The name of role that owns the database\n" - ) - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the database was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the database was last updated\n" - ) + id: Annotated[int, Field(description="The database ID\n")] + branch_id: Annotated[ + str, Field(description="The ID of the branch to which the database belongs\n") + ] + name: Annotated[str, Field(description="The database name\n")] + owner_name: Annotated[ + str, Field(description="The name of role that owns the database\n") + ] + created_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the database was created\n"), + ] + updated_at: Annotated[ + AwareDatetime, + Field( + description="A timestamp indicating when the database was last updated\n" + ), + ] class Database1(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - name: str = Field(..., description="The name of the datbase\n") - owner_name: str = Field( - ..., description="The name of the role that owns the database\n" - ) + name: Annotated[str, Field(description="The name of the datbase\n")] + owner_name: Annotated[ + str, Field(description="The name of the role that owns the database\n") + ] class DatabaseCreateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) database: Database1 @@ -598,16 +695,19 @@ class DatabaseCreateRequest(BaseModel): class Database2(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - name: str | None = Field(None, description="The name of the database\n") - owner_name: str | None = Field( - None, description="The name of the role that owns the database\n" - ) + name: Annotated[str | None, Field(None, description="The name of the database\n")] + owner_name: Annotated[ + str | None, + Field(None, description="The name of the role that owns the database\n"), + ] class DatabaseUpdateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) database: Database2 @@ -615,6 +715,7 @@ class DatabaseUpdateRequest(BaseModel): class DatabaseResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) database: Database @@ -622,6 +723,7 @@ class DatabaseResponse(BaseModel): class DatabasesResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) databases: list[Database] @@ -629,6 +731,7 @@ class DatabasesResponse(BaseModel): class CurrentUserAuthAccount(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) email: str @@ -640,6 +743,7 @@ class CurrentUserAuthAccount(BaseModel): class UpdateUserInfoRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) email: str @@ -667,76 +771,62 @@ class ProjectQuota(BaseModel): """ model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - active_time_seconds: int | None = Field( - None, - description="The total amount of wall-clock time allowed to be spent by the project's compute endpoints.\n", - ge=0, - ) - compute_time_seconds: int | None = Field( - None, - description="The total amount of CPU seconds allowed to be spent by the project's compute endpoints.\n", - ge=0, - ) - written_data_bytes: int | None = Field( - None, - description="Total amount of data written to all of a project's branches.\n", - ge=0, - ) - data_transfer_bytes: int | None = Field( - None, - description="Total amount of data transferred from all of a project's branches using the proxy.\n", - ge=0, - ) - logical_size_bytes: int | None = Field( - None, description="Limit on the logical size of every project's branch.\n", ge=0 - ) - - -class PgSettingsData(RootModel[dict[str, str] | None]): - """ - A raw representation of PostgreSQL settings - """ - - model_config = ConfigDict( - populate_by_name=True, - ) - root: dict[str, str] | None = None - - -class PgbouncerSettingsData(RootModel[dict[str, str] | None]): - """ - A raw representation of PgBouncer settings - """ - - model_config = ConfigDict( - populate_by_name=True, - ) - root: dict[str, str] | None = None - - -class PgVersion(RootModel[int]): - model_config = ConfigDict( - populate_by_name=True, - ) - root: int = Field( - ..., - description="The major PostgreSQL version number. Currently supported versions are `14`, `15` and `16`.", - ge=14, - le=16, - ) + active_time_seconds: Annotated[ + int | None, + Field( + None, + description="The total amount of wall-clock time allowed to be spent by the project's compute endpoints.\n", + ge=0, + ), + ] + compute_time_seconds: Annotated[ + int | None, + Field( + None, + description="The total amount of CPU seconds allowed to be spent by the project's compute endpoints.\n", + ge=0, + ), + ] + written_data_bytes: Annotated[ + int | None, + Field( + None, + description="Total amount of data written to all of a project's branches.\n", + ge=0, + ), + ] + data_transfer_bytes: Annotated[ + int | None, + Field( + None, + description="Total amount of data transferred from all of a project's branches using the proxy.\n", + ge=0, + ), + ] + logical_size_bytes: Annotated[ + int | None, + Field( + None, + description="Limit on the logical size of every project's branch.\n", + ge=0, + ), + ] class HealthCheck(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - status: str = Field(..., description="Service status") + status: Annotated[str, Field(description="Service status")] class ProjectOwnerData(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) email: str @@ -744,22 +834,16 @@ class ProjectOwnerData(BaseModel): subscription_type: BillingSubscriptionType -class ErrorCode(RootModel[str]): - model_config = ConfigDict( - populate_by_name=True, - ) - root: str - - class SupportTicketSeverity(Enum): - low = "low" - normal = "normal" - high = "high" - critical = "critical" + LOW = "low" + NORMAL = "normal" + HIGH = "high" + CRITICAL = "critical" class PaginationResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) pagination: Pagination | None = None @@ -767,35 +851,44 @@ class PaginationResponse(BaseModel): class Operation(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - id: UUID = Field(..., description="The operation ID") - project_id: str = Field(..., description="The Neon project ID") - branch_id: str | None = Field(None, description="The branch ID") - endpoint_id: str | None = Field(None, description="The endpoint ID") + id: Annotated[UUID, Field(description="The operation ID")] + project_id: Annotated[str, Field(description="The Neon project ID")] + branch_id: Annotated[str | None, Field(None, description="The branch ID")] + endpoint_id: Annotated[str | None, Field(None, description="The endpoint ID")] action: OperationAction status: OperationStatus - error: str | None = Field(None, description="The error that occured") - failures_count: int = Field( - ..., description="The number of times the operation failed" - ) - retry_at: AwareDatetime | None = Field( - None, description="A timestamp indicating when the operation was last retried" - ) - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the operation was created" - ) - updated_at: AwareDatetime = Field( - ..., - description="A timestamp indicating when the operation status was last updated", - ) - total_duration_ms: int = Field( - ..., description="The total duration of the operation in milliseconds" - ) + error: Annotated[str | None, Field(None, description="The error that occured")] + failures_count: Annotated[ + int, Field(description="The number of times the operation failed") + ] + retry_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="A timestamp indicating when the operation was last retried", + ), + ] + created_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the operation was created"), + ] + updated_at: Annotated[ + AwareDatetime, + Field( + description="A timestamp indicating when the operation status was last updated" + ), + ] + total_duration_ms: Annotated[ + int, Field(description="The total duration of the operation in milliseconds") + ] class OperationResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) operation: Operation @@ -803,6 +896,7 @@ class OperationResponse(BaseModel): class OperationsResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) operations: list[Operation] @@ -810,18 +904,23 @@ class OperationsResponse(BaseModel): class ProjectSettingsData(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) quota: ProjectQuota | None = None allowed_ips: AllowedIps | None = None - enable_logical_replication: bool | None = Field( - None, - description="Sets wal_level=logical for all compute endpoints in this project.\nAll active endpoints will be suspended.\nOnce enabled, logical replication cannot be disabled.\n", - ) + enable_logical_replication: Annotated[ + bool | None, + Field( + None, + description="Sets wal_level=logical for all compute endpoints in this project.\nAll active endpoints will be suspended.\nOnce enabled, logical replication cannot be disabled.\n", + ), + ] class ProjectsConsumptionResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) projects: list[ProjectConsumption] @@ -830,74 +929,108 @@ class ProjectsConsumptionResponse(BaseModel): class Branch1(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - id: str = Field( - ..., - description="The branch ID. This value is generated when a branch is created. A `branch_id` value has a `br` prefix. For example: `br-small-term-683261`.\n", - ) - project_id: str = Field( - ..., description="The ID of the project to which the branch belongs\n" - ) - parent_id: str | None = Field( - None, description="The `branch_id` of the parent branch\n" - ) - parent_lsn: str | None = Field( - None, - description="The Log Sequence Number (LSN) on the parent branch from which this branch was created\n", - ) - parent_timestamp: AwareDatetime | None = Field( - None, - description="The point in time on the parent branch from which this branch was created\n", - ) - name: str = Field(..., description="The branch name\n") + id: Annotated[ + str, + Field( + description="The branch ID. This value is generated when a branch is created. A `branch_id` value has a `br` prefix. For example: `br-small-term-683261`.\n" + ), + ] + project_id: Annotated[ + str, Field(description="The ID of the project to which the branch belongs\n") + ] + parent_id: Annotated[ + str | None, Field(None, description="The `branch_id` of the parent branch\n") + ] + parent_lsn: Annotated[ + str | None, + Field( + None, + description="The Log Sequence Number (LSN) on the parent branch from which this branch was created\n", + ), + ] + parent_timestamp: Annotated[ + AwareDatetime | None, + Field( + None, + description="The point in time on the parent branch from which this branch was created\n", + ), + ] + name: Annotated[str, Field(description="The branch name\n")] current_state: BranchState pending_state: BranchState | None = None - logical_size: int | None = Field( - None, description="The logical size of the branch, in bytes\n" - ) - creation_source: str = Field(..., description="The branch creation source\n") - primary: bool = Field( - ..., description="Whether the branch is the project's primary branch\n" - ) - cpu_used_sec: int = Field( - ..., - description="CPU seconds used by all the endpoints of the branch, including deleted ones.\nThis value is reset at the beginning of each billing period.\nExamples:\n1. A branch that uses 1 CPU for 1 second is equal to `cpu_used_sec=1`.\n2. A branch that uses 2 CPUs simultaneously for 1 second is equal to `cpu_used_sec=2`.\n", - ) + logical_size: Annotated[ + int | None, + Field(None, description="The logical size of the branch, in bytes\n"), + ] + creation_source: Annotated[str, Field(description="The branch creation source\n")] + primary: Annotated[ + bool, Field(description="Whether the branch is the project's primary branch\n") + ] + cpu_used_sec: Annotated[ + int, + Field( + description="CPU seconds used by all the endpoints of the branch, including deleted ones.\nThis value is reset at the beginning of each billing period.\nExamples:\n1. A branch that uses 1 CPU for 1 second is equal to `cpu_used_sec=1`.\n2. A branch that uses 2 CPUs simultaneously for 1 second is equal to `cpu_used_sec=2`.\n" + ), + ] compute_time_seconds: int active_time_seconds: int written_data_bytes: int data_transfer_bytes: int - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the branch was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the branch was last updated\n" - ) - last_reset_at: AwareDatetime | None = Field( - None, description="A timestamp indicating when the branch was last reset\n" - ) + created_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the branch was created\n"), + ] + updated_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the branch was last updated\n"), + ] + last_reset_at: Annotated[ + AwareDatetime | None, + Field( + None, description="A timestamp indicating when the branch was last reset\n" + ), + ] class BranchCreateRequestEndpointOptions(BaseModel): model_config = ConfigDict( - populate_by_name=True, + extra="allow", populate_by_name=True, use_enum_values=True ) type: EndpointType - autoscaling_limit_min_cu: ComputeUnit | None = Field( - None, - description="The minimum number of Compute Units. The minimum value is `0.25`.\n See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\n for more information.\n", - ) - autoscaling_limit_max_cu: ComputeUnit | None = Field( - None, - description="The maximum number of Compute Units.\n See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\n for more information.\n", - ) + autoscaling_limit_min_cu: Annotated[ + float | None, + Field( + None, + description="The minimum number of Compute Units. The minimum value is `0.25`.\n See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\n for more information.\n", + ge=0.25, + ), + ] + autoscaling_limit_max_cu: Annotated[ + float | None, + Field( + None, + description="The maximum number of Compute Units.\n See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\n for more information.\n", + ge=0.25, + ), + ] provisioner: Provisioner | None = None - suspend_timeout_seconds: SuspendTimeoutSeconds | None = None + suspend_timeout_seconds: Annotated[ + int | None, + Field( + None, + description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", + ge=-1, + le=604800, + ), + ] class BranchCreateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) endpoints: list[BranchCreateRequestEndpointOptions] | None = None @@ -906,6 +1039,7 @@ class BranchCreateRequest(BaseModel): class BranchResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) branch: Branch1 @@ -913,6 +1047,7 @@ class BranchResponse(BaseModel): class BranchesResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) branches: list[Branch1] @@ -920,6 +1055,7 @@ class BranchesResponse(BaseModel): class StatementResult(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) data: StatementData | None = None @@ -930,29 +1066,41 @@ class StatementResult(BaseModel): class BillingAccount(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) payment_source: PaymentSource subscription_type: BillingSubscriptionType - quota_reset_at_last: AwareDatetime = Field( - ..., - description="The last time the quota was reset. Defaults to the date-time the account is created.\n", - ) - email: str = Field( - ..., - description="Billing email, to receive emails related to invoices and subscriptions.\n", - ) - address_city: str = Field(..., description="Billing address city.\n") - address_country: str = Field(..., description="Billing address country.\n") - address_line1: str = Field(..., description="Billing address line 1.\n") - address_line2: str = Field(..., description="Billing address line 2.\n") - address_postal_code: str = Field(..., description="Billing address postal code.\n") - address_state: str = Field(..., description="Billing address state or region.\n") - orb_portal_url: str | None = Field(None, description="Orb user portal url\n") + quota_reset_at_last: Annotated[ + AwareDatetime, + Field( + description="The last time the quota was reset. Defaults to the date-time the account is created.\n" + ), + ] + email: Annotated[ + str, + Field( + description="Billing email, to receive emails related to invoices and subscriptions.\n" + ), + ] + address_city: Annotated[str, Field(description="Billing address city.\n")] + address_country: Annotated[str, Field(description="Billing address country.\n")] + address_line1: Annotated[str, Field(description="Billing address line 1.\n")] + address_line2: Annotated[str, Field(description="Billing address line 2.\n")] + address_postal_code: Annotated[ + str, Field(description="Billing address postal code.\n") + ] + address_state: Annotated[ + str, Field(description="Billing address state or region.\n") + ] + orb_portal_url: Annotated[ + str | None, Field(None, description="Orb user portal url\n") + ] class BillingAccountResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) billing_account: BillingAccount @@ -960,12 +1108,15 @@ class BillingAccountResponse(BaseModel): class CurrentUserInfoResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - active_seconds_limit: int = Field( - ..., - description="Control plane observes active endpoints of a user this amount of wall-clock time.\n", - ) + active_seconds_limit: Annotated[ + int, + Field( + description="Control plane observes active endpoints of a user this amount of wall-clock time.\n" + ), + ] billing_account: BillingAccount auth_accounts: list[CurrentUserAuthAccount] email: str @@ -976,7 +1127,7 @@ class CurrentUserInfoResponse(BaseModel): last_name: str projects_limit: int branches_limit: int - max_autoscaling_limit: ComputeUnit + max_autoscaling_limit: Annotated[float, Field(ge=0.25)] compute_seconds_limit: int | None = None plan: str @@ -987,10 +1138,11 @@ class EndpointSettingsData(BaseModel): """ model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - pg_settings: PgSettingsData | None = None - pgbouncer_settings: PgbouncerSettingsData | None = None + pg_settings: dict[str, str] | None = None + pgbouncer_settings: dict[str, str] | None = None class DefaultEndpointSettings(BaseModel): @@ -999,19 +1151,36 @@ class DefaultEndpointSettings(BaseModel): """ model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - pg_settings: PgSettingsData | None = None - pgbouncer_settings: PgbouncerSettingsData | None = None - autoscaling_limit_min_cu: ComputeUnit | None = Field( - None, - description="The minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - autoscaling_limit_max_cu: ComputeUnit | None = Field( - None, - description="The maximum number of Compute Units. See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - suspend_timeout_seconds: SuspendTimeoutSeconds | None = None + pg_settings: dict[str, str] | None = None + pgbouncer_settings: dict[str, str] | None = None + autoscaling_limit_min_cu: Annotated[ + float | None, + Field( + None, + description="The minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", + ge=0.25, + ), + ] + autoscaling_limit_max_cu: Annotated[ + float | None, + Field( + None, + description="The maximum number of Compute Units. See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", + ge=0.25, + ), + ] + suspend_timeout_seconds: Annotated[ + int | None, + Field( + None, + description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", + ge=-1, + le=604800, + ), + ] class GeneralError(BaseModel): @@ -1020,15 +1189,17 @@ class GeneralError(BaseModel): """ model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - code: ErrorCode - message: str = Field(..., description="Error message") + code: str + message: Annotated[str, Field(description="Error message")] class BranchOperations(BranchResponse, OperationsResponse): pass model_config = ConfigDict( + extra="allow", populate_by_name=True, ) @@ -1036,6 +1207,7 @@ class BranchOperations(BranchResponse, OperationsResponse): class DatabaseOperations(DatabaseResponse, OperationsResponse): pass model_config = ConfigDict( + extra="allow", populate_by_name=True, ) @@ -1043,6 +1215,7 @@ class DatabaseOperations(DatabaseResponse, OperationsResponse): class RoleOperations(RoleResponse, OperationsResponse): pass model_config = ConfigDict( + extra="allow", populate_by_name=True, ) @@ -1054,199 +1227,311 @@ class ProjectListItem(BaseModel): """ model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - id: str = Field(..., description="The project ID\n") - platform_id: str = Field( - ..., - description="The cloud platform identifier. Currently, only AWS is supported, for which the identifier is `aws`.\n", - ) - region_id: str = Field(..., description="The region identifier\n") - name: str = Field(..., description="The project name\n") + id: Annotated[str, Field(description="The project ID\n")] + platform_id: Annotated[ + str, + Field( + description="The cloud platform identifier. Currently, only AWS is supported, for which the identifier is `aws`.\n" + ), + ] + region_id: Annotated[str, Field(description="The region identifier\n")] + name: Annotated[str, Field(description="The project name\n")] provisioner: Provisioner default_endpoint_settings: DefaultEndpointSettings | None = None settings: ProjectSettingsData | None = None - pg_version: PgVersion - proxy_host: str = Field( - ..., - description="The proxy host for the project. This value combines the `region_id`, the `platform_id`, and the Neon domain (`neon.tech`).\n", - ) - branch_logical_size_limit: int = Field( - ..., description="The logical size limit for a branch. The value is in MiB.\n" - ) - branch_logical_size_limit_bytes: int = Field( - ..., description="The logical size limit for a branch. The value is in B.\n" - ) - store_passwords: bool = Field( - ..., - description="Whether or not passwords are stored for roles in the Neon project. Storing passwords facilitates access to Neon features that require authorization.\n", - ) - active_time: int = Field( - ..., - description="Control plane observed endpoints of this project being active this amount of wall-clock time.\n", - ge=0, - ) - cpu_used_sec: int = Field( - ..., description="DEPRECATED. Use data from the getProject endpoint instead.\n" - ) - maintenance_starts_at: AwareDatetime | None = Field( - None, - description="A timestamp indicating when project maintenance begins. If set, the project is placed into maintenance mode at this time.\n", - ) - creation_source: str = Field(..., description="The project creation source\n") - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the project was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the project was last updated\n" - ) - synthetic_storage_size: int | None = Field( - None, - description="The current space occupied by the project in storage, in bytes. Synthetic storage size combines the logical data size and Write-Ahead Log (WAL) size for all branches in a project.\n", - ) - quota_reset_at: AwareDatetime | None = Field( - None, - description="DEPRECATED. Use `consumption_period_end` from the getProject endpoint instead.\nA timestamp indicating when the project quota resets\n", - ) + pg_version: Annotated[ + int, + Field( + description="The major PostgreSQL version number. Currently supported versions are `14`, `15` and `16`.", + ge=14, + le=16, + ), + ] + proxy_host: Annotated[ + str, + Field( + description="The proxy host for the project. This value combines the `region_id`, the `platform_id`, and the Neon domain (`neon.tech`).\n" + ), + ] + branch_logical_size_limit: Annotated[ + int, + Field( + description="The logical size limit for a branch. The value is in MiB.\n" + ), + ] + branch_logical_size_limit_bytes: Annotated[ + int, + Field(description="The logical size limit for a branch. The value is in B.\n"), + ] + store_passwords: Annotated[ + bool, + Field( + description="Whether or not passwords are stored for roles in the Neon project. Storing passwords facilitates access to Neon features that require authorization.\n" + ), + ] + active_time: Annotated[ + int, + Field( + description="Control plane observed endpoints of this project being active this amount of wall-clock time.\n", + ge=0, + ), + ] + cpu_used_sec: Annotated[ + int, + Field( + description="DEPRECATED. Use data from the getProject endpoint instead.\n" + ), + ] + maintenance_starts_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="A timestamp indicating when project maintenance begins. If set, the project is placed into maintenance mode at this time.\n", + ), + ] + creation_source: Annotated[str, Field(description="The project creation source\n")] + created_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the project was created\n"), + ] + updated_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the project was last updated\n"), + ] + synthetic_storage_size: Annotated[ + int | None, + Field( + None, + description="The current space occupied by the project in storage, in bytes. Synthetic storage size combines the logical data size and Write-Ahead Log (WAL) size for all branches in a project.\n", + ), + ] + quota_reset_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="DEPRECATED. Use `consumption_period_end` from the getProject endpoint instead.\nA timestamp indicating when the project quota resets\n", + ), + ] owner_id: str - compute_last_active_at: AwareDatetime | None = Field( - None, - description="The most recent time when any endpoint of this project was active.\n\nOmitted when observed no actitivy for endpoints of this project.\n", - ) + compute_last_active_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="The most recent time when any endpoint of this project was active.\n\nOmitted when observed no actitivy for endpoints of this project.\n", + ), + ] class Project(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - data_storage_bytes_hour: int = Field( - ..., - description="Bytes-Hour. Project consumed that much storage hourly during the billing period. The value has some lag.\nThe value is reset at the beginning of each billing period.\n", - ge=0, - ) - data_transfer_bytes: int = Field( - ..., - description="Bytes. Egress traffic from the Neon cloud to the client for given project over the billing period.\nIncludes deleted endpoints. The value has some lag. The value is reset at the beginning of each billing period.\n", - ge=0, - ) - written_data_bytes: int = Field( - ..., - description="Bytes. Amount of WAL that travelled through storage for given project across all branches.\nThe value has some lag. The value is reset at the beginning of each billing period.\n", - ge=0, - ) - compute_time_seconds: int = Field( - ..., - description="Seconds. The number of CPU seconds used by the project's compute endpoints, including compute endpoints that have been deleted.\nThe value has some lag. The value is reset at the beginning of each billing period.\nExamples:\n1. An endpoint that uses 1 CPU for 1 second is equal to `compute_time=1`.\n2. An endpoint that uses 2 CPUs simultaneously for 1 second is equal to `compute_time=2`.\n", - ge=0, - ) - active_time_seconds: int = Field( - ..., - description="Seconds. Control plane observed endpoints of this project being active this amount of wall-clock time.\nThe value has some lag.\nThe value is reset at the beginning of each billing period.\n", - ge=0, - ) - cpu_used_sec: int = Field( - ..., description="DEPRECATED, use compute_time instead.\n" - ) - id: str = Field(..., description="The project ID\n") - platform_id: str = Field( - ..., - description="The cloud platform identifier. Currently, only AWS is supported, for which the identifier is `aws`.\n", - ) - region_id: str = Field(..., description="The region identifier\n") - name: str = Field(..., description="The project name\n") + data_storage_bytes_hour: Annotated[ + int, + Field( + description="Bytes-Hour. Project consumed that much storage hourly during the billing period. The value has some lag.\nThe value is reset at the beginning of each billing period.\n", + ge=0, + ), + ] + data_transfer_bytes: Annotated[ + int, + Field( + description="Bytes. Egress traffic from the Neon cloud to the client for given project over the billing period.\nIncludes deleted endpoints. The value has some lag. The value is reset at the beginning of each billing period.\n", + ge=0, + ), + ] + written_data_bytes: Annotated[ + int, + Field( + description="Bytes. Amount of WAL that travelled through storage for given project across all branches.\nThe value has some lag. The value is reset at the beginning of each billing period.\n", + ge=0, + ), + ] + compute_time_seconds: Annotated[ + int, + Field( + description="Seconds. The number of CPU seconds used by the project's compute endpoints, including compute endpoints that have been deleted.\nThe value has some lag. The value is reset at the beginning of each billing period.\nExamples:\n1. An endpoint that uses 1 CPU for 1 second is equal to `compute_time=1`.\n2. An endpoint that uses 2 CPUs simultaneously for 1 second is equal to `compute_time=2`.\n", + ge=0, + ), + ] + active_time_seconds: Annotated[ + int, + Field( + description="Seconds. Control plane observed endpoints of this project being active this amount of wall-clock time.\nThe value has some lag.\nThe value is reset at the beginning of each billing period.\n", + ge=0, + ), + ] + cpu_used_sec: Annotated[ + int, Field(description="DEPRECATED, use compute_time instead.\n") + ] + id: Annotated[str, Field(description="The project ID\n")] + platform_id: Annotated[ + str, + Field( + description="The cloud platform identifier. Currently, only AWS is supported, for which the identifier is `aws`.\n" + ), + ] + region_id: Annotated[str, Field(description="The region identifier\n")] + name: Annotated[str, Field(description="The project name\n")] provisioner: Provisioner default_endpoint_settings: DefaultEndpointSettings | None = None settings: ProjectSettingsData | None = None - pg_version: PgVersion - proxy_host: str = Field( - ..., - description="The proxy host for the project. This value combines the `region_id`, the `platform_id`, and the Neon domain (`neon.tech`).\n", - ) - branch_logical_size_limit: int = Field( - ..., description="The logical size limit for a branch. The value is in MiB.\n" - ) - branch_logical_size_limit_bytes: int = Field( - ..., description="The logical size limit for a branch. The value is in B.\n" - ) - store_passwords: bool = Field( - ..., - description="Whether or not passwords are stored for roles in the Neon project. Storing passwords facilitates access to Neon features that require authorization.\n", - ) - maintenance_starts_at: AwareDatetime | None = Field( - None, - description="A timestamp indicating when project maintenance begins. If set, the project is placed into maintenance mode at this time.\n", - ) - creation_source: str = Field(..., description="The project creation source\n") - history_retention_seconds: int = Field( - ..., - description="The number of seconds to retain point-in-time restore (PITR) backup history for this project.\n", - ) - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the project was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the project was last updated\n" - ) - synthetic_storage_size: int | None = Field( - None, - description="The current space occupied by the project in storage, in bytes. Synthetic storage size combines the logical data size and Write-Ahead Log (WAL) size for all branches in a project.\n", - ) - consumption_period_start: AwareDatetime = Field( - ..., - description="A date-time indicating when Neon Cloud started measuring consumption for current consumption period.\n", - ) - consumption_period_end: AwareDatetime = Field( - ..., - description="A date-time indicating when Neon Cloud plans to stop measuring consumption for current consumption period.\n", - ) - quota_reset_at: AwareDatetime | None = Field( - None, - description="DEPRECATED. Use `consumption_period_end` from the getProject endpoint instead.\nA timestamp indicating when the project quota resets.\n", - ) + pg_version: Annotated[ + int, + Field( + description="The major PostgreSQL version number. Currently supported versions are `14`, `15` and `16`.", + ge=14, + le=16, + ), + ] + proxy_host: Annotated[ + str, + Field( + description="The proxy host for the project. This value combines the `region_id`, the `platform_id`, and the Neon domain (`neon.tech`).\n" + ), + ] + branch_logical_size_limit: Annotated[ + int, + Field( + description="The logical size limit for a branch. The value is in MiB.\n" + ), + ] + branch_logical_size_limit_bytes: Annotated[ + int, + Field(description="The logical size limit for a branch. The value is in B.\n"), + ] + store_passwords: Annotated[ + bool, + Field( + description="Whether or not passwords are stored for roles in the Neon project. Storing passwords facilitates access to Neon features that require authorization.\n" + ), + ] + maintenance_starts_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="A timestamp indicating when project maintenance begins. If set, the project is placed into maintenance mode at this time.\n", + ), + ] + creation_source: Annotated[str, Field(description="The project creation source\n")] + history_retention_seconds: Annotated[ + int, + Field( + description="The number of seconds to retain point-in-time restore (PITR) backup history for this project.\n" + ), + ] + created_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the project was created\n"), + ] + updated_at: Annotated[ + AwareDatetime, + Field(description="A timestamp indicating when the project was last updated\n"), + ] + synthetic_storage_size: Annotated[ + int | None, + Field( + None, + description="The current space occupied by the project in storage, in bytes. Synthetic storage size combines the logical data size and Write-Ahead Log (WAL) size for all branches in a project.\n", + ), + ] + consumption_period_start: Annotated[ + AwareDatetime, + Field( + description="A date-time indicating when Neon Cloud started measuring consumption for current consumption period.\n" + ), + ] + consumption_period_end: Annotated[ + AwareDatetime, + Field( + description="A date-time indicating when Neon Cloud plans to stop measuring consumption for current consumption period.\n" + ), + ] + quota_reset_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="DEPRECATED. Use `consumption_period_end` from the getProject endpoint instead.\nA timestamp indicating when the project quota resets.\n", + ), + ] owner_id: str owner: ProjectOwnerData | None = None - compute_last_active_at: AwareDatetime | None = Field( - None, - description="The most recent time when any endpoint of this project was active.\n\nOmitted when observed no actitivy for endpoints of this project.\n", - ) + compute_last_active_at: Annotated[ + AwareDatetime | None, + Field( + None, + description="The most recent time when any endpoint of this project was active.\n\nOmitted when observed no actitivy for endpoints of this project.\n", + ), + ] class Project1(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) settings: ProjectSettingsData | None = None - name: str | None = Field(None, description="The project name") + name: Annotated[str | None, Field(None, description="The project name")] branch: Branch | None = None - autoscaling_limit_min_cu: ComputeUnit | None = Field( - None, - description="DEPRECATED, use default_endpoint_settings.autoscaling_limit_min_cu instead.\n\nThe minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - autoscaling_limit_max_cu: ComputeUnit | None = Field( - None, - description="DEPRECATED, use default_endpoint_settings.autoscaling_limit_max_cu instead.\n\nThe maximum number of Compute Units. See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) + autoscaling_limit_min_cu: Annotated[ + float | None, + Field( + None, + description="DEPRECATED, use default_endpoint_settings.autoscaling_limit_min_cu instead.\n\nThe minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", + ge=0.25, + ), + ] + autoscaling_limit_max_cu: Annotated[ + float | None, + Field( + None, + description="DEPRECATED, use default_endpoint_settings.autoscaling_limit_max_cu instead.\n\nThe maximum number of Compute Units. See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", + ge=0.25, + ), + ] provisioner: Provisioner | None = None - region_id: str | None = Field( - None, - description="The region identifier. Refer to our [Regions](https://neon.tech/docs/introduction/regions) documentation for supported regions. Values are specified in this format: `aws-us-east-1`\n", - ) + region_id: Annotated[ + str | None, + Field( + None, + description="The region identifier. Refer to our [Regions](https://neon.tech/docs/introduction/regions) documentation for supported regions. Values are specified in this format: `aws-us-east-1`\n", + ), + ] default_endpoint_settings: DefaultEndpointSettings | None = None - pg_version: PgVersion | None = None - store_passwords: bool | None = Field( - None, - description="Whether or not passwords are stored for roles in the Neon project. Storing passwords facilitates access to Neon features that require authorization.\n", - ) - history_retention_seconds: int | None = Field( - None, - description="The number of seconds to retain the point-in-time restore (PITR) backup history for this project.\nThe default is 604800 seconds (7 days).\n", - ge=0, - le=2592000, - ) + pg_version: Annotated[ + int | None, + Field( + None, + description="The major PostgreSQL version number. Currently supported versions are `14`, `15` and `16`.", + ge=14, + le=16, + ), + ] + store_passwords: Annotated[ + bool | None, + Field( + None, + description="Whether or not passwords are stored for roles in the Neon project. Storing passwords facilitates access to Neon features that require authorization.\n", + ), + ] + history_retention_seconds: Annotated[ + int | None, + Field( + None, + description="The number of seconds to retain the point-in-time restore (PITR) backup history for this project.\nThe default is 604800 seconds (7 days).\n", + ge=0, + le=2592000, + ), + ] class ProjectCreateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) project: Project1 @@ -1254,21 +1539,26 @@ class ProjectCreateRequest(BaseModel): class Project2(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) settings: ProjectSettingsData | None = None - name: str | None = Field(None, description="The project name") + name: Annotated[str | None, Field(None, description="The project name")] default_endpoint_settings: DefaultEndpointSettings | None = None - history_retention_seconds: int | None = Field( - None, - description="The number of seconds to retain the point-in-time restore (PITR) backup history for this project.\nThe default is 604800 seconds (7 days).\n", - ge=0, - le=2592000, - ) + history_retention_seconds: Annotated[ + int | None, + Field( + None, + description="The number of seconds to retain the point-in-time restore (PITR) backup history for this project.\nThe default is 604800 seconds (7 days).\n", + ge=0, + le=2592000, + ), + ] class ProjectUpdateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) project: Project2 @@ -1276,6 +1566,7 @@ class ProjectUpdateRequest(BaseModel): class ProjectResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) project: Project @@ -1283,6 +1574,7 @@ class ProjectResponse(BaseModel): class ProjectsResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) projects: list[ProjectListItem] @@ -1290,110 +1582,170 @@ class ProjectsResponse(BaseModel): class Endpoint(BaseModel): model_config = ConfigDict( - populate_by_name=True, + extra="allow", populate_by_name=True, use_enum_values=True ) - host: str = Field( - ..., - description="The hostname of the compute endpoint. This is the hostname specified when connecting to a Neon database.\n", - ) - id: str = Field( - ..., - description="The compute endpoint ID. Compute endpoint IDs have an `ep-` prefix. For example: `ep-little-smoke-851426`\n", - ) - project_id: str = Field( - ..., description="The ID of the project to which the compute endpoint belongs\n" - ) - branch_id: str = Field( - ..., - description="The ID of the branch that the compute endpoint is associated with\n", - ) - autoscaling_limit_min_cu: ComputeUnit = Field( - ..., description="The minimum number of Compute Units\n" - ) - autoscaling_limit_max_cu: ComputeUnit = Field( - ..., description="The maximum number of Compute Units\n" - ) - region_id: str = Field(..., description="The region identifier\n") + host: Annotated[ + str, + Field( + description="The hostname of the compute endpoint. This is the hostname specified when connecting to a Neon database.\n" + ), + ] + id: Annotated[ + str, + Field( + description="The compute endpoint ID. Compute endpoint IDs have an `ep-` prefix. For example: `ep-little-smoke-851426`\n" + ), + ] + project_id: Annotated[ + str, + Field( + description="The ID of the project to which the compute endpoint belongs\n" + ), + ] + branch_id: Annotated[ + str, + Field( + description="The ID of the branch that the compute endpoint is associated with\n" + ), + ] + autoscaling_limit_min_cu: Annotated[ + float, Field(description="The minimum number of Compute Units\n", ge=0.25) + ] + autoscaling_limit_max_cu: Annotated[ + float, Field(description="The maximum number of Compute Units\n", ge=0.25) + ] + region_id: Annotated[str, Field(description="The region identifier\n")] type: EndpointType current_state: EndpointState pending_state: EndpointState | None = None settings: EndpointSettingsData - pooler_enabled: bool = Field( - ..., - description="Whether connection pooling is enabled for the compute endpoint\n", - ) + pooler_enabled: Annotated[ + bool, + Field( + description="Whether connection pooling is enabled for the compute endpoint\n" + ), + ] pooler_mode: EndpointPoolerMode - disabled: bool = Field( - ..., - description="Whether to restrict connections to the compute endpoint.\nEnabling this option schedules a suspend compute operation.\nA disabled compute endpoint cannot be enabled by a connection or\nconsole action. However, the compute endpoint is periodically\nenabled by check_availability operations.\n", - ) - passwordless_access: bool = Field( - ..., - description="Whether to permit passwordless access to the compute endpoint\n", - ) - last_active: AwareDatetime | None = Field( - None, - description="A timestamp indicating when the compute endpoint was last active\n", - ) - creation_source: str = Field( - ..., description="The compute endpoint creation source\n" - ) - created_at: AwareDatetime = Field( - ..., - description="A timestamp indicating when the compute endpoint was created\n", - ) - updated_at: AwareDatetime = Field( - ..., - description="A timestamp indicating when the compute endpoint was last updated\n", - ) - proxy_host: str = Field( - ..., description='DEPRECATED. Use the "host" property instead.\n' - ) - suspend_timeout_seconds: SuspendTimeoutSeconds + disabled: Annotated[ + bool, + Field( + description="Whether to restrict connections to the compute endpoint.\nEnabling this option schedules a suspend compute operation.\nA disabled compute endpoint cannot be enabled by a connection or\nconsole action. However, the compute endpoint is periodically\nenabled by check_availability operations.\n" + ), + ] + passwordless_access: Annotated[ + bool, + Field( + description="Whether to permit passwordless access to the compute endpoint\n" + ), + ] + last_active: Annotated[ + AwareDatetime | None, + Field( + None, + description="A timestamp indicating when the compute endpoint was last active\n", + ), + ] + creation_source: Annotated[ + str, Field(description="The compute endpoint creation source\n") + ] + created_at: Annotated[ + AwareDatetime, + Field( + description="A timestamp indicating when the compute endpoint was created\n" + ), + ] + updated_at: Annotated[ + AwareDatetime, + Field( + description="A timestamp indicating when the compute endpoint was last updated\n" + ), + ] + proxy_host: Annotated[ + str, Field(description='DEPRECATED. Use the "host" property instead.\n') + ] + suspend_timeout_seconds: Annotated[ + int, + Field( + description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", + ge=-1, + le=604800, + ), + ] provisioner: Provisioner class Endpoint1(BaseModel): model_config = ConfigDict( - populate_by_name=True, - ) - branch_id: str = Field( - ..., - description="The ID of the branch the compute endpoint will be associated with\n", - ) - region_id: str | None = Field( - None, - description="The region where the compute endpoint will be created. Only the project's `region_id` is permitted.\n", + extra="allow", populate_by_name=True, use_enum_values=True ) + branch_id: Annotated[ + str, + Field( + description="The ID of the branch the compute endpoint will be associated with\n" + ), + ] + region_id: Annotated[ + str | None, + Field( + None, + description="The region where the compute endpoint will be created. Only the project's `region_id` is permitted.\n", + ), + ] type: EndpointType settings: EndpointSettingsData | None = None - autoscaling_limit_min_cu: ComputeUnit | None = Field( - None, - description="The minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - autoscaling_limit_max_cu: ComputeUnit | None = Field( - None, - description="The maximum number of Compute Units.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) + autoscaling_limit_min_cu: Annotated[ + float | None, + Field( + None, + description="The minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", + ge=0.25, + ), + ] + autoscaling_limit_max_cu: Annotated[ + float | None, + Field( + None, + description="The maximum number of Compute Units.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", + ge=0.25, + ), + ] provisioner: Provisioner | None = None - pooler_enabled: bool | None = Field( - None, - description="Whether to enable connection pooling for the compute endpoint\n", - ) + pooler_enabled: Annotated[ + bool | None, + Field( + None, + description="Whether to enable connection pooling for the compute endpoint\n", + ), + ] pooler_mode: EndpointPoolerMode | None = None - disabled: bool | None = Field( - None, - description="Whether to restrict connections to the compute endpoint.\nEnabling this option schedules a suspend compute operation.\nA disabled compute endpoint cannot be enabled by a connection or\nconsole action. However, the compute endpoint is periodically\nenabled by check_availability operations.\n", - ) - passwordless_access: bool | None = Field( - None, - description="NOT YET IMPLEMENTED. Whether to permit passwordless access to the compute endpoint.\n", - ) - suspend_timeout_seconds: SuspendTimeoutSeconds | None = None + disabled: Annotated[ + bool | None, + Field( + None, + description="Whether to restrict connections to the compute endpoint.\nEnabling this option schedules a suspend compute operation.\nA disabled compute endpoint cannot be enabled by a connection or\nconsole action. However, the compute endpoint is periodically\nenabled by check_availability operations.\n", + ), + ] + passwordless_access: Annotated[ + bool | None, + Field( + None, + description="NOT YET IMPLEMENTED. Whether to permit passwordless access to the compute endpoint.\n", + ), + ] + suspend_timeout_seconds: Annotated[ + int | None, + Field( + None, + description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", + ge=-1, + le=604800, + ), + ] class EndpointCreateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) endpoint: Endpoint1 @@ -1401,40 +1753,70 @@ class EndpointCreateRequest(BaseModel): class Endpoint2(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) - branch_id: str | None = Field( - None, - description="The destination branch ID. The destination branch must not have an exsiting read-write endpoint.\n", - ) - autoscaling_limit_min_cu: ComputeUnit | None = Field( - None, - description="The minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - autoscaling_limit_max_cu: ComputeUnit | None = Field( - None, - description="The maximum number of Compute Units.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) + branch_id: Annotated[ + str | None, + Field( + None, + description="The destination branch ID. The destination branch must not have an exsiting read-write endpoint.\n", + ), + ] + autoscaling_limit_min_cu: Annotated[ + float | None, + Field( + None, + description="The minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", + ge=0.25, + ), + ] + autoscaling_limit_max_cu: Annotated[ + float | None, + Field( + None, + description="The maximum number of Compute Units.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", + ge=0.25, + ), + ] provisioner: Provisioner | None = None settings: EndpointSettingsData | None = None - pooler_enabled: bool | None = Field( - None, - description="Whether to enable connection pooling for the compute endpoint\n", - ) + pooler_enabled: Annotated[ + bool | None, + Field( + None, + description="Whether to enable connection pooling for the compute endpoint\n", + ), + ] pooler_mode: EndpointPoolerMode | None = None - disabled: bool | None = Field( - None, - description="Whether to restrict connections to the compute endpoint.\nEnabling this option schedules a suspend compute operation.\nA disabled compute endpoint cannot be enabled by a connection or\nconsole action. However, the compute endpoint is periodically\nenabled by check_availability operations.\n", - ) - passwordless_access: bool | None = Field( - None, - description="NOT YET IMPLEMENTED. Whether to permit passwordless access to the compute endpoint.\n", - ) - suspend_timeout_seconds: SuspendTimeoutSeconds | None = None + disabled: Annotated[ + bool | None, + Field( + None, + description="Whether to restrict connections to the compute endpoint.\nEnabling this option schedules a suspend compute operation.\nA disabled compute endpoint cannot be enabled by a connection or\nconsole action. However, the compute endpoint is periodically\nenabled by check_availability operations.\n", + ), + ] + passwordless_access: Annotated[ + bool | None, + Field( + None, + description="NOT YET IMPLEMENTED. Whether to permit passwordless access to the compute endpoint.\n", + ), + ] + suspend_timeout_seconds: Annotated[ + int | None, + Field( + None, + description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", + ge=-1, + le=604800, + ), + ] class EndpointUpdateRequest(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) endpoint: Endpoint2 @@ -1442,6 +1824,7 @@ class EndpointUpdateRequest(BaseModel): class EndpointResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) endpoint: Endpoint @@ -1449,6 +1832,7 @@ class EndpointResponse(BaseModel): class EndpointsResponse(BaseModel): model_config = ConfigDict( + extra="allow", populate_by_name=True, ) endpoints: list[Endpoint] @@ -1457,5 +1841,6 @@ class EndpointsResponse(BaseModel): class EndpointOperations(EndpointResponse, OperationsResponse): pass model_config = ConfigDict( + extra="allow", populate_by_name=True, ) diff --git a/neon_client/resources.py b/neon_client/resources.py index 573d4fb..a574d8c 100644 --- a/neon_client/resources.py +++ b/neon_client/resources.py @@ -1,4 +1,5 @@ from typing import List +from fastapi.encoders import jsonable_encoder from .http_client import Neon_API_V2 from .openapi_models import ( @@ -23,6 +24,11 @@ from .openapi_models import ( OperationResponse, OperationsResponse, PaginationResponse, + Branch, + Branch2, + Branch3, + BranchCreateRequestEndpointOptions, + BranchCreateRequest, ) from .utils import validate_obj_model @@ -33,6 +39,12 @@ class PagedOperationsResponse(OperationsResponse, PaginationResponse): pass +class PagedProjectsResponse(ProjectsResponse, PaginationResponse): + """A response containing a list of projects and pagination information.""" + + pass + + class Resource: base_path = None @@ -44,15 +56,14 @@ class UserResource(Resource): """A resource for interacting with users.""" base_path = "users" - response_model = CurrentUserInfoResponse def get_current_user_info(self): """Get information about the user.""" return self.api.request( method="GET", - path=self.api.url_join(self.path, "me"), - response_model=self.response_model, + path=self.api.url_join(self.base_path, "me"), + response_model=CurrentUserInfoResponse, ) @@ -95,43 +106,51 @@ class ProjectResource(Resource): """A resource for interacting with projects.""" base_path = "projects" - response_model = ProjectsResponse - response_model_single = ProjectResponse - def get_list(self, *, shared=False): + def get_list( + self, + *, + cursor: int | None = None, + limit: int | None = None, + shared: bool = False + ): """Get a list of projects.""" - project_response = self.api.request( + project_params = {} + if cursor is not None: + project_params["cursor"] = cursor + if limit is not None: + project_params["limit"] = limit + + return self.api.request( method="GET", path=( self.api.url_join(self.base_path, "shared") if shared else self.base_path ), - response_model=self.response_model, + params=project_params, + response_model=PagedProjectsResponse, ) - return project_response.projects def get(self, project_id: str): """Get a project.""" - project_response = self.api.request( + return self.api.request( method="GET", path=self.api.url_join(self.base_path, project_id), - response_model=self.response_model_single, + response_model=ProjectResponse, ) - return project_response.project - def create(self, name: str, **kwargs): - """Create a new project.""" + # def create(self, name: str, **kwargs): + # """Create a new project.""" - project_create_response = self.api.request( - method="POST", - path=self.base_path, - json={"project": {"name": name, **kwargs}}, - response_model=self.response_model_single, - ) - return project_create_response.project + # return self.api.request( + # method="POST", + # path=self.base_path, + # json={"project": {"name": name, **kwargs}}, + # response_model=ProjectResponse, + # ).model_dump() def update(self, project: Project): """Update a project.""" @@ -142,7 +161,7 @@ class ProjectResource(Resource): method="PATCH", path=self.api.url_join(self.base_path, project.id), json={"project": payload.model_dump()}, - response_model=self.response_model_single, + response_model=ProjectResponse, ) def delete(self, project_id: str): @@ -151,14 +170,12 @@ class ProjectResource(Resource): return self.api.request( method="DELETE", path=self.api.url_join(self.base_path, project_id), - response_model=self.response_model_single, + response_model=ProjectResponse, ) class DatabaseResource(Resource): base_path = "databases" - response_model = DatabasesResponse - response_model_single = DatabaseResponse def _extract_database(self, obj): """Extract a database from the specified object.""" @@ -189,7 +206,7 @@ class DatabaseResource(Resource): "projects", project_id, "branches", branch_id, "databases" ), response_model=DatabasesResponse, - ).model_dump() + ) def get( self, @@ -210,7 +227,7 @@ class DatabaseResource(Resource): database_name, ), response_model=DatabaseResponse, - ).model_dump() + ) def create( self, @@ -227,9 +244,9 @@ class DatabaseResource(Resource): path=self.api.url_join( "projects", project_id, "branches", branch_id, "databases" ), - json=DatabaseCreateRequest(database=db).model_dump(), + json=jsonable_encoder(DatabaseCreateRequest(database=db)), response_model=DatabaseResponse, - ).model_dump() + ) def update( self, @@ -249,15 +266,13 @@ class DatabaseResource(Resource): ), json=DatabaseUpdateRequest(database=db).model_dump(), response_model=DatabaseResponse, - ).model_dump() + ) class BranchResource(Resource): """A resource for interacting with branches.""" path = "branches" - response_model = BranchesResponse - response_model_single = BranchResponse def get_list(self, project_id: str): """Get a list of branches.""" @@ -265,8 +280,8 @@ class BranchResource(Resource): return self.api.request( method="GET", path=self.api.url_join("projects", project_id, "branches"), - response_model=self.response_model, - ).model_dump() + response_model=BranchesResponse, + ) def get(self, project_id: str, branch_id: str): """Get a branch.""" @@ -274,8 +289,18 @@ class BranchResource(Resource): return self.api.request( method="GET", path=self.api.url_join("projects", project_id, "branches", branch_id), - response_model=self.response_model_single, - ).model_dump() + response_model=BranchResponse, + ) + + def create(self, project_id: str, request: BranchCreateRequest): + """Create a new branch.""" + + return self.api.request( + method="POST", + path=self.api.url_join("projects", project_id, "branches"), + json=request.model_dump(), + response_model=BranchResponse, + ) class OperationResource(Resource): @@ -302,7 +327,7 @@ class OperationResource(Resource): path=self.api.url_join("projects", project_id, "operations"), params=operations_params, response_model=PagedOperationsResponse, - ).model_dump() + ) def get(self, project_id: str, operation_id: str): """Get an operation.""" @@ -311,13 +336,15 @@ class OperationResource(Resource): method="GET", path=self.api.url_join("projects", project_id, "operations", operation_id), response_model=OperationResponse, - ).model_dump() + ) class ResourceCollection: """A collection of resources.""" def __init__(self, api: Neon_API_V2): + """Initialize the collection.""" + # Initialize resources. self.api_keys = APIKeyResource(api) self.users = UserResource(api) diff --git a/neon_client/v2_client.py b/neon_client/v2_client.py index 6aa79ae..d9644f0 100644 --- a/neon_client/v2_client.py +++ b/neon_client/v2_client.py @@ -1,13 +1,90 @@ from .http_client import Neon_API_V2 from .resources import ResourceCollection +from . import openapi_models + + +class BaseNeonItem: + def __repr__(self): + return str(self) + + +class NeonUser(BaseNeonItem, openapi_models.CurrentUserAuthAccount): + @classmethod + def from_get_response(cls, r): + """Create a NeonUser from an API response.""" + + # TODO: is this the right way to do this? + me = r.auth_accounts[0] + + return cls.model_validate(me.model_dump()) + + def __str__(self): + return f"" + + +class CollectionView: + def __init__(self, collection, key_ids=None): + if not key_ids: + key_ids = [] + + self._key_ids = key_ids + self._collection = collection + + def __iter__(self): + return iter(self._collection) + + def __getitem__(self, key): + for k in key_ids: + for item in self._collection: + if getattr(item, k) == key: + return item + + return self._collection[key] + + def __len__(self): + return len(self._collection) + + def __repr__(self): + return repr(self._collection) + + +class NeonAPIKey(BaseNeonItem, openapi_models.ApiKeysListResponseItem): + @classmethod + def from_list_response(cls, r, *, neon): + """Create a list of APIKeys from an API response.""" + + def gen(): + for key in r: + k = cls.model_validate(key.model_dump()) + k.neon = neon + + yield k + + return [g for g in gen()] + + def __str__(self): + return f"" + + def revoke(self, *, neon): + """Revoke this API key.""" + + return bool(neon.resources.api_keys.revoke(self.id)) + class NeonClient: def __init__(self, api_key: str, **kwargs): self.api = Neon_API_V2(api_key, **kwargs) self.resources = ResourceCollection(self.api) - # self.api_keys = APIKeyResource(self.api) - # self.users = UserResource(self.api) - # self.projects = ProjectResource(self.api) - # self.databases = DatabaseResource(self.api) + @property + def me(self): + user = self.resources.users.get_current_user_info() + return NeonUser.from_get_response(user) + + @property + def api_keys(self): + keys = self.resources.api_keys.get_list() + return CollectionView( + NeonAPIKey.from_list_response(keys, neon=self), key_ids=["id"] + )