hammad-python 0.0.10__py3-none-any.whl → 0.0.12__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 (96) hide show
  1. hammad/__init__.py +177 -10
  2. hammad/_core/__init__.py +1 -0
  3. hammad/_core/_utils/__init__.py +4 -0
  4. hammad/_core/_utils/_import_utils.py +182 -0
  5. hammad/ai/__init__.py +59 -0
  6. hammad/ai/_utils.py +142 -0
  7. hammad/ai/completions/__init__.py +44 -0
  8. hammad/ai/completions/client.py +729 -0
  9. hammad/ai/completions/create.py +686 -0
  10. hammad/ai/completions/types.py +711 -0
  11. hammad/ai/completions/utils.py +374 -0
  12. hammad/ai/embeddings/__init__.py +35 -0
  13. hammad/ai/embeddings/client/__init__.py +1 -0
  14. hammad/ai/embeddings/client/base_embeddings_client.py +26 -0
  15. hammad/ai/embeddings/client/fastembed_text_embeddings_client.py +200 -0
  16. hammad/ai/embeddings/client/litellm_embeddings_client.py +288 -0
  17. hammad/ai/embeddings/create.py +159 -0
  18. hammad/ai/embeddings/types.py +69 -0
  19. hammad/base/__init__.py +35 -0
  20. hammad/base/fields.py +546 -0
  21. hammad/base/model.py +1078 -0
  22. hammad/base/utils.py +280 -0
  23. hammad/cache/__init__.py +48 -0
  24. hammad/cache/base_cache.py +181 -0
  25. hammad/cache/cache.py +169 -0
  26. hammad/cache/decorators.py +261 -0
  27. hammad/cache/file_cache.py +80 -0
  28. hammad/cache/ttl_cache.py +74 -0
  29. hammad/cli/__init__.py +33 -0
  30. hammad/cli/animations.py +604 -0
  31. hammad/cli/plugins.py +781 -0
  32. hammad/cli/styles/__init__.py +55 -0
  33. hammad/cli/styles/settings.py +139 -0
  34. hammad/cli/styles/types.py +358 -0
  35. hammad/cli/styles/utils.py +480 -0
  36. hammad/configuration/__init__.py +35 -0
  37. hammad/configuration/configuration.py +564 -0
  38. hammad/data/__init__.py +39 -0
  39. hammad/data/collections/__init__.py +34 -0
  40. hammad/data/collections/base_collection.py +58 -0
  41. hammad/data/collections/collection.py +452 -0
  42. hammad/data/collections/searchable_collection.py +556 -0
  43. hammad/data/collections/vector_collection.py +603 -0
  44. hammad/data/databases/__init__.py +21 -0
  45. hammad/data/databases/database.py +902 -0
  46. hammad/json/__init__.py +21 -0
  47. hammad/{utils/json → json}/converters.py +4 -1
  48. hammad/logging/__init__.py +35 -0
  49. hammad/logging/decorators.py +834 -0
  50. hammad/logging/logger.py +954 -0
  51. hammad/multimodal/__init__.py +24 -0
  52. hammad/multimodal/audio.py +96 -0
  53. hammad/multimodal/image.py +80 -0
  54. hammad/multithreading/__init__.py +304 -0
  55. hammad/pydantic/__init__.py +43 -0
  56. hammad/{utils/pydantic → pydantic}/converters.py +2 -1
  57. hammad/pydantic/models/__init__.py +28 -0
  58. hammad/pydantic/models/arbitrary_model.py +46 -0
  59. hammad/pydantic/models/cacheable_model.py +79 -0
  60. hammad/pydantic/models/fast_model.py +318 -0
  61. hammad/pydantic/models/function_model.py +176 -0
  62. hammad/pydantic/models/subscriptable_model.py +63 -0
  63. hammad/text/__init__.py +82 -0
  64. hammad/text/converters.py +723 -0
  65. hammad/{utils/markdown/formatting.py → text/markdown.py} +25 -23
  66. hammad/text/text.py +1066 -0
  67. hammad/types/__init__.py +11 -0
  68. hammad/types/file.py +358 -0
  69. hammad/{utils/typing/utils.py → typing/__init__.py} +142 -15
  70. hammad/web/__init__.py +43 -0
  71. hammad/web/http/__init__.py +1 -0
  72. hammad/web/http/client.py +944 -0
  73. hammad/web/models.py +245 -0
  74. hammad/web/openapi/client.py +740 -0
  75. hammad/web/search/__init__.py +1 -0
  76. hammad/web/search/client.py +988 -0
  77. hammad/web/utils.py +472 -0
  78. hammad/yaml/__init__.py +30 -0
  79. hammad/yaml/converters.py +19 -0
  80. {hammad_python-0.0.10.dist-info → hammad_python-0.0.12.dist-info}/METADATA +16 -7
  81. hammad_python-0.0.12.dist-info/RECORD +85 -0
  82. hammad/cache.py +0 -675
  83. hammad/database.py +0 -447
  84. hammad/logger.py +0 -273
  85. hammad/types/color.py +0 -951
  86. hammad/utils/markdown/__init__.py +0 -0
  87. hammad/utils/markdown/converters.py +0 -506
  88. hammad/utils/pydantic/__init__.py +0 -0
  89. hammad/utils/text/__init__.py +0 -0
  90. hammad/utils/text/converters.py +0 -229
  91. hammad/utils/typing/__init__.py +0 -0
  92. hammad_python-0.0.10.dist-info/RECORD +0 -22
  93. /hammad/{utils/__init__.py → py.typed} +0 -0
  94. /hammad/{utils/json → web/openapi}/__init__.py +0 -0
  95. {hammad_python-0.0.10.dist-info → hammad_python-0.0.12.dist-info}/WHEEL +0 -0
  96. {hammad_python-0.0.10.dist-info → hammad_python-0.0.12.dist-info}/licenses/LICENSE +0 -0
@@ -1,229 +0,0 @@
1
- """hammad.utils.text.converters"""
2
-
3
- from docstring_parser import parse
4
- from typing import (
5
- Any,
6
- Optional,
7
- )
8
-
9
- from ..typing.utils import (
10
- inspection,
11
- is_pydantic_basemodel,
12
- is_msgspec_struct,
13
- is_dataclass,
14
- )
15
-
16
- __all__ = [
17
- "convert_type_to_text",
18
- "convert_docstring_to_text",
19
- ]
20
-
21
-
22
- def convert_type_to_text(cls: Any) -> str:
23
- """Converts a type into a clean & human readable text representation.
24
-
25
- This function uses `typing_inspect` exclusively to infer nested types
26
- within `Optional`, `Union` types, for the cleanest possible string
27
- representation of a type.
28
-
29
- Args:
30
- cls: The type to convert to a text representation.
31
-
32
- Returns:
33
- A clean, human-readable string representation of the type.
34
- """
35
- # Handle None type
36
- if cls is None or cls is type(None):
37
- return "None"
38
-
39
- # Get origin and args using typing_inspect for better type handling
40
- origin = inspection.get_origin(cls)
41
- args = inspection.get_args(cls)
42
-
43
- if origin is not None:
44
- # Handle Optional (Union[T, None])
45
- if inspection.is_optional_type(cls):
46
- # Recursively get the name of the inner type (the one not None)
47
- inner_type = args[0]
48
- inner_type_name = convert_type_to_text(inner_type)
49
- return f"Optional[{inner_type_name}]"
50
-
51
- # Handle other Union types
52
- if inspection.is_union_type(cls):
53
- # Recursively get names of all arguments in the Union
54
- args_str = ", ".join(convert_type_to_text(arg) for arg in args)
55
- return f"Union[{args_str}]"
56
-
57
- # Handle other generic types (List, Dict, Tuple, Set, etc.)
58
- # Use origin.__name__ for built-in generics like list, dict, tuple, set
59
- origin_name = getattr(origin, "__name__", str(origin).split(".")[-1])
60
- if origin_name.startswith("_"): # Handle internal typing names like _List
61
- origin_name = origin_name[1:]
62
-
63
- # Convert to lowercase for built-in types to match modern Python style
64
- if origin_name in ["List", "Dict", "Tuple", "Set"]:
65
- origin_name = origin_name.lower()
66
-
67
- if args: # If there are type arguments
68
- # Recursively get names of type arguments
69
- args_str = ", ".join(convert_type_to_text(arg) for arg in args)
70
- return f"{origin_name}[{args_str}]"
71
- else: # Generic without arguments (e.g., typing.List)
72
- return origin_name
73
-
74
- # Handle special cases with typing_inspect
75
- if inspection.is_typevar(cls):
76
- return str(cls)
77
- if inspection.is_forward_ref(cls):
78
- return str(cls)
79
- if inspection.is_literal_type(cls):
80
- return f"Literal[{', '.join(str(arg) for arg in args)}]"
81
- if inspection.is_final_type(cls):
82
- return f"Final[{convert_type_to_text(args[0])}]" if args else "Final"
83
- if inspection.is_new_type(cls):
84
- return str(cls)
85
-
86
- # Handle Pydantic BaseModel types
87
- if is_pydantic_basemodel(cls):
88
- if hasattr(cls, "__name__"):
89
- return cls.__name__
90
- return "BaseModel"
91
-
92
- # Handle msgspec Struct types
93
- if is_msgspec_struct(cls):
94
- if hasattr(cls, "__name__"):
95
- return cls.__name__
96
- return "Struct"
97
-
98
- # Handle dataclass types
99
- if is_dataclass(cls):
100
- if hasattr(cls, "__name__"):
101
- return cls.__name__
102
- return "dataclass"
103
-
104
- # Handle basic types with __name__ attribute
105
- if hasattr(cls, "__name__") and cls.__name__ != "<lambda>":
106
- return cls.__name__
107
-
108
- # Special handling for Optional type string representation
109
- if str(cls).startswith("typing.Optional"):
110
- # Extract the inner type from the string representation
111
- inner_type_str = str(cls).replace("typing.Optional[", "").rstrip("]")
112
- return f"Optional[{inner_type_str}]"
113
-
114
- # Fallback for any other types
115
- # Clean up 'typing.' prefix and handle other common representations
116
- return str(cls).replace("typing.", "").replace("__main__.", "")
117
-
118
-
119
- def convert_docstring_to_text(
120
- obj: Any,
121
- *,
122
- params_override: Optional[str] = None,
123
- returns_override: Optional[str] = None,
124
- raises_override: Optional[str] = None,
125
- examples_override: Optional[str] = None,
126
- params_prefix: Optional[str] = None,
127
- returns_prefix: Optional[str] = None,
128
- raises_prefix: Optional[str] = None,
129
- exclude_params: bool = False,
130
- exclude_returns: bool = False,
131
- exclude_raises: bool = False,
132
- exclude_examples: bool = False,
133
- ) -> str:
134
- """
135
- Convert an object's docstring to formatted text using docstring_parser.
136
-
137
- Args:
138
- obj: The object to extract docstring from
139
- params_override: Override text for parameters section
140
- returns_override: Override text for returns section
141
- raises_override: Override text for raises section
142
- examples_override: Override text for examples section
143
- params_prefix: Prefix for parameters section
144
- returns_prefix: Prefix for returns section
145
- raises_prefix: Prefix for raises section
146
- exclude_params: Whether to exclude parameters section
147
- exclude_returns: Whether to exclude returns section
148
- exclude_raises: Whether to exclude raises section
149
- exclude_examples: Whether to exclude examples section
150
-
151
- Returns:
152
- Formatted text representation of the docstring
153
- """
154
- # Get the raw docstring
155
- doc = getattr(obj, "__doc__", None)
156
- if not doc:
157
- return ""
158
-
159
- try:
160
- # Parse the docstring using docstring_parser
161
- parsed = parse(doc)
162
-
163
- parts = []
164
-
165
- # Add short description
166
- if parsed.short_description:
167
- parts.append(parsed.short_description)
168
-
169
- # Add long description
170
- if parsed.long_description:
171
- parts.append("") # Empty line separator
172
- parts.append(parsed.long_description)
173
-
174
- # Add parameters section
175
- if not exclude_params and (params_override or parsed.params):
176
- parts.append("") # Empty line separator
177
- if params_override:
178
- parts.append(params_override)
179
- else:
180
- prefix = params_prefix or "Parameters:"
181
- parts.append(prefix)
182
- for param in parsed.params:
183
- param_line = f" {param.arg_name}"
184
- if param.type_name:
185
- param_line += f" ({param.type_name})"
186
- if param.description:
187
- param_line += f": {param.description}"
188
- parts.append(param_line)
189
-
190
- # Add returns section
191
- if not exclude_returns and (returns_override or parsed.returns):
192
- parts.append("") # Empty line separator
193
- if returns_override:
194
- parts.append(returns_override)
195
- else:
196
- prefix = returns_prefix or "Returns:"
197
- parts.append(prefix)
198
- if parsed.returns:
199
- return_line = " "
200
- if parsed.returns.type_name:
201
- return_line += f"{parsed.returns.type_name}: "
202
- if parsed.returns.description:
203
- return_line += parsed.returns.description
204
- parts.append(return_line)
205
-
206
- # Add raises section
207
- if not exclude_raises and (raises_override or parsed.raises):
208
- parts.append("") # Empty line separator
209
- if raises_override:
210
- parts.append(raises_override)
211
- else:
212
- prefix = raises_prefix or "Raises:"
213
- parts.append(prefix)
214
- for exc in parsed.raises:
215
- exc_line = f" {exc.type_name or 'Exception'}"
216
- if exc.description:
217
- exc_line += f": {exc.description}"
218
- parts.append(exc_line)
219
-
220
- # Add examples section (if available in parsed docstring)
221
- if not exclude_examples and examples_override:
222
- parts.append("") # Empty line separator
223
- parts.append(examples_override)
224
-
225
- return "\n".join(parts)
226
-
227
- except Exception:
228
- # Fallback to raw docstring if parsing fails
229
- return doc.strip()
File without changes
@@ -1,22 +0,0 @@
1
- hammad/__init__.py,sha256=-czVIC0b9FyrYDIlD67WSMUy_nA1UMiiyspkxfz7Tfw,536
2
- hammad/cache.py,sha256=NfOB_JzoTxw-F53tVT7qkFkUUPxaBYHyprm7NCvO9MY,23213
3
- hammad/database.py,sha256=9fXmMTRJuohKYmwG90IyXlSSeWnWSj44o5gRhubGYlM,15092
4
- hammad/logger.py,sha256=_dIDUy-AV_7HyiUOO1EOrh9qaE00SmOeWzlLcGACUVI,8717
5
- hammad/types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- hammad/types/color.py,sha256=lfRBqvc-QVgstNF9-4Fyrkoj9XHGNlvRau91imHJzfc,23330
7
- hammad/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- hammad/utils/json/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- hammad/utils/json/converters.py,sha256=9xOw2nMBQzZdRbaZcmBMlsHWdKjo8ckPxcbWhm9666I,5388
10
- hammad/utils/markdown/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- hammad/utils/markdown/converters.py,sha256=Xw6gthRxsX4sRT52owO74cJnPCmPV85qe2yMVGC3mb4,15403
12
- hammad/utils/markdown/formatting.py,sha256=gbK64OitGyPvVL9O-tsp2DzgxqNMl7VhADakklbpCR0,3204
13
- hammad/utils/pydantic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- hammad/utils/pydantic/converters.py,sha256=89vhpcPbzL3xfuuoFfmpR0PeWe_nM_3GjGiU7pL-xbw,20192
15
- hammad/utils/text/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- hammad/utils/text/converters.py,sha256=eB9_53c0GmjhFppXqw_ISSq6UgbzJ_mrWDiKjTrln08,8213
17
- hammad/utils/typing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- hammad/utils/typing/utils.py,sha256=oJCyw5J8BmZh5TIB04kslZown_x6HQXz5zjbRsoVCtA,8431
19
- hammad_python-0.0.10.dist-info/METADATA,sha256=4oDvdUYeEFmHyZCn_1QEBDNcj6aIdp4252JrQ9yQ1Vk,1106
20
- hammad_python-0.0.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
21
- hammad_python-0.0.10.dist-info/licenses/LICENSE,sha256=h74yFUWjbBaodcWG5wNmm30npjl8obVcxD-1nQfUp2I,1069
22
- hammad_python-0.0.10.dist-info/RECORD,,
File without changes
File without changes