Skip to content
Draft
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
12 changes: 7 additions & 5 deletions src/auth/src/supabase_auth/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ def __init__(
proxy: Optional[str] = None,
) -> None:
extra_headers = {
"X-Client-Info": f"supabase-py/supabase_auth v{__version__}",
"X-Supabase-Client-Platform": platform.system(),
"X-Supabase-Client-Platform-Version": platform.release(),
"X-Supabase-Client-Runtime": "python",
"X-Supabase-Client-Runtime-Version": platform.python_version(),
"X-Client-Info": (
f"supabase-py/supabase_auth v{__version__}"
f"; platform={platform.system()}"
f"; platform-version={platform.release()}"
f"; runtime=python"
f"; runtime-version={platform.python_version()}"
),
}
if headers:
extra_headers.update(headers)
Expand Down
12 changes: 7 additions & 5 deletions src/auth/src/supabase_auth/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ def __init__(
proxy: Optional[str] = None,
) -> None:
extra_headers = {
"X-Client-Info": f"supabase-py/supabase_auth v{__version__}",
"X-Supabase-Client-Platform": platform.system(),
"X-Supabase-Client-Platform-Version": platform.release(),
"X-Supabase-Client-Runtime": "python",
"X-Supabase-Client-Runtime-Version": platform.python_version(),
"X-Client-Info": (
f"supabase-py/supabase_auth v{__version__}"
f"; platform={platform.system()}"
f"; platform-version={platform.release()}"
f"; runtime=python"
f"; runtime-version={platform.python_version()}"
),
}
if headers:
extra_headers.update(headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ def __init__(
raise ValueError("url must be a valid HTTP URL string")
self.url = URL(url)
self.headers = {
"X-Client-Info": f"supabase-py/supabase_functions v{__version__}",
"X-Supabase-Client-Platform": platform.system(),
"X-Supabase-Client-Platform-Version": platform.release(),
"X-Supabase-Client-Runtime": "python",
"X-Supabase-Client-Runtime-Version": platform.python_version(),
"X-Client-Info": (
f"supabase-py/supabase_functions v{__version__}"
f"; platform={platform.system()}"
f"; platform-version={platform.release()}"
f"; runtime=python"
f"; runtime-version={platform.python_version()}"
),
**headers,
}

Expand Down
12 changes: 7 additions & 5 deletions src/functions/src/supabase_functions/_sync/functions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ def __init__(
raise ValueError("url must be a valid HTTP URL string")
self.url = URL(url)
self.headers = {
"X-Client-Info": f"supabase-py/supabase_functions v{__version__}",
"X-Supabase-Client-Platform": platform.system(),
"X-Supabase-Client-Platform-Version": platform.release(),
"X-Supabase-Client-Runtime": "python",
"X-Supabase-Client-Runtime-Version": platform.python_version(),
"X-Client-Info": (
f"supabase-py/supabase_functions v{__version__}"
f"; platform={platform.system()}"
f"; platform-version={platform.release()}"
f"; runtime=python"
f"; runtime-version={platform.python_version()}"
),
**headers,
}

Expand Down
7 changes: 4 additions & 3 deletions src/functions/tests/_async/test_function_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Dict
from unittest.mock import AsyncMock, Mock, patch

Expand Down Expand Up @@ -36,9 +37,9 @@ async def test_init_with_valid_params(
)
assert str(client.url) == valid_url
assert "X-Client-Info" in client.headers
assert (
client.headers["X-Client-Info"]
== f"supabase-py/supabase_functions v{__version__}"
assert re.match(
rf"^supabase-py/supabase_functions v{re.escape(__version__)}; platform=.+; platform-version=.+; runtime=python; runtime-version=\S+$",
client.headers["X-Client-Info"],
)
assert client._client.timeout == Timeout(10)

Expand Down
7 changes: 4 additions & 3 deletions src/functions/tests/_sync/test_function_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Dict
from unittest.mock import Mock, patch

Expand Down Expand Up @@ -36,9 +37,9 @@ def test_init_with_valid_params(
)
assert str(client.url) == valid_url
assert "X-Client-Info" in client.headers
assert (
client.headers["X-Client-Info"]
== f"supabase-py/supabase_functions v{__version__}"
assert re.match(
rf"^supabase-py/supabase_functions v{re.escape(__version__)}; platform=.+; platform-version=.+; runtime=python; runtime-version=\S+$",
client.headers["X-Client-Info"],
)
assert client._client.timeout == Timeout(10)

Expand Down
28 changes: 28 additions & 0 deletions src/functions/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Dict

import pytest
Expand All @@ -14,6 +15,33 @@ def valid_headers() -> Dict[str, str]:
return {"Authorization": "Bearer test_token", "Content-Type": "application/json"}


_X_CLIENT_INFO_PATTERN = re.compile(
r"^supabase-py/supabase_functions v[\d.]+; platform=.+; platform-version=.+; runtime=python; runtime-version=\S+$"
)


def test_async_x_client_info_structured_format(
valid_url: str, valid_headers: Dict[str, str]
) -> None:
client = AsyncFunctionsClient(url=valid_url, headers=valid_headers)
x_client_info = client.headers.get("X-Client-Info")
assert x_client_info is not None
assert _X_CLIENT_INFO_PATTERN.match(
x_client_info
), f"X-Client-Info format is wrong: {x_client_info}"


def test_sync_x_client_info_structured_format(
valid_url: str, valid_headers: Dict[str, str]
) -> None:
client = SyncFunctionsClient(url=valid_url, headers=valid_headers)
x_client_info = client.headers.get("X-Client-Info")
assert x_client_info is not None
assert _X_CLIENT_INFO_PATTERN.match(
x_client_info
), f"X-Client-Info format is wrong: {x_client_info}"


def test_create_async_client(valid_url: str, valid_headers: Dict[str, str]) -> None:
# Test creating async client with explicit verify=True
client = create_client(
Expand Down
12 changes: 7 additions & 5 deletions src/postgrest/src/postgrest/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ def __init__(
http_client: Optional[AsyncClient] = None,
) -> None:
headers = {
"X-Client-Info": f"supabase-py/postgrest-py v{__version__}",
"X-Supabase-Client-Platform": platform.system(),
"X-Supabase-Client-Platform-Version": platform.release(),
"X-Supabase-Client-Runtime": "python",
"X-Supabase-Client-Runtime-Version": platform.python_version(),
"X-Client-Info": (
f"supabase-py/postgrest-py v{__version__}"
f"; platform={platform.system()}"
f"; platform-version={platform.release()}"
f"; runtime=python"
f"; runtime-version={platform.python_version()}"
),
**headers,
}

Expand Down
12 changes: 7 additions & 5 deletions src/postgrest/src/postgrest/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ def __init__(
http_client: Optional[Client] = None,
) -> None:
headers = {
"X-Client-Info": f"supabase-py/postgrest-py v{__version__}",
"X-Supabase-Client-Platform": platform.system(),
"X-Supabase-Client-Platform-Version": platform.release(),
"X-Supabase-Client-Runtime": "python",
"X-Supabase-Client-Runtime-Version": platform.python_version(),
"X-Client-Info": (
f"supabase-py/postgrest-py v{__version__}"
f"; platform={platform.system()}"
f"; platform-version={platform.release()}"
f"; runtime=python"
f"; runtime-version={platform.python_version()}"
),
**headers,
}

Expand Down
11 changes: 11 additions & 0 deletions src/postgrest/tests/_async/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from unittest.mock import patch

import pytest
Expand All @@ -22,6 +23,16 @@ async def postgrest_client():
yield client


class TestXClientInfo:
def test_structured_metadata_format(self, postgrest_client: AsyncPostgrestClient):
x_client_info = postgrest_client.session.headers.get("X-Client-Info")
assert x_client_info is not None
assert re.match(
r"^supabase-py/postgrest-py v[\d.]+; platform=.+; platform-version=.+; runtime=python; runtime-version=\S+$",
x_client_info,
), f"X-Client-Info format is wrong: {x_client_info}"


class TestConstructor:
def test_simple(self, postgrest_client: AsyncPostgrestClient):
session = postgrest_client.session
Expand Down
11 changes: 11 additions & 0 deletions src/postgrest/tests/_sync/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from unittest.mock import patch

import pytest
Expand All @@ -22,6 +23,16 @@ def postgrest_client():
yield client


class TestXClientInfo:
def test_structured_metadata_format(self, postgrest_client: SyncPostgrestClient):
x_client_info = postgrest_client.session.headers.get("X-Client-Info")
assert x_client_info is not None
assert re.match(
r"^supabase-py/postgrest-py v[\d.]+; platform=.+; platform-version=.+; runtime=python; runtime-version=\S+$",
x_client_info,
), f"X-Client-Info format is wrong: {x_client_info}"


class TestConstructor:
def test_simple(self, postgrest_client: SyncPostgrestClient):
session = postgrest_client.session
Expand Down
12 changes: 7 additions & 5 deletions src/storage/src/storage3/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ def __init__(
http_client: Optional[AsyncClient] = None,
) -> None:
headers = {
"X-Client-Info": f"supabase-py/storage3 v{__version__}",
"X-Supabase-Client-Platform": platform.system(),
"X-Supabase-Client-Platform-Version": platform.release(),
"X-Supabase-Client-Runtime": "python",
"X-Supabase-Client-Runtime-Version": platform.python_version(),
"X-Client-Info": (
f"supabase-py/storage3 v{__version__}"
f"; platform={platform.system()}"
f"; platform-version={platform.release()}"
f"; runtime=python"
f"; runtime-version={platform.python_version()}"
),
**headers,
}

Expand Down
12 changes: 7 additions & 5 deletions src/storage/src/storage3/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ def __init__(
http_client: Optional[Client] = None,
) -> None:
headers = {
"X-Client-Info": f"supabase-py/storage3 v{__version__}",
"X-Supabase-Client-Platform": platform.system(),
"X-Supabase-Client-Platform-Version": platform.release(),
"X-Supabase-Client-Runtime": "python",
"X-Supabase-Client-Runtime-Version": platform.python_version(),
"X-Client-Info": (
f"supabase-py/storage3 v{__version__}"
f"; platform={platform.system()}"
f"; platform-version={platform.release()}"
f"; runtime=python"
f"; runtime-version={platform.python_version()}"
),
**headers,
}

Expand Down
24 changes: 24 additions & 0 deletions src/storage/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Dict

import pytest
Expand All @@ -16,6 +17,29 @@ def valid_headers() -> Dict[str, str]:
return {"Authorization": "Bearer test_token", "apikey": "test_api_key"}


_X_CLIENT_INFO_PATTERN = re.compile(
r"^supabase-py/storage3 v[\d.]+; platform=.+; platform-version=.+; runtime=python; runtime-version=\S+$"
)


def test_async_x_client_info_structured_format(valid_url, valid_headers) -> None:
client = AsyncStorageClient(url=valid_url, headers=valid_headers)
x_client_info = client._client.headers.get("X-Client-Info")
assert x_client_info is not None
assert _X_CLIENT_INFO_PATTERN.match(
x_client_info
), f"X-Client-Info format is wrong: {x_client_info}"


def test_sync_x_client_info_structured_format(valid_url, valid_headers) -> None:
client = SyncStorageClient(url=valid_url, headers=valid_headers)
x_client_info = client._client.headers.get("X-Client-Info")
assert x_client_info is not None
assert _X_CLIENT_INFO_PATTERN.match(
x_client_info
), f"X-Client-Info format is wrong: {x_client_info}"


def test_create_async_client(valid_url, valid_headers) -> None:
client = AsyncStorageClient(url=valid_url, headers=valid_headers)

Expand Down
11 changes: 10 additions & 1 deletion src/supabase/src/supabase/lib/client_options.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import platform
from dataclasses import dataclass, field
from typing import Dict, Optional, Union

Expand All @@ -19,7 +20,15 @@

from ..version import __version__

DEFAULT_HEADERS = {"X-Client-Info": f"supabase-py/{__version__}"}
DEFAULT_HEADERS = {
"X-Client-Info": (
f"supabase-py/{__version__}"
f"; platform={platform.system()}"
f"; platform-version={platform.release()}"
f"; runtime=python"
f"; runtime-version={platform.python_version()}"
)
}


@dataclass
Expand Down