Skip to content

Commit

Permalink
feat(client): Add custom User-Agent in Docker client as `tc-python/<v…
Browse files Browse the repository at this point in the history
…ersion>` (#507)

Set User-Agent in format `tc-python/<version>`, `version` value is
coming from `pyproject.toml`.

The `User-Agent` header will allow to identify Testcontainers language
implementation and the specific version. Also, track the usage of the
library.
  • Loading branch information
eddumelendez authored Mar 27, 2024
1 parent 2e27225 commit dd55082
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/testcontainers/core/docker_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import functools as ft
import importlib.metadata
import ipaddress
import os
import urllib
Expand Down Expand Up @@ -44,6 +45,7 @@ def __init__(self, **kwargs) -> None:
else:
self.client = docker.from_env(**kwargs)
self.client.api.headers["x-tc-sid"] = SESSION_ID
self.client.api.headers["User-Agent"] = "tc-python/" + importlib.metadata.version("testcontainers")

@ft.wraps(ContainerCollection.run)
def run(
Expand Down

0 comments on commit dd55082

Please # to comment.