t3api-utils 1.4.0__tar.gz → 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. t3api_utils-2.0.0/PKG-INFO +123 -0
  2. t3api_utils-2.0.0/README.md +95 -0
  3. t3api_utils-2.0.0/pyproject.toml +100 -0
  4. t3api_utils-2.0.0/pyproject.toml.orig +86 -0
  5. t3api_utils-2.0.0/t3api_utils/__init__.py +95 -0
  6. t3api_utils-2.0.0/t3api_utils/_api.py +52 -0
  7. t3api_utils-2.0.0/t3api_utils/_console.py +186 -0
  8. t3api_utils-2.0.0/t3api_utils/_http.py +320 -0
  9. t3api_utils-2.0.0/t3api_utils/_paths.py +19 -0
  10. t3api_utils-2.0.0/t3api_utils/_ratelimit.py +52 -0
  11. t3api_utils-2.0.0/t3api_utils/auth/__init__.py +0 -0
  12. t3api_utils-2.0.0/t3api_utils/auth/credentials.py +128 -0
  13. t3api_utils-2.0.0/t3api_utils/auth/login.py +234 -0
  14. t3api_utils-2.0.0/t3api_utils/auth/resolve.py +162 -0
  15. t3api_utils-2.0.0/t3api_utils/auth/secret_keys.py +132 -0
  16. t3api_utils-2.0.0/t3api_utils/auth/states.py +121 -0
  17. t3api_utils-2.0.0/t3api_utils/auth/store.py +234 -0
  18. t3api_utils-2.0.0/t3api_utils/cli/__init__.py +5 -0
  19. t3api_utils-2.0.0/t3api_utils/cli/main.py +634 -0
  20. t3api_utils-2.0.0/t3api_utils/client.py +761 -0
  21. t3api_utils-2.0.0/t3api_utils/errors.py +227 -0
  22. t3api_utils-2.0.0/t3api_utils/local.py +240 -0
  23. t3api_utils-2.0.0/t3api_utils/pickers.py +125 -0
  24. t3api_utils-2.0.0/t3api_utils/py.typed +0 -0
  25. t3api_utils-2.0.0/t3api_utils/reports.py +194 -0
  26. t3api_utils-2.0.0/t3api_utils/spec/__init__.py +6 -0
  27. t3api_utils-2.0.0/t3api_utils/spec/loader.py +208 -0
  28. t3api_utils-2.0.0/t3api_utils/spec/openapi.json.gz +0 -0
  29. t3api_utils-2.0.0/t3api_utils/spec/registry.py +370 -0
  30. t3api_utils-2.0.0/t3api_utils/tag_lists.py +342 -0
  31. t3api_utils-2.0.0/t3api_utils/tui/__init__.py +0 -0
  32. t3api_utils-2.0.0/t3api_utils/tui/inspector.py +150 -0
  33. t3api_utils-2.0.0/t3api_utils/writes.py +273 -0
  34. t3api_utils-1.4.0/LICENSE +0 -674
  35. t3api_utils-1.4.0/PKG-INFO +0 -141
  36. t3api_utils-1.4.0/README.md +0 -106
  37. t3api_utils-1.4.0/pyproject.toml +0 -89
  38. t3api_utils-1.4.0/setup.cfg +0 -4
  39. t3api_utils-1.4.0/t3api_utils/__init__.py +0 -18
  40. t3api_utils-1.4.0/t3api_utils/api/__init__.py +0 -8
  41. t3api_utils-1.4.0/t3api_utils/api/client.py +0 -209
  42. t3api_utils-1.4.0/t3api_utils/api/interfaces.py +0 -77
  43. t3api_utils-1.4.0/t3api_utils/api/operations.py +0 -329
  44. t3api_utils-1.4.0/t3api_utils/api/parallel.py +0 -481
  45. t3api_utils-1.4.0/t3api_utils/auth/__init__.py +0 -5
  46. t3api_utils-1.4.0/t3api_utils/auth/interfaces.py +0 -28
  47. t3api_utils-1.4.0/t3api_utils/auth/utils.py +0 -675
  48. t3api_utils-1.4.0/t3api_utils/cli/__init__.py +0 -1
  49. t3api_utils-1.4.0/t3api_utils/cli/consts.py +0 -155
  50. t3api_utils-1.4.0/t3api_utils/cli/utils.py +0 -716
  51. t3api_utils-1.4.0/t3api_utils/collection/__init__.py +0 -1
  52. t3api_utils-1.4.0/t3api_utils/collection/utils.py +0 -100
  53. t3api_utils-1.4.0/t3api_utils/db/__init__.py +0 -1
  54. t3api_utils-1.4.0/t3api_utils/db/consts.py +0 -13
  55. t3api_utils-1.4.0/t3api_utils/db/utils.py +0 -248
  56. t3api_utils-1.4.0/t3api_utils/exceptions.py +0 -5
  57. t3api_utils-1.4.0/t3api_utils/file/__init__.py +0 -1
  58. t3api_utils-1.4.0/t3api_utils/file/consts.py +0 -17
  59. t3api_utils-1.4.0/t3api_utils/file/utils.py +0 -206
  60. t3api_utils-1.4.0/t3api_utils/http/__init__.py +0 -1
  61. t3api_utils-1.4.0/t3api_utils/http/utils.py +0 -756
  62. t3api_utils-1.4.0/t3api_utils/inspector/__init__.py +0 -5
  63. t3api_utils-1.4.0/t3api_utils/inspector/app.py +0 -341
  64. t3api_utils-1.4.0/t3api_utils/interfaces.py +0 -6
  65. t3api_utils-1.4.0/t3api_utils/intro.py +0 -650
  66. t3api_utils-1.4.0/t3api_utils/logging.py +0 -69
  67. t3api_utils-1.4.0/t3api_utils/main/__init__.py +0 -1
  68. t3api_utils-1.4.0/t3api_utils/main/handlers.py +0 -310
  69. t3api_utils-1.4.0/t3api_utils/main/utils.py +0 -1695
  70. t3api_utils-1.4.0/t3api_utils/openapi/__init__.py +0 -6
  71. t3api_utils-1.4.0/t3api_utils/openapi/collection_picker.py +0 -151
  72. t3api_utils-1.4.0/t3api_utils/openapi/spec_fetcher.py +0 -236
  73. t3api_utils-1.4.0/t3api_utils/style/__init__.py +0 -67
  74. t3api_utils-1.4.0/t3api_utils/style/console.py +0 -19
  75. t3api_utils-1.4.0/t3api_utils/style/messages.py +0 -140
  76. t3api_utils-1.4.0/t3api_utils/style/styles.py +0 -67
  77. t3api_utils-1.4.0/t3api_utils.egg-info/PKG-INFO +0 -141
  78. t3api_utils-1.4.0/t3api_utils.egg-info/SOURCES.txt +0 -66
  79. t3api_utils-1.4.0/t3api_utils.egg-info/dependency_links.txt +0 -1
  80. t3api_utils-1.4.0/t3api_utils.egg-info/requires.txt +0 -18
  81. t3api_utils-1.4.0/t3api_utils.egg-info/top_level.txt +0 -1
  82. t3api_utils-1.4.0/tests/test_api_auth.py +0 -300
  83. t3api_utils-1.4.0/tests/test_api_client.py +0 -206
  84. t3api_utils-1.4.0/tests/test_api_interfaces.py +0 -178
  85. t3api_utils-1.4.0/tests/test_api_operations.py +0 -342
  86. t3api_utils-1.4.0/tests/test_api_parallel.py +0 -455
  87. t3api_utils-1.4.0/tests/test_auth.py +0 -224
  88. t3api_utils-1.4.0/tests/test_cli.py +0 -430
  89. t3api_utils-1.4.0/tests/test_collection.py +0 -72
  90. t3api_utils-1.4.0/tests/test_db.py +0 -444
  91. t3api_utils-1.4.0/tests/test_exceptions.py +0 -258
  92. t3api_utils-1.4.0/tests/test_files.py +0 -81
  93. t3api_utils-1.4.0/tests/test_http.py +0 -889
  94. t3api_utils-1.4.0/tests/test_inspector.py +0 -557
  95. t3api_utils-1.4.0/tests/test_interfaces.py +0 -325
  96. t3api_utils-1.4.0/tests/test_logging.py +0 -281
  97. t3api_utils-1.4.0/tests/test_main.py +0 -1089
  98. t3api_utils-1.4.0/tests/test_openapi.py +0 -274
  99. t3api_utils-1.4.0/tests/test_openapi_integration.py +0 -123
  100. t3api_utils-1.4.0/tests/test_smoke.py +0 -33
  101. t3api_utils-1.4.0/tests/test_style.py +0 -209
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: t3api-utils
3
+ Version: 2.0.0
4
+ Summary: Secret-key auth, collection loading, reports and tag lists for the T3 API
5
+ Keywords: t3,metrc,track and trace,cannabis,api
6
+ Author: Matt Frisbie
7
+ Author-email: Matt Frisbie <matt@classvsoftware.com>
8
+ License-Expression: GPL-3.0-only
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Typing :: Typed
15
+ Requires-Dist: httpx2>=2.16
16
+ Requires-Dist: rich>=13.0
17
+ Requires-Dist: typer>=0.16
18
+ Requires-Dist: keyring>=25.0
19
+ Requires-Dist: platformdirs>=4.0
20
+ Requires-Dist: pyotp>=2.8
21
+ Requires-Dist: tomli-w>=1.0
22
+ Requires-Dist: textual>=6.0 ; extra == 'tui'
23
+ Requires-Python: >=3.12
24
+ Project-URL: Homepage, https://github.com/classvsoftware/t3api-python-utils
25
+ Project-URL: Documentation, https://classvsoftware.github.io/t3api-python-utils/
26
+ Provides-Extra: tui
27
+ Description-Content-Type: text/markdown
28
+
29
+ # t3api-utils
30
+
31
+ A Python library and `t3api` command for the [T3 API](https://api.trackandtrace.tools/v2/docs)
32
+ (Track & Trace Tools), which serves Metrc cannabis-compliance data. It handles
33
+ login and secret keys, loads whole collections, sends writes safely (dry run
34
+ unless you say otherwise), downloads server-side reports and builds tag lists.
35
+
36
+ **Documentation: <https://classvsoftware.github.io/t3api-python-utils/>**
37
+
38
+ > 2.0 is a rewrite and doesn't share an API with 1.x. See
39
+ > [Migrating from 1.x](https://classvsoftware.github.io/t3api-python-utils/migration/).
40
+ > 1.x is frozen at 1.5.0.
41
+
42
+ ## Install
43
+
44
+ Python 3.12 or later.
45
+
46
+ ```bash
47
+ uv add t3api-utils
48
+ pip install "t3api-utils[tui]" # [tui] adds the terminal row inspector
49
+ ```
50
+
51
+ ## Quickstart
52
+
53
+ Log in once. This creates a T3 secret key from your Metrc login and saves it to
54
+ your OS keyring; your Metrc password isn't stored.
55
+
56
+ ```bash
57
+ t3api login
58
+ ```
59
+
60
+ Then, in a script:
61
+
62
+ ```python
63
+ import t3api_utils as t3
64
+
65
+ client = t3.connect()
66
+ items = client.collect("METRC_ACTIVE_ITEMS", license="LIC-00001")
67
+ t3.to_csv(items, "items.csv")
68
+ ```
69
+
70
+ For scheduled jobs and CI, set `T3_SECRET_KEY` instead of logging in.
71
+
72
+ A few more things it does:
73
+
74
+ ```python
75
+ # Writes are a dry run unless submit=True
76
+ client.post("/v2/items/discontinue", license="LIC-00001", json={"id": 12345}, submit=True)
77
+
78
+ # Validate every row, then submit
79
+ client.bulk("/v2/items/discontinue", rows=[{"id": i["id"]} for i in items], license="LIC-00001", submit=True)
80
+
81
+ # Server-side report straight to a file
82
+ client.report("ITEMS_REPORT", licenses=["LIC-00001"], to="items.xlsx")
83
+
84
+ # A column of tag labels to full package records
85
+ tl = client.tag_lists.from_csv("labels.csv", column="label", license="LIC-00001",
86
+ endpoint="METRC_ACTIVE_PACKAGES")
87
+ packages = tl.resolve()
88
+ ```
89
+
90
+ ## The t3api command
91
+
92
+ ```bash
93
+ t3api login # save a secret key to a profile
94
+ t3api pull METRC_ACTIVE_PACKAGES -l LIC-00001 -o packages.csv # a whole collection to CSV or JSON
95
+ t3api report ITEMS_REPORT -l LIC-00001 -o items.xlsx # a server-side report
96
+ t3api endpoints harvest --kind collection # search the T3 spec
97
+ t3api keys list # manage secret keys
98
+ ```
99
+
100
+ `t3api --help` lists every command.
101
+
102
+ ## Development
103
+
104
+ ```bash
105
+ uv sync
106
+ uv run pytest
107
+ uv run mypy
108
+ uv run mkdocs serve
109
+ ```
110
+
111
+ See [CLAUDE.md](CLAUDE.md) for the project layout and conventions, and
112
+ [CHANGELOG.md](CHANGELOG.md) for release notes.
113
+
114
+ ## License
115
+
116
+ [GPL-3.0-only](LICENSE).
117
+
118
+ ## Links
119
+
120
+ - [Documentation](https://classvsoftware.github.io/t3api-python-utils/)
121
+ - [T3 API docs](https://api.trackandtrace.tools/v2/docs)
122
+ - [T3 website](https://www.trackandtrace.tools) and [wiki](https://www.trackandtrace.tools/wiki)
123
+ - [Example scripts](https://github.com/classvsoftware/t3-api-examples)
@@ -0,0 +1,95 @@
1
+ # t3api-utils
2
+
3
+ A Python library and `t3api` command for the [T3 API](https://api.trackandtrace.tools/v2/docs)
4
+ (Track & Trace Tools), which serves Metrc cannabis-compliance data. It handles
5
+ login and secret keys, loads whole collections, sends writes safely (dry run
6
+ unless you say otherwise), downloads server-side reports and builds tag lists.
7
+
8
+ **Documentation: <https://classvsoftware.github.io/t3api-python-utils/>**
9
+
10
+ > 2.0 is a rewrite and doesn't share an API with 1.x. See
11
+ > [Migrating from 1.x](https://classvsoftware.github.io/t3api-python-utils/migration/).
12
+ > 1.x is frozen at 1.5.0.
13
+
14
+ ## Install
15
+
16
+ Python 3.12 or later.
17
+
18
+ ```bash
19
+ uv add t3api-utils
20
+ pip install "t3api-utils[tui]" # [tui] adds the terminal row inspector
21
+ ```
22
+
23
+ ## Quickstart
24
+
25
+ Log in once. This creates a T3 secret key from your Metrc login and saves it to
26
+ your OS keyring; your Metrc password isn't stored.
27
+
28
+ ```bash
29
+ t3api login
30
+ ```
31
+
32
+ Then, in a script:
33
+
34
+ ```python
35
+ import t3api_utils as t3
36
+
37
+ client = t3.connect()
38
+ items = client.collect("METRC_ACTIVE_ITEMS", license="LIC-00001")
39
+ t3.to_csv(items, "items.csv")
40
+ ```
41
+
42
+ For scheduled jobs and CI, set `T3_SECRET_KEY` instead of logging in.
43
+
44
+ A few more things it does:
45
+
46
+ ```python
47
+ # Writes are a dry run unless submit=True
48
+ client.post("/v2/items/discontinue", license="LIC-00001", json={"id": 12345}, submit=True)
49
+
50
+ # Validate every row, then submit
51
+ client.bulk("/v2/items/discontinue", rows=[{"id": i["id"]} for i in items], license="LIC-00001", submit=True)
52
+
53
+ # Server-side report straight to a file
54
+ client.report("ITEMS_REPORT", licenses=["LIC-00001"], to="items.xlsx")
55
+
56
+ # A column of tag labels to full package records
57
+ tl = client.tag_lists.from_csv("labels.csv", column="label", license="LIC-00001",
58
+ endpoint="METRC_ACTIVE_PACKAGES")
59
+ packages = tl.resolve()
60
+ ```
61
+
62
+ ## The t3api command
63
+
64
+ ```bash
65
+ t3api login # save a secret key to a profile
66
+ t3api pull METRC_ACTIVE_PACKAGES -l LIC-00001 -o packages.csv # a whole collection to CSV or JSON
67
+ t3api report ITEMS_REPORT -l LIC-00001 -o items.xlsx # a server-side report
68
+ t3api endpoints harvest --kind collection # search the T3 spec
69
+ t3api keys list # manage secret keys
70
+ ```
71
+
72
+ `t3api --help` lists every command.
73
+
74
+ ## Development
75
+
76
+ ```bash
77
+ uv sync
78
+ uv run pytest
79
+ uv run mypy
80
+ uv run mkdocs serve
81
+ ```
82
+
83
+ See [CLAUDE.md](CLAUDE.md) for the project layout and conventions, and
84
+ [CHANGELOG.md](CHANGELOG.md) for release notes.
85
+
86
+ ## License
87
+
88
+ [GPL-3.0-only](LICENSE).
89
+
90
+ ## Links
91
+
92
+ - [Documentation](https://classvsoftware.github.io/t3api-python-utils/)
93
+ - [T3 API docs](https://api.trackandtrace.tools/v2/docs)
94
+ - [T3 website](https://www.trackandtrace.tools) and [wiki](https://www.trackandtrace.tools/wiki)
95
+ - [Example scripts](https://github.com/classvsoftware/t3-api-examples)
@@ -0,0 +1,100 @@
1
+ [project]
2
+ name = "t3api-utils"
3
+ version = "2.0.0"
4
+ description = "Secret-key auth, collection loading, reports and tag lists for the T3 API"
5
+ readme = "README.md"
6
+ license = "GPL-3.0-only"
7
+ requires-python = ">=3.12"
8
+ keywords = [
9
+ "t3",
10
+ "metrc",
11
+ "track and trace",
12
+ "cannabis",
13
+ "api",
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Operating System :: OS Independent",
21
+ "Typing :: Typed",
22
+ ]
23
+ dependencies = [
24
+ "httpx2>=2.16",
25
+ "rich>=13.0",
26
+ "typer>=0.16",
27
+ "keyring>=25.0",
28
+ "platformdirs>=4.0",
29
+ "pyotp>=2.8",
30
+ "tomli-w>=1.0",
31
+ ]
32
+
33
+ [[project.authors]]
34
+ name = "Matt Frisbie"
35
+ email = "matt@classvsoftware.com"
36
+
37
+ [project.optional-dependencies]
38
+ tui = ["textual>=6.0"]
39
+
40
+ [project.scripts]
41
+ t3api = "t3api_utils.cli:app"
42
+
43
+ [project.urls]
44
+ Homepage = "https://github.com/classvsoftware/t3api-python-utils"
45
+ Documentation = "https://classvsoftware.github.io/t3api-python-utils/"
46
+
47
+ [build-system]
48
+ requires = ["uv_build>=0.9.0,<0.10.0"]
49
+ build-backend = "uv_build"
50
+
51
+ [tool.uv.build-backend]
52
+ module-name = "t3api_utils"
53
+ module-root = ""
54
+
55
+ [tool.mypy]
56
+ files = [
57
+ "t3api_utils",
58
+ "tests",
59
+ "scripts",
60
+ ]
61
+ strict = true
62
+ warn_unreachable = true
63
+
64
+ [[tool.mypy.overrides]]
65
+ module = [
66
+ "pyotp",
67
+ "pyotp.*",
68
+ ]
69
+ ignore_missing_imports = true
70
+
71
+ [tool.pytest.ini_options]
72
+ testpaths = ["tests"]
73
+ addopts = "-ra --strict-markers"
74
+ markers = ["sandbox: live tests against the T3 sandbox; need T3_SMOKE_SECRET_KEY"]
75
+ filterwarnings = ["error"]
76
+
77
+ [tool.coverage.run]
78
+ source = ["t3api_utils"]
79
+ branch = true
80
+
81
+ [tool.coverage.report]
82
+ show_missing = true
83
+ skip_covered = true
84
+ fail_under = 100
85
+ exclude_also = [
86
+ "if TYPE_CHECKING:",
87
+ "@overload",
88
+ "raise NotImplementedError",
89
+ ]
90
+
91
+ [dependency-groups]
92
+ dev = [
93
+ "textual>=6.0",
94
+ "pytest>=8.3",
95
+ "pytest-cov>=6.0",
96
+ "mypy>=1.14",
97
+ "mkdocs>=1.6",
98
+ "mkdocs-material>=9.0",
99
+ "mkdocstrings[python]>=0.27",
100
+ ]
@@ -0,0 +1,86 @@
1
+ [project]
2
+ name = "t3api-utils"
3
+ version = "2.0.0"
4
+ description = "Secret-key auth, collection loading, reports and tag lists for the T3 API"
5
+ authors = [{ name = "Matt Frisbie", email = "matt@classvsoftware.com" }]
6
+ readme = "README.md"
7
+ license = "GPL-3.0-only"
8
+ requires-python = ">=3.12"
9
+ keywords = ["t3", "metrc", "track and trace", "cannabis", "api"]
10
+ classifiers = [
11
+ "Development Status :: 5 - Production/Stable",
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3.12",
14
+ "Programming Language :: Python :: 3.13",
15
+ "Operating System :: OS Independent",
16
+ "Typing :: Typed",
17
+ ]
18
+ dependencies = [
19
+ "httpx2>=2.16",
20
+ "rich>=13.0",
21
+ "typer>=0.16",
22
+ "keyring>=25.0",
23
+ "platformdirs>=4.0",
24
+ "pyotp>=2.8",
25
+ "tomli-w>=1.0",
26
+ ]
27
+
28
+ [project.optional-dependencies]
29
+ tui = ["textual>=6.0"]
30
+
31
+ [project.scripts]
32
+ t3api = "t3api_utils.cli:app"
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/classvsoftware/t3api-python-utils"
36
+ Documentation = "https://classvsoftware.github.io/t3api-python-utils/"
37
+
38
+ [build-system]
39
+ requires = ["uv_build>=0.9.0,<0.10.0"]
40
+ build-backend = "uv_build"
41
+
42
+ [tool.uv.build-backend]
43
+ module-name = "t3api_utils"
44
+ module-root = ""
45
+
46
+ [dependency-groups]
47
+ dev = [
48
+ "textual>=6.0",
49
+ "pytest>=8.3",
50
+ "pytest-cov>=6.0",
51
+ "mypy>=1.14",
52
+ "mkdocs>=1.6",
53
+ "mkdocs-material>=9.0",
54
+ "mkdocstrings[python]>=0.27",
55
+ ]
56
+
57
+ [tool.mypy]
58
+ files = ["t3api_utils", "tests", "scripts"]
59
+ strict = true
60
+ warn_unreachable = true
61
+
62
+ [[tool.mypy.overrides]]
63
+ module = ["pyotp", "pyotp.*"]
64
+ ignore_missing_imports = true
65
+
66
+ [tool.pytest.ini_options]
67
+ testpaths = ["tests"]
68
+ addopts = "-ra --strict-markers"
69
+ markers = [
70
+ "sandbox: live tests against the T3 sandbox; need T3_SMOKE_SECRET_KEY",
71
+ ]
72
+ filterwarnings = ["error"]
73
+
74
+ [tool.coverage.run]
75
+ source = ["t3api_utils"]
76
+ branch = true
77
+
78
+ [tool.coverage.report]
79
+ show_missing = true
80
+ skip_covered = true
81
+ fail_under = 100
82
+ exclude_also = [
83
+ "if TYPE_CHECKING:",
84
+ "@overload",
85
+ "raise NotImplementedError",
86
+ ]
@@ -0,0 +1,95 @@
1
+ """t3api-utils: secret-key auth, collections, reports and tag lists for the T3 API.
2
+
3
+ ```python
4
+ import t3api_utils as t3
5
+
6
+ client = t3.connect()
7
+ items = client.collect("METRC_ACTIVE_ITEMS", license="LIC-00001")
8
+ t3.to_csv(items, "items.csv")
9
+ ```
10
+
11
+ Importing the package has no side effects: no files, no logging setup, no
12
+ network calls.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from collections.abc import Mapping, Sequence
18
+ from importlib import metadata
19
+ from typing import Any
20
+
21
+ from t3api_utils.auth.credentials import BearerAuth, SecretKeyAuth
22
+ from t3api_utils.auth.resolve import connect
23
+ from t3api_utils.client import T3Client
24
+ from t3api_utils.errors import (
25
+ APIError,
26
+ AuthError,
27
+ AuthRequired,
28
+ NotFound,
29
+ NotInteractive,
30
+ RateLimited,
31
+ ServerError,
32
+ SpecError,
33
+ T3Error,
34
+ TagListResolveError,
35
+ UnknownEndpoint,
36
+ ValidationError,
37
+ )
38
+ from t3api_utils.local import filter_rows, read_rows, to_csv, to_json
39
+ from t3api_utils.pickers import pick_file
40
+ from t3api_utils.spec.registry import Endpoint
41
+ from t3api_utils.tag_lists import TagList
42
+ from t3api_utils.writes import BulkResult, RowResult, WriteResult
43
+
44
+ try:
45
+ __version__ = metadata.version("t3api-utils")
46
+ except metadata.PackageNotFoundError: # pragma: no cover - only in odd installs
47
+ __version__ = "0+unknown"
48
+
49
+ TUI_HINT = "t3.inspect() needs Textual. Install it with: pip install 't3api-utils[tui]'"
50
+
51
+
52
+ def inspect(rows: Sequence[Mapping[str, Any]], *, title: str = "rows") -> None:
53
+ """Browse rows in the Textual inspector (needs ``t3api-utils[tui]``)."""
54
+ try:
55
+ from t3api_utils.tui import inspector
56
+ except ImportError as exc:
57
+ raise ImportError(TUI_HINT) from exc
58
+ if not rows:
59
+ from t3api_utils import _console
60
+
61
+ _console.info("No rows to inspect.")
62
+ return
63
+ inspector.run(rows, title=title)
64
+
65
+
66
+ __all__ = [
67
+ "APIError",
68
+ "AuthError",
69
+ "AuthRequired",
70
+ "BearerAuth",
71
+ "BulkResult",
72
+ "Endpoint",
73
+ "NotFound",
74
+ "NotInteractive",
75
+ "RateLimited",
76
+ "RowResult",
77
+ "SecretKeyAuth",
78
+ "ServerError",
79
+ "SpecError",
80
+ "T3Client",
81
+ "T3Error",
82
+ "TagList",
83
+ "TagListResolveError",
84
+ "UnknownEndpoint",
85
+ "ValidationError",
86
+ "WriteResult",
87
+ "__version__",
88
+ "connect",
89
+ "filter_rows",
90
+ "inspect",
91
+ "pick_file",
92
+ "read_rows",
93
+ "to_csv",
94
+ "to_json",
95
+ ]
@@ -0,0 +1,52 @@
1
+ """Send a request and turn errors into APIError (internal)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ import httpx2
8
+
9
+ from t3api_utils.errors import T3Error, error_from_response
10
+
11
+
12
+ def send(
13
+ http: httpx2.Client,
14
+ method: str,
15
+ url: str,
16
+ *,
17
+ credential_kind: str | None = None,
18
+ **kwargs: Any,
19
+ ) -> httpx2.Response:
20
+ """Send one request; raise the matching APIError for a non-2xx response."""
21
+ response = http.request(method, url, **kwargs)
22
+ if response.is_error:
23
+ raise error_from_response(response, credential_kind=credential_kind)
24
+ return response
25
+
26
+
27
+ def parse(response: httpx2.Response) -> Any:
28
+ """Parsed JSON for JSON responses, ``None`` for an empty body, else ``bytes``."""
29
+ content = response.content
30
+ if not content:
31
+ return None
32
+ if "json" in response.headers.get("content-type", ""):
33
+ return response.json()
34
+ return content
35
+
36
+
37
+ def require_field(data: Any, field: str, what: str) -> str:
38
+ """Return ``data[field]`` as a string, or raise T3Error if the response lacks it."""
39
+ if isinstance(data, dict) and data.get(field):
40
+ return str(data[field])
41
+ raise T3Error(f"{what} returned an unexpected response (no {field!r}).")
42
+
43
+
44
+ def call(
45
+ http: httpx2.Client,
46
+ method: str,
47
+ url: str,
48
+ *,
49
+ credential_kind: str | None = None,
50
+ **kwargs: Any,
51
+ ) -> Any:
52
+ return parse(send(http, method, url, credential_kind=credential_kind, **kwargs))