hammad-python 0.0.10__py3-none-any.whl → 0.0.11__py3-none-any.whl
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.
- hammad/__init__.py +64 -10
- hammad/based/__init__.py +52 -0
- hammad/based/fields.py +546 -0
- hammad/based/model.py +968 -0
- hammad/based/utils.py +455 -0
- hammad/cache/__init__.py +30 -0
- hammad/{cache.py → cache/_cache.py} +83 -12
- hammad/cli/__init__.py +25 -0
- hammad/cli/plugins/__init__.py +786 -0
- hammad/cli/styles/__init__.py +5 -0
- hammad/cli/styles/animations.py +548 -0
- hammad/cli/styles/settings.py +135 -0
- hammad/cli/styles/types.py +358 -0
- hammad/cli/styles/utils.py +480 -0
- hammad/data/__init__.py +51 -0
- hammad/data/collections/__init__.py +32 -0
- hammad/data/collections/base_collection.py +58 -0
- hammad/data/collections/collection.py +227 -0
- hammad/data/collections/searchable_collection.py +556 -0
- hammad/data/collections/vector_collection.py +497 -0
- hammad/data/databases/__init__.py +21 -0
- hammad/data/databases/database.py +551 -0
- hammad/data/types/__init__.py +33 -0
- hammad/data/types/files/__init__.py +1 -0
- hammad/data/types/files/audio.py +81 -0
- hammad/data/types/files/configuration.py +475 -0
- hammad/data/types/files/document.py +195 -0
- hammad/data/types/files/file.py +358 -0
- hammad/data/types/files/image.py +80 -0
- hammad/json/__init__.py +21 -0
- hammad/{utils/json → json}/converters.py +4 -1
- hammad/logging/__init__.py +27 -0
- hammad/logging/decorators.py +432 -0
- hammad/logging/logger.py +534 -0
- hammad/pydantic/__init__.py +43 -0
- hammad/{utils/pydantic → pydantic}/converters.py +2 -1
- hammad/pydantic/models/__init__.py +28 -0
- hammad/pydantic/models/arbitrary_model.py +46 -0
- hammad/pydantic/models/cacheable_model.py +79 -0
- hammad/pydantic/models/fast_model.py +318 -0
- hammad/pydantic/models/function_model.py +176 -0
- hammad/pydantic/models/subscriptable_model.py +63 -0
- hammad/text/__init__.py +37 -0
- hammad/text/text.py +1068 -0
- hammad/text/utils/__init__.py +1 -0
- hammad/{utils/text → text/utils}/converters.py +2 -2
- hammad/text/utils/markdown/__init__.py +1 -0
- hammad/{utils → text/utils}/markdown/converters.py +3 -3
- hammad/{utils → text/utils}/markdown/formatting.py +1 -1
- hammad/{utils/typing/utils.py → typing/__init__.py} +75 -2
- hammad/web/__init__.py +42 -0
- hammad/web/http/__init__.py +1 -0
- hammad/web/http/client.py +944 -0
- hammad/web/openapi/client.py +740 -0
- hammad/web/search/__init__.py +1 -0
- hammad/web/search/client.py +936 -0
- hammad/web/utils.py +463 -0
- hammad/yaml/__init__.py +30 -0
- hammad/yaml/converters.py +19 -0
- {hammad_python-0.0.10.dist-info → hammad_python-0.0.11.dist-info}/METADATA +14 -8
- hammad_python-0.0.11.dist-info/RECORD +65 -0
- hammad/database.py +0 -447
- hammad/logger.py +0 -273
- hammad/types/color.py +0 -951
- hammad/utils/json/__init__.py +0 -0
- hammad/utils/markdown/__init__.py +0 -0
- hammad/utils/pydantic/__init__.py +0 -0
- hammad/utils/text/__init__.py +0 -0
- hammad/utils/typing/__init__.py +0 -0
- hammad_python-0.0.10.dist-info/RECORD +0 -22
- /hammad/{types/__init__.py → py.typed} +0 -0
- /hammad/{utils → web/openapi}/__init__.py +0 -0
- {hammad_python-0.0.10.dist-info → hammad_python-0.0.11.dist-info}/WHEEL +0 -0
- {hammad_python-0.0.10.dist-info → hammad_python-0.0.11.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
"""hammad.text.utils"""
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"""hammad.utils.
|
1
|
+
"""hammad.text.utils.converters"""
|
2
2
|
|
3
3
|
from docstring_parser import parse
|
4
4
|
from typing import (
|
@@ -6,7 +6,7 @@ from typing import (
|
|
6
6
|
Optional,
|
7
7
|
)
|
8
8
|
|
9
|
-
from
|
9
|
+
from ...typing import (
|
10
10
|
inspection,
|
11
11
|
is_pydantic_basemodel,
|
12
12
|
is_msgspec_struct,
|
@@ -0,0 +1 @@
|
|
1
|
+
"""hammad.text.utils.markdown"""
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"""hammad.utils.markdown.converters"""
|
1
|
+
"""hammad.text.utils.markdown.converters"""
|
2
2
|
|
3
3
|
import json
|
4
4
|
import logging
|
@@ -15,12 +15,12 @@ from typing import (
|
|
15
15
|
Union,
|
16
16
|
)
|
17
17
|
|
18
|
-
from
|
18
|
+
from ....typing import (
|
19
19
|
is_pydantic_basemodel,
|
20
20
|
is_pydantic_basemodel_instance,
|
21
21
|
is_msgspec_struct,
|
22
22
|
)
|
23
|
-
from
|
23
|
+
from ...utils.converters import convert_type_to_text as convert_type_to_string
|
24
24
|
from .formatting import (
|
25
25
|
bold,
|
26
26
|
italic,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"""hammad.utils.typing
|
1
|
+
"""hammad.utils.typing
|
2
2
|
|
3
3
|
Contains various utility functions in regards to typing or working
|
4
4
|
with type hints. These utils are also exposed in:
|
@@ -11,7 +11,7 @@ hammad.typing.get_type_description(Optional[int])
|
|
11
11
|
```
|
12
12
|
"""
|
13
13
|
|
14
|
-
from typing import Any
|
14
|
+
from typing import Any, TYPE_CHECKING
|
15
15
|
import typing_inspect as inspection
|
16
16
|
from typing_inspect import (
|
17
17
|
is_callable_type,
|
@@ -63,6 +63,10 @@ __all__ = (
|
|
63
63
|
"is_union_origin",
|
64
64
|
"inspect_annotation",
|
65
65
|
"get_literal_values",
|
66
|
+
"get_last_args",
|
67
|
+
"get_last_origin",
|
68
|
+
"get_generic_bases",
|
69
|
+
"get_typed_dict_keys",
|
66
70
|
)
|
67
71
|
|
68
72
|
|
@@ -278,3 +282,72 @@ def get_type_description(t: Any) -> str:
|
|
278
282
|
return f"typevar({t.__name__})"
|
279
283
|
|
280
284
|
return str(t)
|
285
|
+
|
286
|
+
|
287
|
+
if TYPE_CHECKING:
|
288
|
+
pass
|
289
|
+
|
290
|
+
|
291
|
+
def create_lazy_loader(imports_dict: dict[str, str], package: str):
|
292
|
+
"""Create a lazy loader function for __getattr__.
|
293
|
+
|
294
|
+
Args:
|
295
|
+
imports_dict: Dictionary mapping attribute names to their module paths
|
296
|
+
package: The package name for import_module
|
297
|
+
|
298
|
+
Returns:
|
299
|
+
A __getattr__ function that lazily imports modules
|
300
|
+
"""
|
301
|
+
|
302
|
+
def __getattr__(name: str):
|
303
|
+
if name in imports_dict:
|
304
|
+
from importlib import import_module
|
305
|
+
|
306
|
+
module = import_module(imports_dict[name], package)
|
307
|
+
return getattr(module, name)
|
308
|
+
raise AttributeError(f"module '{package}' has no attribute '{name}'")
|
309
|
+
|
310
|
+
return __getattr__
|
311
|
+
|
312
|
+
|
313
|
+
def parse_type_checking_imports(source_code: str) -> dict[str, str]:
|
314
|
+
"""Parse TYPE_CHECKING imports from source code to build import map.
|
315
|
+
|
316
|
+
This is a simple parser that extracts import information from
|
317
|
+
TYPE_CHECKING blocks to automatically build the module map.
|
318
|
+
|
319
|
+
Args:
|
320
|
+
source_code: The source code containing TYPE_CHECKING imports
|
321
|
+
|
322
|
+
Returns:
|
323
|
+
Dictionary mapping imported names to their module paths
|
324
|
+
"""
|
325
|
+
import ast
|
326
|
+
import re
|
327
|
+
|
328
|
+
# Parse the source code
|
329
|
+
tree = ast.parse(source_code)
|
330
|
+
|
331
|
+
imports_map = {}
|
332
|
+
in_type_checking = False
|
333
|
+
|
334
|
+
for node in ast.walk(tree):
|
335
|
+
# Check if we're in a TYPE_CHECKING block
|
336
|
+
if isinstance(node, ast.If):
|
337
|
+
if (
|
338
|
+
isinstance(node.test, ast.Name) and node.test.id == "TYPE_CHECKING"
|
339
|
+
) or (
|
340
|
+
isinstance(node.test, ast.Attribute)
|
341
|
+
and isinstance(node.test.value, ast.Name)
|
342
|
+
and node.test.value.id == "typing"
|
343
|
+
and node.test.attr == "TYPE_CHECKING"
|
344
|
+
):
|
345
|
+
# Process imports in the TYPE_CHECKING block
|
346
|
+
for stmt in node.body:
|
347
|
+
if isinstance(stmt, ast.ImportFrom):
|
348
|
+
module = stmt.module or ""
|
349
|
+
for alias in stmt.names:
|
350
|
+
name = alias.asname or alias.name
|
351
|
+
imports_map[name] = f".{module}"
|
352
|
+
|
353
|
+
return imports_map
|
hammad/web/__init__.py
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
"""hammad.web"""
|
2
|
+
|
3
|
+
from typing import TYPE_CHECKING
|
4
|
+
from ..based.utils import auto_create_lazy_loader
|
5
|
+
|
6
|
+
if TYPE_CHECKING:
|
7
|
+
from .utils import (
|
8
|
+
run_web_request,
|
9
|
+
read_web_page,
|
10
|
+
read_web_pages,
|
11
|
+
search_web,
|
12
|
+
search_news,
|
13
|
+
extract_page_links,
|
14
|
+
)
|
15
|
+
from .http.client import AsyncHttpClient, HttpClient, create_http_client
|
16
|
+
from .openapi.client import AsyncOpenAPIClient, OpenAPIClient, create_openapi_client
|
17
|
+
from .search.client import AsyncSearchClient, SearchClient, create_search_client
|
18
|
+
|
19
|
+
__all__ = (
|
20
|
+
"run_web_request",
|
21
|
+
"read_web_page",
|
22
|
+
"read_web_pages",
|
23
|
+
"search_web",
|
24
|
+
"search_news",
|
25
|
+
"extract_page_links",
|
26
|
+
"AsyncHttpClient",
|
27
|
+
"HttpClient",
|
28
|
+
"create_http_client",
|
29
|
+
"AsyncOpenAPIClient",
|
30
|
+
"OpenAPIClient",
|
31
|
+
"create_openapi_client",
|
32
|
+
"AsyncSearchClient",
|
33
|
+
"SearchClient",
|
34
|
+
"create_search_client",
|
35
|
+
)
|
36
|
+
|
37
|
+
__getattr__ = auto_create_lazy_loader(__all__)
|
38
|
+
|
39
|
+
|
40
|
+
def __dir__() -> list[str]:
|
41
|
+
"""Get the attributes of the web module."""
|
42
|
+
return list(__all__)
|
@@ -0,0 +1 @@
|
|
1
|
+
"""hammad.web.http"""
|