Skip to content

Bumps the Python types from the OpenAPI schema #10

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ $ make record

This will record new cassettes for the tests. Make sure to commit these cassettes along with your changes.

### Updating the schema

In order to update the Python data types from the OpenAPI schema, you need to:

```
$ mkdir neon_client/
$ make schema
# Now, take `neon_client/schema.py` and replace `neon_api/schema.py` with it.
# Now, run:
$ make test
# You may have to run `make record` to update the fixtures.
```

## License & Copyright

[Apache 2.0 Licensed](./LICENSE).
36 changes: 1 addition & 35 deletions neon_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def project(self, project_id: str) -> t.Dict[str, t.Any]:

return self._request("GET", r_path)

@returns_model(schema.ConnectionUri)
@returns_model(schema.ConnectionURIResponse)
def connection_uri(
self,
project_id: str,
Expand Down Expand Up @@ -797,37 +797,3 @@ def operation(self, project_id: str, operation_id: str) -> t.Dict[str, t.Any]:
return self._request(
"GET", f"projects/{ project_id }/operations/{ operation_id }"
)

@returns_model(schema.ProjectsConsumptionResponse)
def consumption(
self,
*,
cursor: str = None,
limit: int = None,
from_date: datetime = None,
to_date: datetime = None,
) -> t.Dict[str, t.Any]:
"""Experimental — get a list of consumption metrics for all projects.

:param cursor: The cursor for pagination (default is None).
:param limit: The maximum number of projects to retrieve (default is None).
:param from_date: The start date for the consumption metrics (default is None).
:param to_date: The end date for the consumption metrics (default is None).
:return: A dataclass representing the consumption metrics.

More info: https://api-docs.neon.tech/reference/listprojectsconsumption
"""

# Convert datetime objects to ISO 8601 strings.
from_date = (
to_iso8601(from_date) if isinstance(from_date, datetime) else from_date
)
to_date = to_iso8601(to_date) if isinstance(to_date, datetime) else to_date

# Construct the request parameters.
r_params = compact_mapping(
{"cursor": cursor, "limit": limit, "from": from_date, "to": to_date}
)

# Make the request.
return self._request("GET", "consumption/projects", params=r_params)
Loading
Loading