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.
Files changed (74) hide show
  1. hammad/__init__.py +64 -10
  2. hammad/based/__init__.py +52 -0
  3. hammad/based/fields.py +546 -0
  4. hammad/based/model.py +968 -0
  5. hammad/based/utils.py +455 -0
  6. hammad/cache/__init__.py +30 -0
  7. hammad/{cache.py → cache/_cache.py} +83 -12
  8. hammad/cli/__init__.py +25 -0
  9. hammad/cli/plugins/__init__.py +786 -0
  10. hammad/cli/styles/__init__.py +5 -0
  11. hammad/cli/styles/animations.py +548 -0
  12. hammad/cli/styles/settings.py +135 -0
  13. hammad/cli/styles/types.py +358 -0
  14. hammad/cli/styles/utils.py +480 -0
  15. hammad/data/__init__.py +51 -0
  16. hammad/data/collections/__init__.py +32 -0
  17. hammad/data/collections/base_collection.py +58 -0
  18. hammad/data/collections/collection.py +227 -0
  19. hammad/data/collections/searchable_collection.py +556 -0
  20. hammad/data/collections/vector_collection.py +497 -0
  21. hammad/data/databases/__init__.py +21 -0
  22. hammad/data/databases/database.py +551 -0
  23. hammad/data/types/__init__.py +33 -0
  24. hammad/data/types/files/__init__.py +1 -0
  25. hammad/data/types/files/audio.py +81 -0
  26. hammad/data/types/files/configuration.py +475 -0
  27. hammad/data/types/files/document.py +195 -0
  28. hammad/data/types/files/file.py +358 -0
  29. hammad/data/types/files/image.py +80 -0
  30. hammad/json/__init__.py +21 -0
  31. hammad/{utils/json → json}/converters.py +4 -1
  32. hammad/logging/__init__.py +27 -0
  33. hammad/logging/decorators.py +432 -0
  34. hammad/logging/logger.py +534 -0
  35. hammad/pydantic/__init__.py +43 -0
  36. hammad/{utils/pydantic → pydantic}/converters.py +2 -1
  37. hammad/pydantic/models/__init__.py +28 -0
  38. hammad/pydantic/models/arbitrary_model.py +46 -0
  39. hammad/pydantic/models/cacheable_model.py +79 -0
  40. hammad/pydantic/models/fast_model.py +318 -0
  41. hammad/pydantic/models/function_model.py +176 -0
  42. hammad/pydantic/models/subscriptable_model.py +63 -0
  43. hammad/text/__init__.py +37 -0
  44. hammad/text/text.py +1068 -0
  45. hammad/text/utils/__init__.py +1 -0
  46. hammad/{utils/text → text/utils}/converters.py +2 -2
  47. hammad/text/utils/markdown/__init__.py +1 -0
  48. hammad/{utils → text/utils}/markdown/converters.py +3 -3
  49. hammad/{utils → text/utils}/markdown/formatting.py +1 -1
  50. hammad/{utils/typing/utils.py → typing/__init__.py} +75 -2
  51. hammad/web/__init__.py +42 -0
  52. hammad/web/http/__init__.py +1 -0
  53. hammad/web/http/client.py +944 -0
  54. hammad/web/openapi/client.py +740 -0
  55. hammad/web/search/__init__.py +1 -0
  56. hammad/web/search/client.py +936 -0
  57. hammad/web/utils.py +463 -0
  58. hammad/yaml/__init__.py +30 -0
  59. hammad/yaml/converters.py +19 -0
  60. {hammad_python-0.0.10.dist-info → hammad_python-0.0.11.dist-info}/METADATA +14 -8
  61. hammad_python-0.0.11.dist-info/RECORD +65 -0
  62. hammad/database.py +0 -447
  63. hammad/logger.py +0 -273
  64. hammad/types/color.py +0 -951
  65. hammad/utils/json/__init__.py +0 -0
  66. hammad/utils/markdown/__init__.py +0 -0
  67. hammad/utils/pydantic/__init__.py +0 -0
  68. hammad/utils/text/__init__.py +0 -0
  69. hammad/utils/typing/__init__.py +0 -0
  70. hammad_python-0.0.10.dist-info/RECORD +0 -22
  71. /hammad/{types/__init__.py → py.typed} +0 -0
  72. /hammad/{utils → web/openapi}/__init__.py +0 -0
  73. {hammad_python-0.0.10.dist-info → hammad_python-0.0.11.dist-info}/WHEEL +0 -0
  74. {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.text.converters"""
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 ..typing.utils import (
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 ..typing.utils import (
18
+ from ....typing import (
19
19
  is_pydantic_basemodel,
20
20
  is_pydantic_basemodel_instance,
21
21
  is_msgspec_struct,
22
22
  )
23
- from ..text.converters import convert_type_to_text as convert_type_to_string
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.markdown.formatting"""
1
+ """hammad.text.utils.markdown.formatting"""
2
2
 
3
3
  from typing import (
4
4
  List,
@@ -1,4 +1,4 @@
1
- """hammad.utils.typing.utils
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"""