hammad-python 0.0.13__py3-none-any.whl → 0.0.15__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 (87) hide show
  1. hammad_python-0.0.15.dist-info/METADATA +184 -0
  2. hammad_python-0.0.15.dist-info/RECORD +4 -0
  3. hammad/__init__.py +0 -180
  4. hammad/_core/__init__.py +0 -1
  5. hammad/_core/_utils/__init__.py +0 -4
  6. hammad/_core/_utils/_import_utils.py +0 -182
  7. hammad/ai/__init__.py +0 -59
  8. hammad/ai/_utils.py +0 -142
  9. hammad/ai/completions/__init__.py +0 -44
  10. hammad/ai/completions/client.py +0 -729
  11. hammad/ai/completions/create.py +0 -686
  12. hammad/ai/completions/types.py +0 -711
  13. hammad/ai/completions/utils.py +0 -374
  14. hammad/ai/embeddings/__init__.py +0 -35
  15. hammad/ai/embeddings/client/__init__.py +0 -1
  16. hammad/ai/embeddings/client/base_embeddings_client.py +0 -26
  17. hammad/ai/embeddings/client/fastembed_text_embeddings_client.py +0 -200
  18. hammad/ai/embeddings/client/litellm_embeddings_client.py +0 -288
  19. hammad/ai/embeddings/create.py +0 -159
  20. hammad/ai/embeddings/types.py +0 -69
  21. hammad/base/__init__.py +0 -35
  22. hammad/base/fields.py +0 -546
  23. hammad/base/model.py +0 -1078
  24. hammad/base/utils.py +0 -280
  25. hammad/cache/__init__.py +0 -48
  26. hammad/cache/base_cache.py +0 -181
  27. hammad/cache/cache.py +0 -169
  28. hammad/cache/decorators.py +0 -261
  29. hammad/cache/file_cache.py +0 -80
  30. hammad/cache/ttl_cache.py +0 -74
  31. hammad/cli/__init__.py +0 -33
  32. hammad/cli/animations.py +0 -604
  33. hammad/cli/plugins.py +0 -781
  34. hammad/cli/styles/__init__.py +0 -55
  35. hammad/cli/styles/settings.py +0 -139
  36. hammad/cli/styles/types.py +0 -358
  37. hammad/cli/styles/utils.py +0 -480
  38. hammad/configuration/__init__.py +0 -35
  39. hammad/configuration/configuration.py +0 -564
  40. hammad/data/__init__.py +0 -39
  41. hammad/data/collections/__init__.py +0 -34
  42. hammad/data/collections/base_collection.py +0 -58
  43. hammad/data/collections/collection.py +0 -452
  44. hammad/data/collections/searchable_collection.py +0 -556
  45. hammad/data/collections/vector_collection.py +0 -603
  46. hammad/data/databases/__init__.py +0 -21
  47. hammad/data/databases/database.py +0 -902
  48. hammad/json/__init__.py +0 -21
  49. hammad/json/converters.py +0 -152
  50. hammad/logging/__init__.py +0 -35
  51. hammad/logging/decorators.py +0 -834
  52. hammad/logging/logger.py +0 -954
  53. hammad/multimodal/__init__.py +0 -24
  54. hammad/multimodal/audio.py +0 -96
  55. hammad/multimodal/image.py +0 -80
  56. hammad/multithreading/__init__.py +0 -304
  57. hammad/py.typed +0 -0
  58. hammad/pydantic/__init__.py +0 -43
  59. hammad/pydantic/converters.py +0 -623
  60. hammad/pydantic/models/__init__.py +0 -28
  61. hammad/pydantic/models/arbitrary_model.py +0 -46
  62. hammad/pydantic/models/cacheable_model.py +0 -79
  63. hammad/pydantic/models/fast_model.py +0 -318
  64. hammad/pydantic/models/function_model.py +0 -176
  65. hammad/pydantic/models/subscriptable_model.py +0 -63
  66. hammad/text/__init__.py +0 -82
  67. hammad/text/converters.py +0 -723
  68. hammad/text/markdown.py +0 -131
  69. hammad/text/text.py +0 -1066
  70. hammad/types/__init__.py +0 -11
  71. hammad/types/file.py +0 -358
  72. hammad/typing/__init__.py +0 -407
  73. hammad/web/__init__.py +0 -43
  74. hammad/web/http/__init__.py +0 -1
  75. hammad/web/http/client.py +0 -944
  76. hammad/web/models.py +0 -245
  77. hammad/web/openapi/__init__.py +0 -0
  78. hammad/web/openapi/client.py +0 -740
  79. hammad/web/search/__init__.py +0 -1
  80. hammad/web/search/client.py +0 -988
  81. hammad/web/utils.py +0 -472
  82. hammad/yaml/__init__.py +0 -30
  83. hammad/yaml/converters.py +0 -19
  84. hammad_python-0.0.13.dist-info/METADATA +0 -38
  85. hammad_python-0.0.13.dist-info/RECORD +0 -85
  86. {hammad_python-0.0.13.dist-info → hammad_python-0.0.15.dist-info}/WHEEL +0 -0
  87. {hammad_python-0.0.13.dist-info → hammad_python-0.0.15.dist-info}/licenses/LICENSE +0 -0
@@ -1,480 +0,0 @@
1
- """hammad.cli.styles.utils"""
2
-
3
- import time
4
- from typing import Optional, TYPE_CHECKING
5
-
6
- if TYPE_CHECKING:
7
- from rich import get_console as get_rich_console
8
- from rich.console import Console, RenderableType
9
- from rich.live import Live
10
- from rich.panel import Panel
11
- from rich.style import Style
12
- from rich.text import Text
13
-
14
- from .types import (
15
- CLIStyleError,
16
- CLIStyleType,
17
- CLIStyleBackgroundType,
18
- )
19
- from .settings import (
20
- CLIStyleRenderableSettings,
21
- CLIStyleBackgroundSettings,
22
- CLIStyleLiveSettings,
23
- )
24
-
25
- # Lazy import cache for rich components
26
- _RICH_CACHE = {}
27
-
28
-
29
- def _get_rich_console():
30
- """Lazy import for rich console"""
31
- if "get_console" not in _RICH_CACHE:
32
- from rich import get_console as get_rich_console
33
-
34
- _RICH_CACHE["get_console"] = get_rich_console
35
- return _RICH_CACHE["get_console"]
36
-
37
-
38
- def _get_rich_classes():
39
- """Lazy import for rich classes"""
40
- if "classes" not in _RICH_CACHE:
41
- from rich.console import Console, RenderableType
42
- from rich.live import Live
43
- from rich.panel import Panel
44
- from rich.style import Style
45
- from rich.text import Text
46
-
47
- _RICH_CACHE["classes"] = {
48
- "Console": Console,
49
- "RenderableType": RenderableType,
50
- "Live": Live,
51
- "Panel": Panel,
52
- "Style": Style,
53
- "Text": Text,
54
- }
55
- return _RICH_CACHE["classes"]
56
-
57
-
58
- def live_render(
59
- r,
60
- live_settings: CLIStyleLiveSettings,
61
- console=None,
62
- ) -> None:
63
- """Runs a rich live renderable.
64
-
65
- Args:
66
- r : The renderable to run.
67
- settings : The settings to use for the live renderable.
68
- console : The console to use for the live renderable."""
69
-
70
- rich_classes = _get_rich_classes()
71
- RenderableType = rich_classes["RenderableType"]
72
- Live = rich_classes["Live"]
73
-
74
- if console is None:
75
- get_rich_console = _get_rich_console()
76
- console = get_rich_console()
77
-
78
- if not isinstance(r, RenderableType):
79
- raise CLIStyleError("The renderable must be a RenderableType.")
80
-
81
- if not live_settings.get("duration"):
82
- duration = 2.0
83
- else:
84
- duration = live_settings["duration"]
85
- if "duration" in live_settings:
86
- del live_settings["duration"]
87
-
88
- if not live_settings.get("refresh_rate"):
89
- refresh_rate = 20
90
- else:
91
- refresh_rate = live_settings["refresh_rate"]
92
- if "refresh_rate" in live_settings:
93
- del live_settings["refresh_rate"]
94
-
95
- if not live_settings.get("auto_refresh"):
96
- live_settings["auto_refresh"] = True
97
- if not live_settings.get("transient"):
98
- live_settings["transient"] = False
99
- if not live_settings.get("redirect_stdout"):
100
- live_settings["redirect_stdout"] = True
101
- if not live_settings.get("redirect_stderr"):
102
- live_settings["redirect_stderr"] = True
103
- if not live_settings.get("vertical_overflow"):
104
- live_settings["vertical_overflow"] = "ellipsis"
105
-
106
- try:
107
- with Live(r, console=console, **live_settings) as live:
108
- start_time = time.time()
109
- while time.time() - start_time < duration:
110
- time.sleep(1 / refresh_rate)
111
- live.refresh()
112
- except Exception as e:
113
- raise CLIStyleError(f"Error running rich live: {e}") from e
114
-
115
-
116
- def style_renderable(
117
- r,
118
- style: CLIStyleType | None = None,
119
- style_settings: CLIStyleRenderableSettings | None = None,
120
- bg: CLIStyleBackgroundType | None = None,
121
- bg_settings: CLIStyleBackgroundSettings | None = None,
122
- ):
123
- """Styles a renderable with a rich string tag or settings.
124
-
125
- Args:
126
- r : The renderable to style.
127
- style : The rich string tag to apply to the renderable.
128
- style_settings : The settings to apply to the renderable.
129
- bg : The rich string tag to apply to the background.
130
- bg_settings : The settings to apply to the background.
131
- """
132
-
133
- try:
134
- rich_classes = _get_rich_classes()
135
- Style = rich_classes["Style"]
136
- Text = rich_classes["Text"]
137
- Panel = rich_classes["Panel"]
138
-
139
- # First handle style processing to get styled_renderable
140
- styled_renderable = r
141
-
142
- # Handle string-based styles (including color tags and complex styles)
143
- if isinstance(style, str):
144
- try:
145
- # For strings, use Rich's style parsing directly to support things like 'black on red'
146
- rich_style = Style.parse(style)
147
- styled_renderable = (
148
- Text(r, style=rich_style) if isinstance(r, str) else r
149
- )
150
- except Exception:
151
- # Fallback to treating as simple color if parsing fails
152
- rich_style = Style(color=style)
153
- styled_renderable = (
154
- Text(r, style=rich_style) if isinstance(r, str) else r
155
- )
156
-
157
- # Handle tuple-based styles (RGB color tuples)
158
- elif isinstance(style, tuple):
159
- try:
160
- # Convert tuple to RGB format for Rich
161
- rgb_color = f"rgb({style[0]},{style[1]},{style[2]})"
162
- rich_style = Style(color=rgb_color)
163
- styled_renderable = (
164
- Text(r, style=rich_style) if isinstance(r, str) else r
165
- )
166
- except Exception:
167
- # Fallback to original renderable if tuple processing fails
168
- styled_renderable = r
169
-
170
- # Handle dict-based styles passed as style parameter
171
- elif isinstance(style, dict):
172
- try:
173
- # Process text/style properties from dict
174
- text_style_kwargs = {}
175
-
176
- # Handle color from style dict
177
- if "color" in style:
178
- try:
179
- color_value = style["color"]
180
- if isinstance(color_value, tuple):
181
- text_style_kwargs["color"] = (
182
- f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
183
- )
184
- else:
185
- text_style_kwargs["color"] = color_value
186
- except Exception:
187
- # Skip color if processing fails
188
- pass
189
-
190
- # Handle text style properties
191
- text_style_props = [
192
- "bold",
193
- "dim",
194
- "italic",
195
- "underline",
196
- "blink",
197
- "blink2",
198
- "reverse",
199
- "conceal",
200
- "strike",
201
- "underline2",
202
- "frame",
203
- "encircle",
204
- "overline",
205
- "link",
206
- ]
207
-
208
- for prop in text_style_props:
209
- if prop in style:
210
- try:
211
- text_style_kwargs[prop] = style[prop]
212
- except Exception:
213
- # Skip property if processing fails
214
- continue
215
-
216
- # Create rich style from text properties
217
- try:
218
- rich_style = (
219
- Style(**text_style_kwargs) if text_style_kwargs else None
220
- )
221
- except Exception:
222
- rich_style = None
223
-
224
- # Apply text style to renderable
225
- try:
226
- if isinstance(r, str):
227
- styled_renderable = (
228
- Text(r, style=rich_style) if rich_style else Text(r)
229
- )
230
- elif isinstance(r, Text) and rich_style:
231
- styled_renderable = Text(r.plain, style=rich_style)
232
- else:
233
- styled_renderable = r
234
- except Exception:
235
- styled_renderable = r
236
-
237
- except Exception:
238
- # Fallback to original renderable if dict processing fails
239
- styled_renderable = r
240
-
241
- # Handle style_settings dict
242
- elif style_settings:
243
- try:
244
- # Process text/style properties
245
- text_style_kwargs = {}
246
-
247
- # Handle color from style settings
248
- if "color" in style_settings:
249
- try:
250
- color_value = style_settings["color"]
251
- if isinstance(color_value, tuple):
252
- text_style_kwargs["color"] = (
253
- f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
254
- )
255
- else:
256
- text_style_kwargs["color"] = color_value
257
- except Exception:
258
- # Skip color if processing fails
259
- pass
260
-
261
- # Handle text style properties
262
- text_style_props = [
263
- "bold",
264
- "dim",
265
- "italic",
266
- "underline",
267
- "blink",
268
- "blink2",
269
- "reverse",
270
- "conceal",
271
- "strike",
272
- "underline2",
273
- "frame",
274
- "encircle",
275
- "overline",
276
- "link",
277
- ]
278
-
279
- for prop in text_style_props:
280
- if prop in style_settings:
281
- try:
282
- text_style_kwargs[prop] = style_settings[prop]
283
- except Exception:
284
- # Skip property if processing fails
285
- continue
286
-
287
- # Create rich style from text properties
288
- try:
289
- rich_style = (
290
- Style(**text_style_kwargs) if text_style_kwargs else None
291
- )
292
- except Exception:
293
- rich_style = None
294
-
295
- # Apply text style to renderable
296
- try:
297
- if isinstance(r, str):
298
- styled_renderable = (
299
- Text(r, style=rich_style) if rich_style else Text(r)
300
- )
301
- elif isinstance(r, Text) and rich_style:
302
- styled_renderable = Text(r.plain, style=rich_style)
303
- else:
304
- styled_renderable = r
305
- except Exception:
306
- styled_renderable = r
307
-
308
- except Exception:
309
- # Fallback to original renderable if dict processing fails
310
- styled_renderable = r
311
-
312
- # Handle background settings (from bg or bg_settings parameter)
313
- if bg or bg_settings:
314
- try:
315
- if bg_settings:
316
- # Full background configuration
317
- panel_kwargs = {}
318
-
319
- # Handle box style
320
- if "box" in bg_settings:
321
- try:
322
- box_name = bg_settings["box"]
323
- from rich import box as rich_box_module
324
-
325
- box_map = {
326
- "ascii": rich_box_module.ASCII,
327
- "ascii2": rich_box_module.ASCII2,
328
- "ascii_double_head": rich_box_module.ASCII_DOUBLE_HEAD,
329
- "square": rich_box_module.SQUARE,
330
- "square_double_head": rich_box_module.SQUARE_DOUBLE_HEAD,
331
- "minimal": rich_box_module.MINIMAL,
332
- "minimal_heavy_head": rich_box_module.MINIMAL_HEAVY_HEAD,
333
- "minimal_double_head": rich_box_module.MINIMAL_DOUBLE_HEAD,
334
- "simple": rich_box_module.SIMPLE,
335
- "simple_head": rich_box_module.SIMPLE_HEAD,
336
- "simple_heavy": rich_box_module.SIMPLE_HEAVY,
337
- "horizontals": rich_box_module.HORIZONTALS,
338
- "rounded": rich_box_module.ROUNDED,
339
- "heavy": rich_box_module.HEAVY,
340
- "heavy_edge": rich_box_module.HEAVY_EDGE,
341
- "heavy_head": rich_box_module.HEAVY_HEAD,
342
- "double": rich_box_module.DOUBLE,
343
- "double_edge": rich_box_module.DOUBLE_EDGE,
344
- "markdown": getattr(
345
- rich_box_module,
346
- "MARKDOWN",
347
- rich_box_module.ROUNDED,
348
- ),
349
- }
350
- panel_kwargs["box"] = box_map.get(
351
- box_name, rich_box_module.ROUNDED
352
- )
353
- except Exception:
354
- # Use default box if box processing fails
355
- pass
356
-
357
- # Handle panel properties
358
- panel_props = [
359
- "title",
360
- "subtitle",
361
- "title_align",
362
- "subtitle_align",
363
- "safe_box",
364
- "expand",
365
- "width",
366
- "height",
367
- "padding",
368
- "highlight",
369
- ]
370
-
371
- for prop in panel_props:
372
- if prop in bg_settings:
373
- try:
374
- panel_kwargs[prop] = bg_settings[prop]
375
- except Exception:
376
- # Skip property if processing fails
377
- continue
378
-
379
- # Handle background style
380
- if "style" in bg_settings:
381
- try:
382
- bg_style = bg_settings["style"]
383
- if isinstance(bg_style, dict):
384
- bg_style_kwargs = {}
385
- if "color" in bg_style:
386
- try:
387
- color_value = bg_style["color"]
388
- if isinstance(color_value, tuple):
389
- bg_style_kwargs["bgcolor"] = (
390
- f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
391
- )
392
- else:
393
- bg_style_kwargs["bgcolor"] = color_value
394
- except Exception:
395
- pass
396
- panel_kwargs["style"] = Style(**bg_style_kwargs)
397
- else:
398
- # Handle string or tuple background style
399
- if isinstance(bg_style, tuple):
400
- panel_kwargs["style"] = Style(
401
- bgcolor=f"rgb({bg_style[0]},{bg_style[1]},{bg_style[2]})"
402
- )
403
- else:
404
- panel_kwargs["style"] = Style(bgcolor=bg_style)
405
- except Exception:
406
- # Skip background style if processing fails
407
- pass
408
-
409
- # Handle border style
410
- if "border_style" in bg_settings:
411
- try:
412
- border_style = bg_settings["border_style"]
413
- if isinstance(border_style, dict):
414
- border_style_kwargs = {}
415
- if "color" in border_style:
416
- try:
417
- color_value = border_style["color"]
418
- if isinstance(color_value, tuple):
419
- border_style_kwargs["color"] = (
420
- f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
421
- )
422
- else:
423
- border_style_kwargs["color"] = color_value
424
- except Exception:
425
- pass
426
-
427
- for prop in ["bold", "dim", "italic"]:
428
- if prop in border_style:
429
- try:
430
- border_style_kwargs[prop] = border_style[
431
- prop
432
- ]
433
- except Exception:
434
- continue
435
-
436
- panel_kwargs["border_style"] = Style(
437
- **border_style_kwargs
438
- )
439
- except Exception:
440
- # Skip border style if processing fails
441
- pass
442
-
443
- # Handle background color if specified at top level
444
- if "color" in bg_settings and "style" not in bg_settings:
445
- try:
446
- color_value = bg_settings["color"]
447
- if isinstance(color_value, tuple):
448
- panel_kwargs["style"] = Style(
449
- bgcolor=f"rgb({color_value[0]},{color_value[1]},{color_value[2]})"
450
- )
451
- else:
452
- panel_kwargs["style"] = Style(bgcolor=color_value)
453
- except Exception:
454
- # Skip background color if processing fails
455
- pass
456
-
457
- try:
458
- return Panel(styled_renderable, **panel_kwargs)
459
- except Exception:
460
- # Fallback to styled renderable if panel creation fails
461
- return styled_renderable
462
-
463
- elif bg:
464
- # Simple background color (string from bg parameter)
465
- try:
466
- bg_style = Style(bgcolor=bg)
467
- return Panel(styled_renderable, style=bg_style)
468
- except Exception:
469
- # Fallback to styled renderable if panel creation fails
470
- return styled_renderable
471
- except Exception:
472
- # Skip background processing if it fails
473
- pass
474
-
475
- # Return styled renderable (with or without background processing)
476
- return styled_renderable
477
-
478
- except Exception:
479
- # Ultimate fallback - return original renderable
480
- return r
@@ -1,35 +0,0 @@
1
- """hammad.configuration
2
-
3
- Contains the `Configuration` class and related functions for parsing configurations
4
- from various sources.
5
- """
6
-
7
- from typing import TYPE_CHECKING
8
- from .._core._utils._import_utils import _auto_create_getattr_loader
9
-
10
- if TYPE_CHECKING:
11
- from .configuration import (
12
- Configuration,
13
- read_configuration_from_file,
14
- read_configuration_from_url,
15
- read_configuration_from_os_vars,
16
- read_configuration_from_os_prefix,
17
- read_configuration_from_dotenv,
18
- )
19
-
20
-
21
- __all__ = (
22
- "Configuration",
23
- "read_configuration_from_file",
24
- "read_configuration_from_url",
25
- "read_configuration_from_os_vars",
26
- "read_configuration_from_os_prefix",
27
- "read_configuration_from_dotenv",
28
- )
29
-
30
-
31
- __getattr__ = _auto_create_getattr_loader(__all__)
32
-
33
-
34
- def __dir__() -> list[str]:
35
- return list(__all__)