Skip to content

Commit 2279349

Browse files
committed
use custom user agent
1 parent a1ace3d commit 2279349

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/lpdb_python/session.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,23 @@
1515
)
1616
import re
1717
import warnings
18+
import importlib.metadata as metadata
1819

1920
import requests
2021

2122
__all__ = ["LpdbDataType", "LpdbError", "LpdbWarning", "LpdbSession"]
2223

24+
_PACKAGE_NAME: Final[str] = "lpdb_python"
25+
26+
27+
@cache
28+
def _get_version() -> str:
29+
try:
30+
return metadata.version(_PACKAGE_NAME)
31+
except metadata.PackageNotFoundError:
32+
return "dev"
33+
34+
2335
type LpdbDataType = Literal[
2436
"broadcasters",
2537
"company",
@@ -122,6 +134,7 @@ def _get_header(self) -> dict[str, str]:
122134
"authorization": f"Apikey {self.__api_key}",
123135
"accept": "application/json",
124136
"accept-encoding": "gzip",
137+
"user-agent": f"{_PACKAGE_NAME}/{_get_version()}",
125138
}
126139

127140
@staticmethod

0 commit comments

Comments
 (0)