Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.44.0"
".": "0.45.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 657
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/gcore%2Fgcore-8c3bd3792724737d30da0f0200f0c589f9942ea3a028fcc9bcd56f3490ffc29a.yml
openapi_spec_hash: 7b184f4e52554b89cadf11b43f395583
config_hash: aa5a9dd05b6324fcb454d0694e5901a3
openapi_spec_hash: 426e01a73386f9de9841899806ddb3e3
config_hash: 22eb06625c071a1a8620647d9cc56df3
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 0.45.0 (2026-04-28)

Full Changelog: [v0.44.0...v0.45.0](https://github.com/G-Core/gcore-python/compare/v0.44.0...v0.45.0)

### ⚠ BREAKING CHANGES

* **cloud:** correct pg conf validation response model name

### Features

* support setting headers via env ([48f6c89](https://github.com/G-Core/gcore-python/commit/48f6c89a1755f00ee53c9764273e937864c59666))


### Bug Fixes

* **cloud:** correct pg conf validation response model name ([c5bc635](https://github.com/G-Core/gcore-python/commit/c5bc635407def6e004bdb94a24e9045a1f8cf416))
* use correct field name format for multipart file arrays ([5db7792](https://github.com/G-Core/gcore-python/commit/5db779213e0c088d2a615dccd43e0f7ca94bea1a))

## 0.44.0 (2026-04-27)

Full Changelog: [v0.43.0...v0.44.0](https://github.com/G-Core/gcore-python/compare/v0.43.0...v0.44.0)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "gcore"
version = "0.44.0"
version = "0.45.0"
description = "The official Python library for the gcore API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
25 changes: 24 additions & 1 deletion src/gcore/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
RequestOptions,
not_given,
)
from ._utils import is_given, get_async_library, maybe_coerce_integer
from ._utils import (
is_given,
is_mapping_t,
get_async_library,
maybe_coerce_integer,
)
from ._compat import cached_property
from ._version import __version__
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
Expand Down Expand Up @@ -116,6 +121,15 @@ def __init__(
if base_url is None:
base_url = f"https://api.gcore.com"

custom_headers_env = os.environ.get("GCORE_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down Expand Up @@ -395,6 +409,15 @@ def __init__(
if base_url is None:
base_url = f"https://api.gcore.com"

custom_headers_env = os.environ.get("GCORE_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down
8 changes: 2 additions & 6 deletions src/gcore/_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

from typing import Any, List, Tuple, Union, Mapping, TypeVar
from urllib.parse import parse_qs, urlencode
from typing_extensions import Literal, get_args
from typing_extensions import get_args

from ._types import NotGiven, not_given
from ._types import NotGiven, ArrayFormat, NestedFormat, not_given
from ._utils import flatten

_T = TypeVar("_T")


ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
NestedFormat = Literal["dots", "brackets"]

PrimitiveData = Union[str, int, float, bool, None]
# this should be Data = Union[PrimitiveData, "List[Data]", "Tuple[Data]", "Mapping[str, Data]"]
# https://github.com/microsoft/pyright/issues/3555
Expand Down
3 changes: 3 additions & 0 deletions src/gcore/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
ModelT = TypeVar("ModelT", bound=pydantic.BaseModel)
_T = TypeVar("_T")

ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
NestedFormat = Literal["dots", "brackets"]


# Approximates httpx internal ProxiesTypes and RequestFiles types
# while adding support for `PathLike` instances
Expand Down
42 changes: 34 additions & 8 deletions src/gcore/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
)
from pathlib import Path
from datetime import date, datetime
from typing_extensions import TypeGuard
from typing_extensions import TypeGuard, get_args

import sniffio

from .._types import Omit, NotGiven, FileTypes, HeadersLike
from .._types import Omit, NotGiven, FileTypes, ArrayFormat, HeadersLike

_T = TypeVar("_T")
_TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
Expand All @@ -40,25 +40,45 @@ def extract_files(
query: Mapping[str, object],
*,
paths: Sequence[Sequence[str]],
array_format: ArrayFormat = "brackets",
) -> list[tuple[str, FileTypes]]:
"""Recursively extract files from the given dictionary based on specified paths.

A path may look like this ['foo', 'files', '<array>', 'data'].

``array_format`` controls how ``<array>`` segments contribute to the emitted
field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"`` and
``"comma"`` (``foo``), ``"indices"`` (``foo[0]``, ``foo[1]``).

Note: this mutates the given dictionary.
"""
files: list[tuple[str, FileTypes]] = []
for path in paths:
files.extend(_extract_items(query, path, index=0, flattened_key=None))
files.extend(_extract_items(query, path, index=0, flattened_key=None, array_format=array_format))
return files


def _array_suffix(array_format: ArrayFormat, array_index: int) -> str:
if array_format == "brackets":
return "[]"
if array_format == "indices":
return f"[{array_index}]"
if array_format == "repeat" or array_format == "comma":
# Both repeat the bare field name for each file part; there is no
# meaningful way to comma-join binary parts.
return ""
raise NotImplementedError(
f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}"
)


def _extract_items(
obj: object,
path: Sequence[str],
*,
index: int,
flattened_key: str | None,
array_format: ArrayFormat,
) -> list[tuple[str, FileTypes]]:
try:
key = path[index]
Expand All @@ -75,9 +95,11 @@ def _extract_items(

if is_list(obj):
files: list[tuple[str, FileTypes]] = []
for entry in obj:
assert_is_file_content(entry, key=flattened_key + "[]" if flattened_key else "")
files.append((flattened_key + "[]", cast(FileTypes, entry)))
for array_index, entry in enumerate(obj):
suffix = _array_suffix(array_format, array_index)
emitted_key = (flattened_key + suffix) if flattened_key else suffix
assert_is_file_content(entry, key=emitted_key)
files.append((emitted_key, cast(FileTypes, entry)))
return files

assert_is_file_content(obj, key=flattened_key)
Expand Down Expand Up @@ -106,6 +128,7 @@ def _extract_items(
path,
index=index,
flattened_key=flattened_key,
array_format=array_format,
)
elif is_list(obj):
if key != "<array>":
Expand All @@ -117,9 +140,12 @@ def _extract_items(
item,
path,
index=index,
flattened_key=flattened_key + "[]" if flattened_key is not None else "[]",
flattened_key=(
(flattened_key if flattened_key is not None else "") + _array_suffix(array_format, array_index)
),
array_format=array_format,
)
for item in obj
for array_index, item in enumerate(obj)
]
)

Expand Down
2 changes: 1 addition & 1 deletion src/gcore/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "gcore"
__version__ = "0.44.0" # x-release-please-version
__version__ = "0.45.0" # x-release-please-version
4 changes: 2 additions & 2 deletions src/gcore/resources/cloud/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1190,12 +1190,12 @@ Methods:
Types:

```python
from gcore.types.cloud.databases.postgres import CustomConfigurationValidateResponse
from gcore.types.cloud.databases.postgres import PgConfValidation
```

Methods:

- <code title="post /cloud/v1/dbaas/postgres/validate_pg_conf/{project_id}/{region_id}">client.cloud.databases.postgres.custom_configurations.<a href="./src/gcore/resources/cloud/databases/postgres/custom_configurations.py">validate</a>(\*, project_id, region_id, \*\*<a href="src/gcore/types/cloud/databases/postgres/custom_configuration_validate_params.py">params</a>) -> <a href="./src/gcore/types/cloud/databases/postgres/custom_configuration_validate_response.py">CustomConfigurationValidateResponse</a></code>
- <code title="post /cloud/v1/dbaas/postgres/validate_pg_conf/{project_id}/{region_id}">client.cloud.databases.postgres.custom_configurations.<a href="./src/gcore/resources/cloud/databases/postgres/custom_configurations.py">validate</a>(\*, project_id, region_id, \*\*<a href="src/gcore/types/cloud/databases/postgres/custom_configuration_validate_params.py">params</a>) -> <a href="./src/gcore/types/cloud/databases/postgres/pg_conf_validation.py">PgConfValidation</a></code>

## VolumeSnapshots

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
)
from ....._base_client import make_request_options
from .....types.cloud.databases.postgres import custom_configuration_validate_params
from .....types.cloud.databases.postgres.custom_configuration_validate_response import (
CustomConfigurationValidateResponse,
)
from .....types.cloud.databases.postgres.pg_conf_validation import PgConfValidation

__all__ = ["CustomConfigurationsResource", "AsyncCustomConfigurationsResource"]

Expand Down Expand Up @@ -56,7 +54,7 @@ def validate(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> CustomConfigurationValidateResponse:
) -> PgConfValidation:
"""
Validate a custom PostgreSQL configuration file.

Expand Down Expand Up @@ -97,7 +95,7 @@ def validate(
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=CustomConfigurationValidateResponse,
cast_to=PgConfValidation,
)


Expand Down Expand Up @@ -134,7 +132,7 @@ async def validate(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> CustomConfigurationValidateResponse:
) -> PgConfValidation:
"""
Validate a custom PostgreSQL configuration file.

Expand Down Expand Up @@ -175,7 +173,7 @@ async def validate(
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=CustomConfigurationValidateResponse,
cast_to=PgConfValidation,
)


Expand Down
4 changes: 1 addition & 3 deletions src/gcore/types/cloud/databases/postgres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from __future__ import annotations

from .postgres_cluster import PostgresCluster as PostgresCluster
from .pg_conf_validation import PgConfValidation as PgConfValidation
from .cluster_list_params import ClusterListParams as ClusterListParams
from .cluster_create_params import ClusterCreateParams as ClusterCreateParams
from .cluster_update_params import ClusterUpdateParams as ClusterUpdateParams
from .postgres_cluster_short import PostgresClusterShort as PostgresClusterShort
from .postgres_configuration import PostgresConfiguration as PostgresConfiguration
from .custom_configuration_validate_params import CustomConfigurationValidateParams as CustomConfigurationValidateParams
from .custom_configuration_validate_response import (
CustomConfigurationValidateResponse as CustomConfigurationValidateResponse,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from ....._models import BaseModel

__all__ = ["CustomConfigurationValidateResponse"]
__all__ = ["PgConfValidation"]


class CustomConfigurationValidateResponse(BaseModel):
class PgConfValidation(BaseModel):
errors: List[str]
"""Errors list"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

from gcore import Gcore, AsyncGcore
from tests.utils import assert_matches_type
from gcore.types.cloud.databases.postgres import (
CustomConfigurationValidateResponse,
)
from gcore.types.cloud.databases.postgres import PgConfValidation

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")

Expand All @@ -27,7 +25,7 @@ def test_method_validate(self, client: Gcore) -> None:
pg_conf="\nlisten_addresses = 'localhost'\nport = 5432\nmax_connections = 100\nshared_buffers = 128MB\nlogging_collector = on",
version="15",
)
assert_matches_type(CustomConfigurationValidateResponse, custom_configuration, path=["response"])
assert_matches_type(PgConfValidation, custom_configuration, path=["response"])

@parametrize
def test_raw_response_validate(self, client: Gcore) -> None:
Expand All @@ -41,7 +39,7 @@ def test_raw_response_validate(self, client: Gcore) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
custom_configuration = response.parse()
assert_matches_type(CustomConfigurationValidateResponse, custom_configuration, path=["response"])
assert_matches_type(PgConfValidation, custom_configuration, path=["response"])

@parametrize
def test_streaming_response_validate(self, client: Gcore) -> None:
Expand All @@ -55,7 +53,7 @@ def test_streaming_response_validate(self, client: Gcore) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

custom_configuration = response.parse()
assert_matches_type(CustomConfigurationValidateResponse, custom_configuration, path=["response"])
assert_matches_type(PgConfValidation, custom_configuration, path=["response"])

assert cast(Any, response.is_closed) is True

Expand All @@ -73,7 +71,7 @@ async def test_method_validate(self, async_client: AsyncGcore) -> None:
pg_conf="\nlisten_addresses = 'localhost'\nport = 5432\nmax_connections = 100\nshared_buffers = 128MB\nlogging_collector = on",
version="15",
)
assert_matches_type(CustomConfigurationValidateResponse, custom_configuration, path=["response"])
assert_matches_type(PgConfValidation, custom_configuration, path=["response"])

@parametrize
async def test_raw_response_validate(self, async_client: AsyncGcore) -> None:
Expand All @@ -87,7 +85,7 @@ async def test_raw_response_validate(self, async_client: AsyncGcore) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
custom_configuration = await response.parse()
assert_matches_type(CustomConfigurationValidateResponse, custom_configuration, path=["response"])
assert_matches_type(PgConfValidation, custom_configuration, path=["response"])

@parametrize
async def test_streaming_response_validate(self, async_client: AsyncGcore) -> None:
Expand All @@ -101,6 +99,6 @@ async def test_streaming_response_validate(self, async_client: AsyncGcore) -> No
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

custom_configuration = await response.parse()
assert_matches_type(CustomConfigurationValidateResponse, custom_configuration, path=["response"])
assert_matches_type(PgConfValidation, custom_configuration, path=["response"])

assert cast(Any, response.is_closed) is True
Loading
Loading