This is an automated email from the ASF dual-hosted git repository.

kevinjqliu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 36ed4af6 add X-Client-Version header to rest client (#2910)
36ed4af6 is described below

commit 36ed4af622b53035ee01df68bf94aa8828ab89e1
Author: Neelesh Salian <[email protected]>
AuthorDate: Wed Jan 14 09:55:37 2026 -0800

    add X-Client-Version header to rest client (#2910)
    
    Closes #2373
    
    # Rationale for this change
    Bringing parity to the headers in Python.
    The version is as per the [HttpClient in
    
Java](https://github.com/apache/iceberg/blob/68e555b94f4706a2af41dcb561c84007230c0bc1/core/src/main/java/org/apache/iceberg/rest/HTTPClient.java#L533-L534)
    and the version string is matching
    
[IcebergBuild](https://github.com/apache/iceberg/blob/779af12312fcf70c1e6e52d610d64cf947fd0a4f/api/src/main/java/org/apache/iceberg/IcebergBuild.java#L67)
    but with `PyIceberg` instead of Iceberg.
    
    Previously, this was worked on #2652 but since that has stalled, adding
    a fix to close our the issue. Thanks to @jaimeferj for his original PR.
    
    ## Are these changes tested?
    - Added a test in `tests/catalog/test_rest.py` -
    `test_client_version_header`
    
    ## Are there any user-facing changes?
    No
---
 pyiceberg/catalog/rest/__init__.py | 1 +
 tests/catalog/test_rest.py         | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/pyiceberg/catalog/rest/__init__.py 
b/pyiceberg/catalog/rest/__init__.py
index 7866f5e8..29fcade7 100644
--- a/pyiceberg/catalog/rest/__init__.py
+++ b/pyiceberg/catalog/rest/__init__.py
@@ -617,6 +617,7 @@ class RestCatalog(Catalog):
         session.headers.update(header_properties)
         session.headers["Content-type"] = "application/json"
         session.headers["User-Agent"] = f"PyIceberg/{__version__}"
+        session.headers["X-Client-Version"] = f"PyIceberg {__version__}"
         session.headers.setdefault("X-Iceberg-Access-Delegation", 
ACCESS_DELEGATION_DEFAULT)
 
     def _create_table(
diff --git a/tests/catalog/test_rest.py b/tests/catalog/test_rest.py
index 5aae5949..281418e0 100644
--- a/tests/catalog/test_rest.py
+++ b/tests/catalog/test_rest.py
@@ -1944,6 +1944,12 @@ def test_auth_header(rest_mock: Mocker) -> None:
     assert mock_request.last_request.text == 
"grant_type=client_credentials&client_id=client&client_secret=secret&scope=catalog"
 
 
+def test_client_version_header(rest_mock: Mocker) -> None:
+    catalog = RestCatalog("rest", uri=TEST_URI, warehouse="s3://some-bucket")
+    assert catalog._session.headers.get("X-Client-Version") == f"PyIceberg 
{pyiceberg.__version__}"
+    assert rest_mock.last_request.headers["X-Client-Version"] == f"PyIceberg 
{pyiceberg.__version__}"
+
+
 class TestRestCatalogClose:
     """Tests RestCatalog close functionality"""
 

Reply via email to