hammad-python 0.0.11__py3-none-any.whl → 0.0.13__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 (80) hide show
  1. hammad/__init__.py +169 -56
  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/{based → base}/fields.py +23 -23
  21. hammad/{based → base}/model.py +124 -14
  22. hammad/base/utils.py +280 -0
  23. hammad/cache/__init__.py +30 -12
  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 +10 -2
  30. hammad/cli/{styles/animations.py → animations.py} +79 -23
  31. hammad/cli/{plugins/__init__.py → plugins.py} +85 -90
  32. hammad/cli/styles/__init__.py +50 -0
  33. hammad/cli/styles/settings.py +4 -0
  34. hammad/configuration/__init__.py +35 -0
  35. hammad/{data/types/files → configuration}/configuration.py +96 -7
  36. hammad/data/__init__.py +14 -26
  37. hammad/data/collections/__init__.py +4 -2
  38. hammad/data/collections/collection.py +300 -75
  39. hammad/data/collections/vector_collection.py +118 -12
  40. hammad/data/databases/__init__.py +2 -2
  41. hammad/data/databases/database.py +383 -32
  42. hammad/json/__init__.py +2 -2
  43. hammad/logging/__init__.py +13 -5
  44. hammad/logging/decorators.py +404 -2
  45. hammad/logging/logger.py +442 -22
  46. hammad/multimodal/__init__.py +24 -0
  47. hammad/{data/types/files → multimodal}/audio.py +21 -6
  48. hammad/{data/types/files → multimodal}/image.py +5 -5
  49. hammad/multithreading/__init__.py +304 -0
  50. hammad/pydantic/__init__.py +2 -2
  51. hammad/pydantic/converters.py +1 -1
  52. hammad/pydantic/models/__init__.py +2 -2
  53. hammad/text/__init__.py +59 -14
  54. hammad/text/converters.py +723 -0
  55. hammad/text/{utils/markdown/formatting.py → markdown.py} +25 -23
  56. hammad/text/text.py +12 -14
  57. hammad/types/__init__.py +11 -0
  58. hammad/{data/types/files → types}/file.py +18 -18
  59. hammad/typing/__init__.py +138 -84
  60. hammad/web/__init__.py +3 -2
  61. hammad/web/models.py +245 -0
  62. hammad/web/search/client.py +75 -23
  63. hammad/web/utils.py +14 -5
  64. hammad/yaml/__init__.py +2 -2
  65. hammad/yaml/converters.py +1 -1
  66. {hammad_python-0.0.11.dist-info → hammad_python-0.0.13.dist-info}/METADATA +4 -1
  67. hammad_python-0.0.13.dist-info/RECORD +85 -0
  68. hammad/based/__init__.py +0 -52
  69. hammad/based/utils.py +0 -455
  70. hammad/cache/_cache.py +0 -746
  71. hammad/data/types/__init__.py +0 -33
  72. hammad/data/types/files/__init__.py +0 -1
  73. hammad/data/types/files/document.py +0 -195
  74. hammad/text/utils/__init__.py +0 -1
  75. hammad/text/utils/converters.py +0 -229
  76. hammad/text/utils/markdown/__init__.py +0 -1
  77. hammad/text/utils/markdown/converters.py +0 -506
  78. hammad_python-0.0.11.dist-info/RECORD +0 -65
  79. {hammad_python-0.0.11.dist-info → hammad_python-0.0.13.dist-info}/WHEEL +0 -0
  80. {hammad_python-0.0.11.dist-info → hammad_python-0.0.13.dist-info}/licenses/LICENSE +0 -0
@@ -3,3 +3,53 @@
3
3
  Contains resources, types and other utilities in context of
4
4
  styling rendered content in the CLI. Most resources within this
5
5
  submodule are not meant for direct use."""
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 .settings import (
12
+ CLIStyleRenderableSettings,
13
+ CLIStyleLiveSettings,
14
+ CLIStyleBackgroundSettings,
15
+ )
16
+ from .types import (
17
+ CLIStyleBackgroundType,
18
+ CLIStyleBoxName,
19
+ CLIStyleColorName,
20
+ CLIStyleError,
21
+ CLIStyleJustifyMethod,
22
+ CLIStyleOverflowMethod,
23
+ CLIStyleStyleName,
24
+ CLIStyleType,
25
+ CLIStyleVerticalOverflowMethod,
26
+ )
27
+ from .utils import live_render, style_renderable
28
+
29
+
30
+ __all__ = (
31
+ # hammad.cli.styles.settings
32
+ "CLIStyleRenderableSettings",
33
+ "CLIStyleLiveSettings",
34
+ "CLIStyleBackgroundSettings",
35
+ # hammad.cli.styles.types
36
+ "CLIStyleBackgroundType",
37
+ "CLIStyleBoxName",
38
+ "CLIStyleColorName",
39
+ "CLIStyleError",
40
+ "CLIStyleJustifyMethod",
41
+ "CLIStyleOverflowMethod",
42
+ "CLIStyleStyleName",
43
+ "CLIStyleType",
44
+ "CLIStyleVerticalOverflowMethod",
45
+ # hammad.cli.styles.utils
46
+ "live_render",
47
+ "style_renderable",
48
+ )
49
+
50
+
51
+ __getattr__ = _auto_create_getattr_loader(__all__)
52
+
53
+
54
+ def __dir__() -> list[str]:
55
+ return list(__all__)
@@ -4,6 +4,7 @@ from typing import Any
4
4
  from typing_extensions import TypedDict, NotRequired
5
5
 
6
6
  from .types import (
7
+ CLIStyleColorName,
7
8
  CLIStyleBoxName,
8
9
  CLIStyleJustifyMethod,
9
10
  CLIStyleOverflowMethod,
@@ -28,6 +29,9 @@ class CLIStyleRenderableSettings(TypedDict, total=False):
28
29
  tag with a color / style name. or apply the `style_settings`
29
30
  parameter with these settings."""
30
31
 
32
+ color: NotRequired[CLIStyleColorName]
33
+ """The color of the renderable output or content."""
34
+
31
35
  # rich.text
32
36
 
33
37
  justify: NotRequired[CLIStyleJustifyMethod]
@@ -0,0 +1,35 @@
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__)
@@ -7,11 +7,19 @@ from typing import Any, Self
7
7
  from dotenv import load_dotenv, dotenv_values
8
8
  import httpx
9
9
  import msgspec
10
+ import yaml
10
11
 
11
- from .file import File, FileSource
12
- from ....based.fields import basedfield
12
+ from ..types.file import File, FileSource
13
+ from ..base.fields import field
13
14
 
14
- __all__ = ("Configuration",)
15
+ __all__ = (
16
+ "Configuration",
17
+ "read_configuration_from_file",
18
+ "read_configuration_from_url",
19
+ "read_configuration_from_os_vars",
20
+ "read_configuration_from_os_prefix",
21
+ "read_configuration_from_dotenv",
22
+ )
15
23
 
16
24
 
17
25
  class Configuration(File):
@@ -24,10 +32,10 @@ class Configuration(File):
24
32
  with configuration-specific functionality."""
25
33
 
26
34
  # Configuration-specific fields
27
- config_data: dict[str, Any] = basedfield(default_factory=dict)
35
+ config_data: dict[str, Any] = field(default_factory=dict)
28
36
  """The actual configuration key-value pairs."""
29
37
 
30
- format_type: str | None = basedfield(default=None)
38
+ format_type: str | None = field(default=None)
31
39
  """The format type of the configuration (json, toml, yaml, ini, env)."""
32
40
 
33
41
  def __post_init__(self):
@@ -54,7 +62,13 @@ class Configuration(File):
54
62
  elif format_type == "toml":
55
63
  self.config_data = msgspec.toml.decode(content.encode("utf-8"))
56
64
  elif format_type == "yaml":
57
- self.config_data = msgspec.yaml.decode(content.encode("utf-8"))
65
+ # Use PyYAML with unsafe_load for YAML tags like !!python/name:
66
+ # This is needed for files like mkdocs.yml that use custom constructors
67
+ try:
68
+ self.config_data = yaml.unsafe_load(content)
69
+ except yaml.constructor.ConstructorError:
70
+ # Fallback to safe_load if unsafe_load fails
71
+ self.config_data = yaml.safe_load(content)
58
72
  elif format_type == "ini":
59
73
  parser = configparser.ConfigParser()
60
74
  parser.read_string(content)
@@ -129,7 +143,9 @@ class Configuration(File):
129
143
  elif format_type == "toml":
130
144
  return msgspec.toml.encode(self.config_data).decode("utf-8")
131
145
  elif format_type == "yaml":
132
- return msgspec.yaml.encode(self.config_data).decode("utf-8")
146
+ return yaml.dump(
147
+ self.config_data, default_flow_style=False, allow_unicode=True
148
+ )
133
149
  elif format_type == "ini":
134
150
  parser = configparser.ConfigParser()
135
151
  for section_name, section_data in self.config_data.items():
@@ -473,3 +489,76 @@ class Configuration(File):
473
489
  def items(self):
474
490
  """Return configuration key-value pairs."""
475
491
  return self.config_data.items()
492
+
493
+
494
+ # HELPERS
495
+
496
+
497
+ def read_configuration_from_file(path: str | Path) -> Configuration:
498
+ """Parse a filepath into a `Configuration` object.
499
+
500
+ Valid file types:
501
+ - json
502
+ - toml
503
+ - yaml
504
+ - ini
505
+ - env
506
+
507
+ Args:
508
+ path: The path to the file to parse.
509
+
510
+ Returns:
511
+ A `Configuration` object.
512
+ """
513
+ file_obj = File.from_path(path, lazy=False)
514
+ return Configuration.from_file(file_obj)
515
+
516
+
517
+ def read_configuration_from_url(url: str) -> Configuration:
518
+ """Parse a URL into a `Configuration` object.
519
+
520
+ Args:
521
+ url: The URL to parse.
522
+
523
+ Returns:
524
+ A `Configuration` object.
525
+ """
526
+ return Configuration.from_url(url)
527
+
528
+
529
+ def read_configuration_from_os_vars(vars: list[str]) -> Configuration:
530
+ """Parse a list of environment variables into a `Configuration` object.
531
+
532
+ Args:
533
+ vars: The list of environment variables to parse.
534
+
535
+ Returns:
536
+ A `Configuration` object.
537
+ """
538
+ return Configuration.from_os_vars(vars)
539
+
540
+
541
+ def read_configuration_from_os_prefix(prefix: str) -> Configuration:
542
+ """Parse a list of environment variables into a `Configuration` object.
543
+
544
+ Args:
545
+ prefix: The prefix to use to filter the variables.
546
+
547
+ Returns:
548
+ A `Configuration` object.
549
+ """
550
+ return Configuration.from_os_prefix(prefix)
551
+
552
+
553
+ def read_configuration_from_dotenv(path: str | Path = ".env") -> Configuration:
554
+ """Parse a .env file into a `Configuration` object.
555
+
556
+ NOTE: Defaults to `.env` in the current working directory.
557
+
558
+ Args:
559
+ path: The path to the .env file to parse.
560
+
561
+ Returns:
562
+ A `Configuration` object.
563
+ """
564
+ return Configuration.from_dotenv(path)
hammad/data/__init__.py CHANGED
@@ -1,49 +1,37 @@
1
1
  """hammad.data"""
2
2
 
3
3
  from typing import TYPE_CHECKING
4
- from ..based.utils import auto_create_lazy_loader
4
+ from .._core._utils._import_utils import _auto_create_getattr_loader
5
5
 
6
6
  if TYPE_CHECKING:
7
- from .collections.base_collection import BaseCollection
8
- from .collections.searchable_collection import SearchableCollection
9
- from .collections.vector_collection import (
7
+ from .collections import (
8
+ Collection,
9
+ BaseCollection,
10
10
  VectorCollection,
11
- )
12
- from .collections.collection import (
13
- create_collection,
14
11
  VectorCollectionSettings,
12
+ SearchableCollection,
15
13
  SearchableCollectionSettings,
14
+ create_collection,
16
15
  )
17
- from .databases.database import (
18
- Database,
19
- create_database,
20
- )
21
- from .types.files.file import File, FileSource
22
- from .types.files.audio import Audio
23
- from .types.files.image import Image
24
- from .types.files.configuration import Configuration
25
- from .types.files.document import Document
16
+ from .databases import Database, create_database
26
17
 
27
18
 
28
19
  __all__ = (
29
- "create_collection",
20
+ # hammad.data.collections
21
+ "Collection",
22
+ "BaseCollection",
30
23
  "VectorCollection",
31
24
  "VectorCollectionSettings",
32
25
  "SearchableCollection",
33
26
  "SearchableCollectionSettings",
34
- "BaseCollection",
35
- "create_database",
27
+ "create_collection",
28
+ # hammad.data.databases
36
29
  "Database",
37
- "File",
38
- "FileSource",
39
- "Audio",
40
- "Image",
41
- "Configuration",
42
- "Document",
30
+ "create_database",
43
31
  )
44
32
 
45
33
 
46
- __getattr__ = auto_create_lazy_loader(__all__)
34
+ __getattr__ = _auto_create_getattr_loader(__all__)
47
35
 
48
36
 
49
37
  def __dir__() -> list[str]:
@@ -1,7 +1,7 @@
1
1
  """hammad.data.collections"""
2
2
 
3
3
  from typing import TYPE_CHECKING
4
- from ...based.utils import auto_create_lazy_loader
4
+ from ..._core._utils._import_utils import _auto_create_getattr_loader
5
5
 
6
6
  if TYPE_CHECKING:
7
7
  from .base_collection import BaseCollection
@@ -11,6 +11,7 @@ if TYPE_CHECKING:
11
11
  create_collection,
12
12
  VectorCollectionSettings,
13
13
  SearchableCollectionSettings,
14
+ Collection,
14
15
  )
15
16
 
16
17
 
@@ -21,10 +22,11 @@ __all__ = (
21
22
  "create_collection",
22
23
  "VectorCollectionSettings",
23
24
  "SearchableCollectionSettings",
25
+ "Collection",
24
26
  )
25
27
 
26
28
 
27
- __getattr__ = auto_create_lazy_loader(__all__)
29
+ __getattr__ = _auto_create_getattr_loader(__all__)
28
30
 
29
31
 
30
32
  def __dir__() -> list[str]: