Skip to content

Commit 4827964

Browse files
authored
chg: ✨ add user-agent header with SDK and Python versions (#36)
1 parent 5fccd0f commit 4827964

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

mindee/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from mindee.documents.invoice import Invoice
1010
from mindee.documents.passport import Passport
1111

12+
1213
DOCUMENT_CLASSES = {
1314
"receipt": Receipt,
1415
"invoice": Invoice,

mindee/http.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import requests
2+
from mindee.versions import __version__, python_version, get_platform
3+
4+
platform = get_platform()
25

36

47
def request(url, input_file, token, include_words=False):
@@ -12,7 +15,10 @@ def request(url, input_file, token, include_words=False):
1215
input_file.file_object.seek(0)
1316

1417
files = {"document": (input_file.filename, input_file.file_object.read())}
15-
headers = {"Authorization": f"Token {token}"}
18+
headers = {
19+
"Authorization": f"Token {token}",
20+
"User-Agent": f"mindee-api-python@v{__version__} python-v{python_version} {platform}",
21+
}
1622

1723
params = {}
1824
if include_words:

mindee/versions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
3+
__version__ = "1.2.3"
4+
5+
python_version = "%s.%s" % (sys.version_info[0], sys.version_info[1])
6+
7+
8+
def get_platform() -> str:
9+
platforms = {
10+
"linux": "linux",
11+
"win32": "windows",
12+
"darwin": "macos",
13+
"aix": "aix",
14+
"freebsd": "freebsd",
15+
}
16+
for name, agent_name in platforms.items():
17+
if sys.platform.startswith(name):
18+
return agent_name
19+
return sys.platform

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
from setuptools import find_packages, setup
3-
4-
__version__ = None
3+
from mindee.versions import __version__
54

65

76
with open("README.md", "r", newline="", encoding="utf-8") as fh:
@@ -32,10 +31,10 @@ def make_requirements_list(file="requirements.txt", only_regular=True):
3231

3332

3433
setup(
35-
python_requires=">=3.0",
34+
python_requires=">=3.6",
3635
name=f"{PACKAGE_NAME}",
3736
description="Mindee API helper library for python",
38-
version="v1.2.3",
37+
version=__version__,
3938
long_description=long_description,
4039
long_description_content_type="text/markdown",
4140
url=GIT_URL,

0 commit comments

Comments
 (0)