deweypy 0.0.1__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.
- deweypy-0.0.1/PKG-INFO +60 -0
- deweypy-0.0.1/README.md +40 -0
- deweypy-0.0.1/pyproject.toml +191 -0
- deweypy-0.0.1/src/deweypy/__init__.py +0 -0
- deweypy-0.0.1/src/deweypy/__main__.py +5 -0
- deweypy-0.0.1/src/deweypy/app.py +5 -0
- deweypy-0.0.1/src/deweypy/auth.py +77 -0
- deweypy-0.0.1/src/deweypy/context.py +156 -0
- deweypy-0.0.1/src/deweypy/display.py +5 -0
- deweypy-0.0.1/src/deweypy/download/__init__.py +10 -0
- deweypy-0.0.1/src/deweypy/download/asynchronous.py +1026 -0
- deweypy-0.0.1/src/deweypy/download/settings.py +93 -0
- deweypy-0.0.1/src/deweypy/download/speed_testing.py +97 -0
- deweypy-0.0.1/src/deweypy/download/speedy.py +97 -0
- deweypy-0.0.1/src/deweypy/download/synchronous.py +447 -0
- deweypy-0.0.1/src/deweypy/download/types.py +113 -0
- deweypy-0.0.1/src/deweypy/main.py +228 -0
- deweypy-0.0.1/src/deweypy/py.typed +0 -0
deweypy-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: deweypy
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python client for Dewey Data (https://deweydata.io/).
|
|
5
|
+
Requires-Dist: aiofiles>=24.1.0
|
|
6
|
+
Requires-Dist: aiopath>=0.7.7
|
|
7
|
+
Requires-Dist: anyio>=4.11.0
|
|
8
|
+
Requires-Dist: async-property>=0.2.2
|
|
9
|
+
Requires-Dist: attrs>=25.3.0
|
|
10
|
+
Requires-Dist: culsans>=0.9.0
|
|
11
|
+
Requires-Dist: httpx-aiohttp>=0.1.8
|
|
12
|
+
Requires-Dist: httpx[http2]>=0.28.1
|
|
13
|
+
Requires-Dist: ipywidgets>=8.1.7
|
|
14
|
+
Requires-Dist: python-slugify>=8.0.4
|
|
15
|
+
Requires-Dist: rich>=14.1.0
|
|
16
|
+
Requires-Dist: shellingham>=1.5.4
|
|
17
|
+
Requires-Dist: typer>=0.19.2
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# deweypy
|
|
22
|
+
|
|
23
|
+
## Dewey Data Python Client
|
|
24
|
+
|
|
25
|
+
### Getting Started
|
|
26
|
+
|
|
27
|
+
To download your data using the Dewey Data Python Client, follow these steps in your command line or terminal:
|
|
28
|
+
1. **Install the client**
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install git+https://github.com/Dewey-Data/deweypy.git
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. **Make a directory for your downloads**
|
|
35
|
+
```bash
|
|
36
|
+
mkdir dewey-downloads/
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
3. **Locate `FOLDER_ID`**
|
|
40
|
+
|
|
41
|
+
`FOLDER_ID` can be extracted from the end of the end of the API URL after `data/`
|
|
42
|
+
|
|
43
|
+
4. **Run client**
|
|
44
|
+
```bash
|
|
45
|
+
python -m deweypy --api-key <YOUR_API_KEY> speedy-download <FOLDER_ID>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
#### A few notes...
|
|
50
|
+
- For now, please use the CLI to download data. This method is well tested; notebook support will be available soon.
|
|
51
|
+
- Increasing the number of workers for multi-threaded downloads yields diminishing returns, as API requests are limited both by our bucket’s rate limits and your own. We recommend the default of 8 workers, but you can override this with:
|
|
52
|
+
`--num-workers <INT>` following `speedy-download <FOLDER_ID>`.
|
|
53
|
+
- If your dataset is date-partitioned, you can limit the data processed by specifying partition boundaries at the end of your command:
|
|
54
|
+
```bash
|
|
55
|
+
--partition-key-before YYYY-MM-DD --partition-key-after YYYY-MM-DD
|
|
56
|
+
```
|
|
57
|
+
- `--partition-key-before` includes all partitions up to and including the given date.
|
|
58
|
+
- `--partition-key-after` includes all partitions from and including the given date onward.
|
|
59
|
+
### Working with data post-download
|
|
60
|
+
For guidance on analyzing your downloaded data, check out the [provided notebook tutorial](https://github.com/Dewey-Data/deweypy/blob/main/notebook-examples/customized-monthly-patterns.ipynb). It demonstrates how to work with Polars, Pandas, and DuckDB, and includes methods for exporting data to Parquet format for more efficient downstream analysis.
|
deweypy-0.0.1/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# deweypy
|
|
2
|
+
|
|
3
|
+
## Dewey Data Python Client
|
|
4
|
+
|
|
5
|
+
### Getting Started
|
|
6
|
+
|
|
7
|
+
To download your data using the Dewey Data Python Client, follow these steps in your command line or terminal:
|
|
8
|
+
1. **Install the client**
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install git+https://github.com/Dewey-Data/deweypy.git
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
2. **Make a directory for your downloads**
|
|
15
|
+
```bash
|
|
16
|
+
mkdir dewey-downloads/
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
3. **Locate `FOLDER_ID`**
|
|
20
|
+
|
|
21
|
+
`FOLDER_ID` can be extracted from the end of the end of the API URL after `data/`
|
|
22
|
+
|
|
23
|
+
4. **Run client**
|
|
24
|
+
```bash
|
|
25
|
+
python -m deweypy --api-key <YOUR_API_KEY> speedy-download <FOLDER_ID>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#### A few notes...
|
|
30
|
+
- For now, please use the CLI to download data. This method is well tested; notebook support will be available soon.
|
|
31
|
+
- Increasing the number of workers for multi-threaded downloads yields diminishing returns, as API requests are limited both by our bucket’s rate limits and your own. We recommend the default of 8 workers, but you can override this with:
|
|
32
|
+
`--num-workers <INT>` following `speedy-download <FOLDER_ID>`.
|
|
33
|
+
- If your dataset is date-partitioned, you can limit the data processed by specifying partition boundaries at the end of your command:
|
|
34
|
+
```bash
|
|
35
|
+
--partition-key-before YYYY-MM-DD --partition-key-after YYYY-MM-DD
|
|
36
|
+
```
|
|
37
|
+
- `--partition-key-before` includes all partitions up to and including the given date.
|
|
38
|
+
- `--partition-key-after` includes all partitions from and including the given date onward.
|
|
39
|
+
### Working with data post-download
|
|
40
|
+
For guidance on analyzing your downloaded data, check out the [provided notebook tutorial](https://github.com/Dewey-Data/deweypy/blob/main/notebook-examples/customized-monthly-patterns.ipynb). It demonstrates how to work with Polars, Pandas, and DuckDB, and includes methods for exporting data to Parquet format for more efficient downstream analysis.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# ==== uv ====
|
|
2
|
+
# https://github.com/astral-sh/uv
|
|
3
|
+
|
|
4
|
+
[project]
|
|
5
|
+
name = "deweypy"
|
|
6
|
+
version = "0.0.1"
|
|
7
|
+
description = "A Python client for Dewey Data (https://deweydata.io/)."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
|
|
11
|
+
dependencies = [
|
|
12
|
+
"aiofiles>=24.1.0",
|
|
13
|
+
"aiopath>=0.7.7",
|
|
14
|
+
"anyio>=4.11.0",
|
|
15
|
+
"async-property>=0.2.2",
|
|
16
|
+
"attrs>=25.3.0",
|
|
17
|
+
"culsans>=0.9.0",
|
|
18
|
+
"httpx-aiohttp>=0.1.8",
|
|
19
|
+
"httpx[http2]>=0.28.1",
|
|
20
|
+
"ipywidgets>=8.1.7",
|
|
21
|
+
"python-slugify>=8.0.4",
|
|
22
|
+
"rich>=14.1.0",
|
|
23
|
+
"shellingham>=1.5.4",
|
|
24
|
+
"typer>=0.19.2",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[dependency-groups]
|
|
28
|
+
dev = [
|
|
29
|
+
"coverage>=7.10.7",
|
|
30
|
+
"duckdb>=1.4.0",
|
|
31
|
+
"ipython>=9.5.0",
|
|
32
|
+
"mypy>=1.18.2",
|
|
33
|
+
"notebook>=7.4.5",
|
|
34
|
+
"pandas[pyarrow]>=2.3.2",
|
|
35
|
+
"polars[pyarrow]>=1.33.1",
|
|
36
|
+
"pre-commit>=4.3.0",
|
|
37
|
+
"pytest>=8.4.2",
|
|
38
|
+
"pytest-cov>=7.0.0",
|
|
39
|
+
"pytest-mock>=3.15.1",
|
|
40
|
+
"respx>=0.22.0",
|
|
41
|
+
"ruff>=0.13.1",
|
|
42
|
+
"time-machine>=2.19.0",
|
|
43
|
+
"types-aiofiles>=24.1.0.20250822",
|
|
44
|
+
"uvloop>=0.21.0; sys_platform != 'win32'",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.scripts]
|
|
48
|
+
dewey = "deweypy:main.app"
|
|
49
|
+
|
|
50
|
+
[build-system]
|
|
51
|
+
requires = ["uv_build>=0.8.21,<0.9.0"]
|
|
52
|
+
build-backend = "uv_build"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# ==== coverage ====
|
|
56
|
+
# https://github.com/nedbat/coveragepy
|
|
57
|
+
[tool.coverage.run]
|
|
58
|
+
omit = ["*/tests/*"]
|
|
59
|
+
|
|
60
|
+
[tool.coverage.report]
|
|
61
|
+
# https://coverage.readthedocs.io/en/latest/config.html#sample-file
|
|
62
|
+
exclude_also = [
|
|
63
|
+
# Don't complain about missing debug-only code:
|
|
64
|
+
"def __repr__",
|
|
65
|
+
"if self\\.debug",
|
|
66
|
+
# Don't complain if tests don't hit defensive assertion code:
|
|
67
|
+
"raise AssertionError",
|
|
68
|
+
"raise NotImplementedError",
|
|
69
|
+
"raise RuntimeError",
|
|
70
|
+
# Don't complain if non-runnable code isn't run:
|
|
71
|
+
"if 0:",
|
|
72
|
+
"if __name__ == .__main__.:",
|
|
73
|
+
# Don't complain about abstract methods, they aren't run:
|
|
74
|
+
"@(abc\\.)?abstractmethod",
|
|
75
|
+
# Don't complain about type checking blocks:
|
|
76
|
+
"if TYPE_CHECKING:",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# ==== mypy ====
|
|
81
|
+
# https://github.com/python/mypy
|
|
82
|
+
[tool.mypy]
|
|
83
|
+
python_version = "3.12"
|
|
84
|
+
check_untyped_defs = true
|
|
85
|
+
exclude = []
|
|
86
|
+
ignore_missing_imports = true
|
|
87
|
+
local_partial_types = true
|
|
88
|
+
warn_unused_ignores = true
|
|
89
|
+
warn_redundant_casts = true
|
|
90
|
+
warn_unused_configs = true
|
|
91
|
+
warn_unreachable = true
|
|
92
|
+
plugins = []
|
|
93
|
+
|
|
94
|
+
[[tool.mypy.overrides]]
|
|
95
|
+
module = "tests.*"
|
|
96
|
+
# Allow tests to have untyped definitions.
|
|
97
|
+
disallow_untyped_defs = false
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# ==== pytest ====
|
|
101
|
+
# https://github.com/pytest-dev/pytest
|
|
102
|
+
[tool.pytest.ini_options]
|
|
103
|
+
minversion = "8.3"
|
|
104
|
+
addopts = "--strict-config --strict-markers"
|
|
105
|
+
python_files = ["tests.py", "test_*.py"]
|
|
106
|
+
norecursedirs = [
|
|
107
|
+
".cache",
|
|
108
|
+
".git",
|
|
109
|
+
".mypy_cache",
|
|
110
|
+
".pytest_cache",
|
|
111
|
+
".ruff_cache",
|
|
112
|
+
".venv",
|
|
113
|
+
"build",
|
|
114
|
+
"dist",
|
|
115
|
+
"htmlcov",
|
|
116
|
+
"node_modules",
|
|
117
|
+
"venv",
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
# ==== ruff ====
|
|
122
|
+
# https://github.com/astral-sh/ruff
|
|
123
|
+
[tool.ruff]
|
|
124
|
+
exclude = [
|
|
125
|
+
".bzr",
|
|
126
|
+
".direnv",
|
|
127
|
+
".eggs",
|
|
128
|
+
".git",
|
|
129
|
+
".git-rewrite",
|
|
130
|
+
".hg",
|
|
131
|
+
".mypy_cache",
|
|
132
|
+
".nox",
|
|
133
|
+
".pants.d",
|
|
134
|
+
".pytype",
|
|
135
|
+
".pytest_cache",
|
|
136
|
+
".ruff_cache",
|
|
137
|
+
".svn",
|
|
138
|
+
".tox",
|
|
139
|
+
".venv",
|
|
140
|
+
"__pypackages__",
|
|
141
|
+
"_build",
|
|
142
|
+
"buck-out",
|
|
143
|
+
"build",
|
|
144
|
+
"dist",
|
|
145
|
+
"node_modules",
|
|
146
|
+
"htmlcov",
|
|
147
|
+
"venv",
|
|
148
|
+
]
|
|
149
|
+
line-length = 88
|
|
150
|
+
target-version = "py313"
|
|
151
|
+
|
|
152
|
+
[tool.ruff.lint]
|
|
153
|
+
ignore = [
|
|
154
|
+
"E501", # Line too long - `ruff format` will handle formatting anyway
|
|
155
|
+
"COM812", # Trailing comma missing
|
|
156
|
+
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
|
|
157
|
+
"RUF005", # Consider {expr} instead of concatenation
|
|
158
|
+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
|
|
159
|
+
"RUF015", # Prefer next({iterable}) over single element slice
|
|
160
|
+
"UP040", # Type alias `...` uses `TypeAlias` annotation instead of the `type` keyword - `mypy` not supported yet
|
|
161
|
+
"B008", # Do not perform function call `...` in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable
|
|
162
|
+
]
|
|
163
|
+
per-file-ignores = { "__init__.py" = [
|
|
164
|
+
"F401", # {name} imported but unused; consider using importlib.util.find_spec to test for availability
|
|
165
|
+
], "**/migrations/*.py" = [
|
|
166
|
+
"I001", # Import block is un-sorted or un-formatted
|
|
167
|
+
"I002", # Missing required import
|
|
168
|
+
], "**/test_*.py" = [
|
|
169
|
+
"PLR0124", # Name compared with itself, consider replacing {left} {} {right}
|
|
170
|
+
"PLR0915", # Too many statements ({statements} > {max_statements})
|
|
171
|
+
], "**/*.ipynb" = [
|
|
172
|
+
"T201", # `print` found
|
|
173
|
+
] }
|
|
174
|
+
select = [
|
|
175
|
+
"F", # Pyflakes (F) - https://docs.astral.sh/ruff/rules/#pyflakes-f
|
|
176
|
+
"E", # pycodestyle error (E) - https://docs.astral.sh/ruff/rules/#error-e
|
|
177
|
+
"I", # isort (I) - https://docs.astral.sh/ruff/rules/#isort-i
|
|
178
|
+
"UP", # pyupgrade (UP) - https://docs.astral.sh/ruff/rules/#pyupgrade-up
|
|
179
|
+
"YTT", # flake8-2020 (YTT) - https://docs.astral.sh/ruff/rules/#flake8-2020-ytt
|
|
180
|
+
"B", # flake8-bugbear (B) - https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
|
|
181
|
+
"C4", # flake8-comprehensions (C4) - https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
|
|
182
|
+
"COM", # flake8-commas (COM) - https://docs.astral.sh/ruff/rules/#flake8-commas-com
|
|
183
|
+
"T20", # flake8-print (T20) - https://docs.astral.sh/ruff/rules/#flake8-print-t20
|
|
184
|
+
"SLOT", # flake8-slots (SLOT) - https://docs.astral.sh/ruff/rules/#flake8-slots-slot
|
|
185
|
+
"RUF", # Ruff-specific (RUF) - https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
|
|
186
|
+
]
|
|
187
|
+
unfixable = []
|
|
188
|
+
|
|
189
|
+
[tool.ruff.lint.isort]
|
|
190
|
+
known-first-party = ["deweypy"]
|
|
191
|
+
required-imports = ["from __future__ import annotations"]
|
|
File without changes
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
from deweypy.context import main_context
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def set_api_key(
|
|
11
|
+
api_key: str,
|
|
12
|
+
*,
|
|
13
|
+
api_key_source: Literal[
|
|
14
|
+
"cli_args", "cli_fallback", "environment", "manually_set"
|
|
15
|
+
] = "manually_set",
|
|
16
|
+
) -> None:
|
|
17
|
+
if not api_key:
|
|
18
|
+
raise ValueError("API key cannot be empty.")
|
|
19
|
+
main_context.api_key = api_key.strip()
|
|
20
|
+
main_context.api_key_source = api_key_source
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def resolve_api_key(
|
|
24
|
+
*,
|
|
25
|
+
potentially_provided_value: str | None,
|
|
26
|
+
callback_if_missing: Callable[[], str],
|
|
27
|
+
invalid_exception_class: type[RuntimeError],
|
|
28
|
+
) -> tuple[str, Literal["provided", "environment", "callback"]]:
|
|
29
|
+
# If `potentially_provided_value` is non-empty, then use it.
|
|
30
|
+
if (cli_api_key := potentially_provided_value) is not None:
|
|
31
|
+
sanity_check_api_key_value(
|
|
32
|
+
cli_api_key,
|
|
33
|
+
invalid_exception_class=invalid_exception_class,
|
|
34
|
+
empty_message="The provided API Key cannot be empty.",
|
|
35
|
+
too_short_message="The provided API Key does not appear to be valid (sanity check, too short).",
|
|
36
|
+
)
|
|
37
|
+
return (cli_api_key, "provided")
|
|
38
|
+
|
|
39
|
+
# Otherwise, check the `DEWEY_API_KEY` environment variable and use that if
|
|
40
|
+
# it's present.
|
|
41
|
+
if env_apikey := os.environ.get("DEWEY_API_KEY"):
|
|
42
|
+
sanity_check_api_key_value(
|
|
43
|
+
env_apikey,
|
|
44
|
+
invalid_exception_class=invalid_exception_class,
|
|
45
|
+
empty_message=(
|
|
46
|
+
"The provided API Key from the environment variable DEWEY_API_KEY "
|
|
47
|
+
"cannot be empty."
|
|
48
|
+
),
|
|
49
|
+
too_short_message=(
|
|
50
|
+
"The provided API Key from the environment variable DEWEY_API_KEY does "
|
|
51
|
+
"not appear to be valid (sanity check, too short)."
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
return (env_apikey, "environment")
|
|
55
|
+
|
|
56
|
+
callback_api_key = callback_if_missing()
|
|
57
|
+
sanity_check_api_key_value(
|
|
58
|
+
callback_api_key, invalid_exception_class=invalid_exception_class
|
|
59
|
+
)
|
|
60
|
+
assert callback_api_key, "Post-condition"
|
|
61
|
+
return (callback_api_key, "callback")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def sanity_check_api_key_value(
|
|
65
|
+
api_key: str | None,
|
|
66
|
+
*,
|
|
67
|
+
invalid_exception_class: type[RuntimeError] | type[ValueError] = ValueError,
|
|
68
|
+
empty_message: str = "The API Key cannot be empty.",
|
|
69
|
+
too_short_message: str = "The API Key does not appear to be valid (sanity check, too short).",
|
|
70
|
+
) -> str:
|
|
71
|
+
if api_key in ("", None):
|
|
72
|
+
raise invalid_exception_class(empty_message)
|
|
73
|
+
assert api_key is not None, "Post-condition"
|
|
74
|
+
assert api_key != "", "Post-condition"
|
|
75
|
+
if len(api_key) <= 18:
|
|
76
|
+
raise invalid_exception_class(too_short_message)
|
|
77
|
+
return api_key
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from functools import lru_cache
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from textwrap import dedent
|
|
7
|
+
from typing import Any, Literal, NoReturn
|
|
8
|
+
|
|
9
|
+
from deweypy.display import ELLIPSIS_CHAR
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(kw_only=True)
|
|
13
|
+
class MainContext:
|
|
14
|
+
entrypoint: Literal["cli", "other", "unknown"] = "unknown"
|
|
15
|
+
|
|
16
|
+
_api_key: str = field(repr=False, default="")
|
|
17
|
+
api_key_source: Literal[
|
|
18
|
+
"cli_args", "cli_fallback", "environment", "manually_set", "unknown"
|
|
19
|
+
] = "unknown"
|
|
20
|
+
api_key_repr_preview: str = field(init=False, repr=True)
|
|
21
|
+
|
|
22
|
+
_download_directory: Path | None = field(default=None)
|
|
23
|
+
download_directory_repr_preview: str = field(init=False, repr=True)
|
|
24
|
+
download_directory_source: Literal[
|
|
25
|
+
"cli_args", "cli_fallback", "environment", "manually_set", "unknown"
|
|
26
|
+
] = "unknown"
|
|
27
|
+
|
|
28
|
+
def __post_init__(self):
|
|
29
|
+
self._set_api_key_repr_preview()
|
|
30
|
+
self._set_download_directory_repr_preview()
|
|
31
|
+
|
|
32
|
+
def __setattr__(self, name: str, value: Any):
|
|
33
|
+
parent_return_value = super().__setattr__(name, value)
|
|
34
|
+
if name == "_api_key":
|
|
35
|
+
self._set_api_key_repr_preview()
|
|
36
|
+
elif name == "_download_directory":
|
|
37
|
+
self._set_download_directory_repr_preview()
|
|
38
|
+
return parent_return_value
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def api_key(self) -> str:
|
|
42
|
+
if self._api_key:
|
|
43
|
+
return self._api_key
|
|
44
|
+
auth_module = _get_auth_module()
|
|
45
|
+
resolved_api_key = auth_module.resolve_api_key(
|
|
46
|
+
potentially_provided_value=self._api_key,
|
|
47
|
+
callback_if_missing=self._missing_api_key_callback,
|
|
48
|
+
invalid_exception_class=RuntimeError,
|
|
49
|
+
)
|
|
50
|
+
self._api_key = resolved_api_key
|
|
51
|
+
auth_module.sanity_check_api_key_value(self._api_key)
|
|
52
|
+
return resolved_api_key
|
|
53
|
+
|
|
54
|
+
@api_key.setter
|
|
55
|
+
def api_key(self, value: str):
|
|
56
|
+
self._api_key = value
|
|
57
|
+
self._set_api_key_repr_preview()
|
|
58
|
+
|
|
59
|
+
def _set_api_key_repr_preview(self):
|
|
60
|
+
if self._api_key in ("", None):
|
|
61
|
+
self.api_key_repr_preview = "not_set"
|
|
62
|
+
return
|
|
63
|
+
auth_module = _get_auth_module()
|
|
64
|
+
auth_module.sanity_check_api_key_value(self._api_key)
|
|
65
|
+
preview_value = self._api_key[:4] + ELLIPSIS_CHAR + self.api_key[-3:]
|
|
66
|
+
self.api_key_repr_preview = preview_value
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def _missing_api_key_callback() -> NoReturn:
|
|
70
|
+
raise RuntimeError(
|
|
71
|
+
dedent(
|
|
72
|
+
"""
|
|
73
|
+
The API Key is not set. You can set it via one of three ways:
|
|
74
|
+
1. If using `deweypy` directly from the shell/command line, you can
|
|
75
|
+
provide the --api-key option to set it.
|
|
76
|
+
2. Set the `DEWEY_API_KEY` environment variable.
|
|
77
|
+
3. If using `deweypy` as a Python library/module, you can call
|
|
78
|
+
`deweypy.auth.set_api_key()` with the API key as the argument.
|
|
79
|
+
For example:
|
|
80
|
+
```
|
|
81
|
+
import deweypy.auth
|
|
82
|
+
deweypy.auth.set_api_key("your_api_key_value...")
|
|
83
|
+
```
|
|
84
|
+
"""
|
|
85
|
+
).strip()
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def download_directory(self) -> Path:
|
|
90
|
+
if self._download_directory:
|
|
91
|
+
return self._download_directory
|
|
92
|
+
download_module = _get_download_module()
|
|
93
|
+
resolved_download_directory = download_module.resolve_download_directory(
|
|
94
|
+
potentially_provided_value=self._download_directory,
|
|
95
|
+
callback_if_missing=self._missing_download_directory_callback,
|
|
96
|
+
invalid_exception_class=RuntimeError,
|
|
97
|
+
)
|
|
98
|
+
self._download_directory = resolved_download_directory
|
|
99
|
+
download_module.sanity_check_download_directory_value(self._download_directory)
|
|
100
|
+
return resolved_download_directory
|
|
101
|
+
|
|
102
|
+
@download_directory.setter
|
|
103
|
+
def download_directory(self, value: Path):
|
|
104
|
+
self._download_directory = value
|
|
105
|
+
self._set_download_directory_repr_preview()
|
|
106
|
+
|
|
107
|
+
def _set_download_directory_repr_preview(self):
|
|
108
|
+
if self._download_directory in ("", None):
|
|
109
|
+
self.download_directory_repr_preview = "not_set"
|
|
110
|
+
return
|
|
111
|
+
download_module = _get_download_module()
|
|
112
|
+
download_module.sanity_check_download_directory_value(self._download_directory)
|
|
113
|
+
assert self._download_directory is not None, "Post-condition"
|
|
114
|
+
preview_value = self._download_directory.as_posix()
|
|
115
|
+
self.download_directory_repr_preview = preview_value
|
|
116
|
+
|
|
117
|
+
@staticmethod
|
|
118
|
+
def _missing_download_directory_callback() -> NoReturn:
|
|
119
|
+
raise RuntimeError(
|
|
120
|
+
dedent(
|
|
121
|
+
"""
|
|
122
|
+
The Download Directory is not set. You can set it via one of three ways:
|
|
123
|
+
1. If using `deweypy` directly from the shell/command line, you
|
|
124
|
+
can provide the --download-directory option to set it.
|
|
125
|
+
2. Set the `DEWEY_DOWNLOAD_DIRECTORY` environment variable.
|
|
126
|
+
3. If using `deweypy` as a Python library/module, you can call
|
|
127
|
+
`deweypy.downloads.set_download_directory()` with the
|
|
128
|
+
download directory as the argument. For example:
|
|
129
|
+
```
|
|
130
|
+
import deweypy.downloads
|
|
131
|
+
deweypy.downloads.set_download_directory("your_download_directory_value...")
|
|
132
|
+
```
|
|
133
|
+
"""
|
|
134
|
+
).strip()
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
main_context = MainContext()
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def set_entrypoint(entrypoint: Literal["cli", "other"]):
|
|
142
|
+
main_context.entrypoint = entrypoint
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@lru_cache(1)
|
|
146
|
+
def _get_auth_module():
|
|
147
|
+
from deweypy import auth as auth_module
|
|
148
|
+
|
|
149
|
+
return auth_module
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@lru_cache(1)
|
|
153
|
+
def _get_download_module():
|
|
154
|
+
from deweypy import download as download_module
|
|
155
|
+
|
|
156
|
+
return download_module
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .asynchronous import AsyncDatasetDownloader, async_api_request, make_async_client
|
|
4
|
+
from .settings import (
|
|
5
|
+
resolve_download_directory,
|
|
6
|
+
sanity_check_download_directory_value,
|
|
7
|
+
set_download_directory,
|
|
8
|
+
)
|
|
9
|
+
from .speedy import run_speedy_download
|
|
10
|
+
from .synchronous import DatasetDownloader, api_request, make_client
|