Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.1.2

**Date** - 09/23/2025
**Date** - 10/16/2025

**Release Tag** - [py2.1.2](https://github.com/datacommonsorg/api-python/releases/tag/py2.1.2)

Expand Down
2 changes: 1 addition & 1 deletion datacommons_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.1.2rc1"
__version__ = "2.1.2"
"""
Data Commons Client Package

Expand Down
11 changes: 0 additions & 11 deletions datacommons_client/endpoints/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import re
from typing import Any, Dict, Optional

from datacommons_client.utils.error_handling import InvalidSurfaceHeaderValueError
from datacommons_client.utils.error_handling import VALID_SURFACE_HEADER_VALUES
from datacommons_client.utils.request_handling import check_instance_is_valid
from datacommons_client.utils.request_handling import post_request
from datacommons_client.utils.request_handling import resolve_instance_url
Expand Down Expand Up @@ -52,15 +50,6 @@ def __init__(
# Resolve from dc_instance
self.base_url = resolve_instance_url(dc_instance)

# if this call originates from another DC product (MCP server, DataGemma, etc.), we indicate that to Mixer
# otherwise, the 'x-surface' header is 'clientlib-python'
if surface_header_value:
# use patterns to support tags like mcp-{VERSION}
if not any(
re.fullmatch(pattern, surface_header_value)
for pattern in VALID_SURFACE_HEADER_VALUES):
raise InvalidSurfaceHeaderValueError

self.headers = self.build_headers(surface_header_value=surface_header_value,
api_key=api_key)

Expand Down
13 changes: 1 addition & 12 deletions datacommons_client/tests/endpoints/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from datacommons_client.endpoints.base import API
from datacommons_client.endpoints.base import Endpoint
from datacommons_client.utils.error_handling import InvalidSurfaceHeaderValueError


@patch(
Expand Down Expand Up @@ -63,7 +62,7 @@ def test_api_initialization_with_dc_instance(mock_resolve_instance_url):
return_value="https://custom-instance/api/v2",
)
def test_api_initialization_with_surface_header(mock_url):
"""Tests API initialization with an invalid surface header raises an InvalidSurfaceHeaderValueError."""
"""Tests API initialization with a surface header """
api = API(dc_instance="custom-instance", surface_header_value="mcp-1.1.0")
assert api.headers == {
"Content-Type": "application/json",
Expand All @@ -77,16 +76,6 @@ def test_api_initialization_invalid_args():
API(dc_instance="custom-instance", url="https://custom.api/v2")


@patch(
"datacommons_client.endpoints.base.resolve_instance_url",
return_value="https://custom-instance/api/v2",
)
def test_api_initialization_invalid_surface(mock_url):
"""Tests API initialization with an invalid surface header raises an InvalidSurfaceHeaderValueError."""
with pytest.raises(InvalidSurfaceHeaderValueError):
API(dc_instance="custom-instance", surface_header_value="not mcp")


@patch(
"datacommons_client.endpoints.base.resolve_instance_url",
return_value="https://custom-instance/api/v2",
Expand Down
11 changes: 0 additions & 11 deletions datacommons_client/utils/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,3 @@ class NoDataForPropertyError(DataCommonsError):
"""Raised when there is no data that meets the specified property filters."""

default_message = "No available data for the specified property filters."


VALID_SURFACE_HEADER_VALUES = ["mcp", r"mcp-[\d\.]+", "datagemma"]


class InvalidSurfaceHeaderValueError(DataCommonsError):
"""
The surface header value must be a surface known to the Data Commons team.
This value is used in the DC usage logs in Mixer.
"""
default_message = "The surface header value should only to indicate a call made from Data Commons surfaces like the MCP server or DataGemma."