Skip to content

Commit dd55082

Browse files
authoredMar 27, 2024··
feat(client): Add custom User-Agent in Docker client as tc-python/<version> (#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.
1 parent 2e27225 commit dd55082

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed
 

‎core/testcontainers/core/docker_client.py

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
1313
import functools as ft
14+
import importlib.metadata
1415
import ipaddress
1516
import os
1617
import urllib
@@ -44,6 +45,7 @@ def __init__(self, **kwargs) -> None:
4445
else:
4546
self.client = docker.from_env(**kwargs)
4647
self.client.api.headers["x-tc-sid"] = SESSION_ID
48+
self.client.api.headers["User-Agent"] = "tc-python/" + importlib.metadata.version("testcontainers")
4749

4850
@ft.wraps(ContainerCollection.run)
4951
def run(

0 commit comments

Comments
 (0)
Please sign in to comment.