hammad-python 0.0.15__py3-none-any.whl → 0.0.17__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 (111) hide show
  1. hammad/__init__.py +178 -0
  2. hammad/_internal.py +237 -0
  3. hammad/cache/__init__.py +40 -0
  4. hammad/cache/base_cache.py +181 -0
  5. hammad/cache/cache.py +169 -0
  6. hammad/cache/decorators.py +261 -0
  7. hammad/cache/file_cache.py +80 -0
  8. hammad/cache/ttl_cache.py +74 -0
  9. hammad/cli/__init__.py +35 -0
  10. hammad/cli/_runner.py +265 -0
  11. hammad/cli/animations.py +573 -0
  12. hammad/cli/plugins.py +836 -0
  13. hammad/cli/styles/__init__.py +55 -0
  14. hammad/cli/styles/settings.py +139 -0
  15. hammad/cli/styles/types.py +358 -0
  16. hammad/cli/styles/utils.py +626 -0
  17. hammad/data/__init__.py +83 -0
  18. hammad/data/collections/__init__.py +44 -0
  19. hammad/data/collections/collection.py +274 -0
  20. hammad/data/collections/indexes/__init__.py +37 -0
  21. hammad/data/collections/indexes/qdrant/__init__.py +1 -0
  22. hammad/data/collections/indexes/qdrant/index.py +735 -0
  23. hammad/data/collections/indexes/qdrant/settings.py +94 -0
  24. hammad/data/collections/indexes/qdrant/utils.py +220 -0
  25. hammad/data/collections/indexes/tantivy/__init__.py +1 -0
  26. hammad/data/collections/indexes/tantivy/index.py +428 -0
  27. hammad/data/collections/indexes/tantivy/settings.py +51 -0
  28. hammad/data/collections/indexes/tantivy/utils.py +200 -0
  29. hammad/data/configurations/__init__.py +35 -0
  30. hammad/data/configurations/configuration.py +564 -0
  31. hammad/data/models/__init__.py +55 -0
  32. hammad/data/models/extensions/__init__.py +4 -0
  33. hammad/data/models/extensions/pydantic/__init__.py +42 -0
  34. hammad/data/models/extensions/pydantic/converters.py +759 -0
  35. hammad/data/models/fields.py +546 -0
  36. hammad/data/models/model.py +1078 -0
  37. hammad/data/models/utils.py +280 -0
  38. hammad/data/sql/__init__.py +23 -0
  39. hammad/data/sql/database.py +578 -0
  40. hammad/data/sql/types.py +141 -0
  41. hammad/data/types/__init__.py +39 -0
  42. hammad/data/types/file.py +358 -0
  43. hammad/data/types/multimodal/__init__.py +24 -0
  44. hammad/data/types/multimodal/audio.py +96 -0
  45. hammad/data/types/multimodal/image.py +80 -0
  46. hammad/data/types/text.py +1066 -0
  47. hammad/formatting/__init__.py +20 -0
  48. hammad/formatting/json/__init__.py +27 -0
  49. hammad/formatting/json/converters.py +158 -0
  50. hammad/formatting/text/__init__.py +63 -0
  51. hammad/formatting/text/converters.py +723 -0
  52. hammad/formatting/text/markdown.py +131 -0
  53. hammad/formatting/yaml/__init__.py +26 -0
  54. hammad/formatting/yaml/converters.py +5 -0
  55. hammad/genai/__init__.py +78 -0
  56. hammad/genai/agents/__init__.py +1 -0
  57. hammad/genai/agents/types/__init__.py +35 -0
  58. hammad/genai/agents/types/history.py +277 -0
  59. hammad/genai/agents/types/tool.py +490 -0
  60. hammad/genai/embedding_models/__init__.py +41 -0
  61. hammad/genai/embedding_models/embedding_model.py +193 -0
  62. hammad/genai/embedding_models/embedding_model_name.py +77 -0
  63. hammad/genai/embedding_models/embedding_model_request.py +65 -0
  64. hammad/genai/embedding_models/embedding_model_response.py +69 -0
  65. hammad/genai/embedding_models/run.py +161 -0
  66. hammad/genai/language_models/__init__.py +35 -0
  67. hammad/genai/language_models/_streaming.py +622 -0
  68. hammad/genai/language_models/_types.py +276 -0
  69. hammad/genai/language_models/_utils/__init__.py +31 -0
  70. hammad/genai/language_models/_utils/_completions.py +131 -0
  71. hammad/genai/language_models/_utils/_messages.py +89 -0
  72. hammad/genai/language_models/_utils/_requests.py +202 -0
  73. hammad/genai/language_models/_utils/_structured_outputs.py +124 -0
  74. hammad/genai/language_models/language_model.py +734 -0
  75. hammad/genai/language_models/language_model_request.py +135 -0
  76. hammad/genai/language_models/language_model_response.py +219 -0
  77. hammad/genai/language_models/language_model_response_chunk.py +53 -0
  78. hammad/genai/language_models/run.py +530 -0
  79. hammad/genai/multimodal_models.py +48 -0
  80. hammad/genai/rerank_models.py +26 -0
  81. hammad/logging/__init__.py +35 -0
  82. hammad/logging/decorators.py +834 -0
  83. hammad/logging/logger.py +954 -0
  84. hammad/mcp/__init__.py +50 -0
  85. hammad/mcp/client/__init__.py +36 -0
  86. hammad/mcp/client/client.py +624 -0
  87. hammad/mcp/client/client_service.py +400 -0
  88. hammad/mcp/client/settings.py +178 -0
  89. hammad/mcp/servers/__init__.py +25 -0
  90. hammad/mcp/servers/launcher.py +1161 -0
  91. hammad/runtime/__init__.py +32 -0
  92. hammad/runtime/decorators.py +142 -0
  93. hammad/runtime/run.py +299 -0
  94. hammad/service/__init__.py +49 -0
  95. hammad/service/create.py +527 -0
  96. hammad/service/decorators.py +285 -0
  97. hammad/typing/__init__.py +435 -0
  98. hammad/web/__init__.py +43 -0
  99. hammad/web/http/__init__.py +1 -0
  100. hammad/web/http/client.py +944 -0
  101. hammad/web/models.py +277 -0
  102. hammad/web/openapi/__init__.py +1 -0
  103. hammad/web/openapi/client.py +740 -0
  104. hammad/web/search/__init__.py +1 -0
  105. hammad/web/search/client.py +1035 -0
  106. hammad/web/utils.py +472 -0
  107. {hammad_python-0.0.15.dist-info → hammad_python-0.0.17.dist-info}/METADATA +8 -1
  108. hammad_python-0.0.17.dist-info/RECORD +110 -0
  109. hammad_python-0.0.15.dist-info/RECORD +0 -4
  110. {hammad_python-0.0.15.dist-info → hammad_python-0.0.17.dist-info}/WHEEL +0 -0
  111. {hammad_python-0.0.15.dist-info → hammad_python-0.0.17.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,83 @@
1
+ """hammad.data"""
2
+
3
+ from typing import TYPE_CHECKING
4
+ from .._internal import create_getattr_importer
5
+
6
+ if TYPE_CHECKING:
7
+ from .types import (
8
+ BaseText,
9
+ Text,
10
+ )
11
+ from .models import (
12
+ Model,
13
+ model_settings,
14
+ field,
15
+ validator,
16
+ is_field,
17
+ is_model,
18
+ convert_to_pydantic_model,
19
+ convert_to_pydantic_field,
20
+ is_pydantic_model_class,
21
+ )
22
+ from .collections import (
23
+ Collection,
24
+ TantivyCollectionIndex,
25
+ QdrantCollectionIndex,
26
+ TantivyCollectionIndexSettings,
27
+ TantivyCollectionIndexQuerySettings,
28
+ QdrantCollectionIndexSettings,
29
+ QdrantCollectionIndexQuerySettings,
30
+ )
31
+ from .sql import (
32
+ DatabaseItemType,
33
+ DatabaseItem,
34
+ Database,
35
+ )
36
+ from .configurations import (
37
+ Configuration,
38
+ read_configuration_from_file,
39
+ read_configuration_from_url,
40
+ read_configuration_from_os_vars,
41
+ read_configuration_from_os_prefix,
42
+ read_configuration_from_dotenv,
43
+ )
44
+
45
+
46
+ __all__ = (
47
+ # hammad.data.types
48
+ "BaseText",
49
+ "Text",
50
+
51
+ # hammad.data.models
52
+ "Model",
53
+ "model_settings",
54
+ "field",
55
+ "validator",
56
+ "is_field",
57
+ "is_model",
58
+
59
+ # hammad.data.collections
60
+ "Collection",
61
+ "TantivyCollectionIndex",
62
+ "QdrantCollectionIndex",
63
+ "TantivyCollectionIndexSettings",
64
+ "TantivyCollectionIndexQuerySettings",
65
+ "QdrantCollectionIndexSettings",
66
+ "QdrantCollectionIndexQuerySettings",
67
+
68
+ # hammad.data.sql
69
+ "DatabaseItemType",
70
+ "DatabaseItem",
71
+ "Database",
72
+
73
+ # hammad.data.configurations
74
+ "Configuration",
75
+ )
76
+
77
+
78
+ __getattr__ = create_getattr_importer(__all__)
79
+
80
+
81
+ def __dir__() -> list[str]:
82
+ """Get the attributes of the hammad.data module."""
83
+ return list(__all__)
@@ -0,0 +1,44 @@
1
+ """hammad.data.collections"""
2
+
3
+ from typing import TYPE_CHECKING
4
+ from ..._internal import create_getattr_importer
5
+
6
+ if TYPE_CHECKING:
7
+ from .collection import Collection
8
+
9
+ from .indexes import (
10
+ TantivyCollectionIndex,
11
+ QdrantCollectionIndex,
12
+ )
13
+
14
+ from .indexes.tantivy.settings import (
15
+ TantivyCollectionIndexSettings,
16
+ TantivyCollectionIndexQuerySettings,
17
+ )
18
+
19
+ from .indexes.qdrant.settings import (
20
+ QdrantCollectionIndexSettings,
21
+ QdrantCollectionIndexQuerySettings,
22
+ )
23
+
24
+
25
+ __all__ = (
26
+ # hammad.data.collections.collection
27
+ "Collection",
28
+
29
+ # hammad.data.collections.indexes
30
+ "TantivyCollectionIndex",
31
+ "QdrantCollectionIndex",
32
+ "TantivyCollectionIndexSettings",
33
+ "TantivyCollectionIndexQuerySettings",
34
+ "QdrantCollectionIndexSettings",
35
+ "QdrantCollectionIndexQuerySettings",
36
+ )
37
+
38
+
39
+ __getattr__ = create_getattr_importer(__all__)
40
+
41
+
42
+ def __dir__() -> list[str]:
43
+ """Get the attributes of the hammad.data.collections module."""
44
+ return list(__all__)
@@ -0,0 +1,274 @@
1
+ """hammad.data.collections.collection"""
2
+
3
+ from typing import (
4
+ Any,
5
+ Callable,
6
+ Dict,
7
+ List,
8
+ Literal,
9
+ Optional,
10
+ Type,
11
+ TypeVar,
12
+ Union,
13
+ overload,
14
+ TYPE_CHECKING,
15
+ )
16
+ from pathlib import Path
17
+
18
+ if TYPE_CHECKING:
19
+ from .indexes.tantivy.index import TantivyCollectionIndex
20
+ from .indexes.qdrant.index import QdrantCollectionIndex, VectorSearchResult
21
+ from .indexes.tantivy.settings import (
22
+ TantivyCollectionIndexSettings,
23
+ TantivyCollectionIndexQuerySettings,
24
+ )
25
+ from .indexes.qdrant.settings import (
26
+ QdrantCollectionIndexSettings,
27
+ QdrantCollectionIndexQuerySettings,
28
+ DistanceMetric,
29
+ )
30
+ from ..sql.types import DatabaseItemType
31
+ from ...genai.embedding_models.embedding_model_name import EmbeddingModelName
32
+ else:
33
+ from .indexes.tantivy.index import TantivyCollectionIndex
34
+ from .indexes.qdrant.index import QdrantCollectionIndex, VectorSearchResult
35
+
36
+
37
+ __all__ = (
38
+ "Collection",
39
+ "VectorSearchResult",
40
+ )
41
+
42
+
43
+ class Collection:
44
+ """
45
+ A unified collection factory that creates the appropriate collection index type
46
+ based on the provided parameters.
47
+
48
+ This class acts as a factory and doesn't contain its own logic - it simply
49
+ returns instances of TantivyCollectionIndex or QdrantCollectionIndex based on the
50
+ vector parameter.
51
+
52
+ The main difference from the old approach is that now collections are 'unified'
53
+ - there's no separate collections interface. Each collection directly uses either
54
+ a Tantivy or Qdrant index with SQL Database as the storage backend.
55
+ """
56
+
57
+ @overload
58
+ def __new__(
59
+ cls,
60
+ name: str = "default",
61
+ *,
62
+ schema: Optional[Type["DatabaseItemType"]] = None,
63
+ ttl: Optional[int] = None,
64
+ path: Optional[Union[Path, str]] = None,
65
+ vector: Literal[False] = False,
66
+ # Tantivy-specific parameters
67
+ fast: bool = True,
68
+ settings: Optional["TantivyCollectionIndexSettings"] = None,
69
+ query_settings: Optional["TantivyCollectionIndexQuerySettings"] = None,
70
+ ) -> "TantivyCollectionIndex": ...
71
+
72
+ @overload
73
+ def __new__(
74
+ cls,
75
+ name: str = "default",
76
+ *,
77
+ schema: Optional[Type["DatabaseItemType"]] = None,
78
+ ttl: Optional[int] = None,
79
+ path: Optional[Union[Path, str]] = None,
80
+ vector: Literal[True] = True,
81
+ vector_size: Optional[int] = None,
82
+ # Vector/Qdrant-specific parameters
83
+ distance_metric: "DistanceMetric" = "dot",
84
+ settings: Optional["QdrantCollectionIndexSettings"] = None,
85
+ query_settings: Optional["QdrantCollectionIndexQuerySettings"] = None,
86
+ embedding_model: Optional["EmbeddingModelName"] = "openai/text-embedding-3-small",
87
+ embedding_dimensions: Optional[int] = None,
88
+ embedding_api_key: Optional[str] = None,
89
+ embedding_base_url: Optional[str] = None,
90
+ # Rerank-specific parameters
91
+ rerank_model: Optional[str] = None,
92
+ rerank_api_key: Optional[str] = None,
93
+ rerank_base_url: Optional[str] = None,
94
+ ) -> "QdrantCollectionIndex": ...
95
+
96
+ def __new__(
97
+ cls,
98
+ name: str = "default",
99
+ *,
100
+ schema: Optional[Type["DatabaseItemType"]] = None,
101
+ ttl: Optional[int] = None,
102
+ path: Optional[Union[Path, str]] = None,
103
+ vector: bool = False,
104
+ vector_size: Optional[int] = None,
105
+ # Tantivy-specific parameters
106
+ fast: bool = True,
107
+ # Unified settings parameters
108
+ settings: Optional[Union["TantivyCollectionIndexSettings", "QdrantCollectionIndexSettings"]] = None,
109
+ query_settings: Optional[Union["TantivyCollectionIndexQuerySettings", "QdrantCollectionIndexQuerySettings"]] = None,
110
+ # Vector/Qdrant-specific parameters
111
+ distance_metric: "DistanceMetric" = "dot",
112
+ embedding_model: Optional["EmbeddingModelName"] = "openai/text-embedding-3-small",
113
+ embedding_dimensions: Optional[int] = None,
114
+ embedding_api_key: Optional[str] = None,
115
+ embedding_base_url: Optional[str] = None,
116
+ # Rerank-specific parameters
117
+ rerank_model: Optional[str] = None,
118
+ rerank_api_key: Optional[str] = None,
119
+ rerank_base_url: Optional[str] = None,
120
+ ) -> Union["TantivyCollectionIndex", "QdrantCollectionIndex"]:
121
+ """
122
+ Create a collection of the specified type.
123
+
124
+ Args:
125
+ name: Name of the collection
126
+ schema: Optional schema type for validation
127
+ ttl: Default TTL for items in seconds
128
+ path: File path for storage (None = in-memory)
129
+ vector: Whether this is a vector collection (True) or text search collection (False)
130
+ vector_size: Size of vectors (required for vector collections)
131
+
132
+ # Tantivy parameters (for non-vector collections):
133
+ fast: Whether to use fast schema building & indexing
134
+
135
+ # Unified parameters:
136
+ settings: Collection settings (TantivyCollectionIndexSettings or QdrantCollectionIndexSettings)
137
+ query_settings: Query behavior settings (TantivyCollectionIndexQuerySettings or QdrantCollectionIndexQuerySettings)
138
+
139
+ # Qdrant parameters (for vector collections):
140
+ distance_metric: Distance metric for similarity search
141
+ embedding_model: The embedding model to use (e.g., 'openai/text-embedding-3-small')
142
+ embedding_dimensions: Number of dimensions for embeddings
143
+ embedding_api_key: API key for the embedding service
144
+ embedding_base_url: Base URL for the embedding service
145
+
146
+ # Rerank parameters (for vector collections):
147
+ rerank_model: The rerank model to use (e.g., 'cohere/rerank-english-v3.0')
148
+ rerank_api_key: API key for the rerank service
149
+ rerank_base_url: Base URL for the rerank service
150
+
151
+ Returns:
152
+ A TantivyCollectionIndex or QdrantCollectionIndex instance
153
+ """
154
+ if vector:
155
+ # Vector collection using Qdrant
156
+ return QdrantCollectionIndex(
157
+ name=name,
158
+ vector_size=vector_size,
159
+ schema=schema,
160
+ ttl=ttl,
161
+ path=path,
162
+ distance_metric=distance_metric,
163
+ settings=settings,
164
+ query_settings=query_settings,
165
+ embedding_model=embedding_model,
166
+ embedding_dimensions=embedding_dimensions,
167
+ embedding_api_key=embedding_api_key,
168
+ embedding_base_url=embedding_base_url,
169
+ rerank_model=rerank_model,
170
+ rerank_api_key=rerank_api_key,
171
+ rerank_base_url=rerank_base_url,
172
+ )
173
+ else:
174
+ # Text search collection using Tantivy
175
+ return TantivyCollectionIndex(
176
+ name=name,
177
+ schema=schema,
178
+ ttl=ttl,
179
+ path=path,
180
+ fast=fast,
181
+ settings=settings,
182
+ query_settings=query_settings,
183
+ )
184
+
185
+
186
+ @overload
187
+ def create_collection(
188
+ name: str = "default",
189
+ *,
190
+ schema: Optional[Type["DatabaseItemType"]] = None,
191
+ ttl: Optional[int] = None,
192
+ path: Optional[Union[Path, str]] = None,
193
+ vector: Literal[False] = False,
194
+ # Tantivy-specific parameters
195
+ fast: bool = True,
196
+ settings: Optional["TantivyCollectionIndexSettings"] = None,
197
+ query_settings: Optional["TantivyCollectionIndexQuerySettings"] = None,
198
+ ) -> "TantivyCollectionIndex": ...
199
+
200
+ @overload
201
+ def create_collection(
202
+ name: str = "default",
203
+ *,
204
+ schema: Optional[Type["DatabaseItemType"]] = None,
205
+ ttl: Optional[int] = None,
206
+ path: Optional[Union[Path, str]] = None,
207
+ vector: Literal[True],
208
+ vector_size: Optional[int] = None,
209
+ # Vector/Qdrant-specific parameters
210
+ distance_metric: "DistanceMetric" = "dot",
211
+ settings: Optional["QdrantCollectionIndexSettings"] = None,
212
+ query_settings: Optional["QdrantCollectionIndexQuerySettings"] = None,
213
+ embedding_function: Optional[Callable[[Any], List[float]]] = None,
214
+ ) -> "QdrantCollectionIndex": ...
215
+
216
+ def create_collection(
217
+ name: str = "default",
218
+ *,
219
+ schema: Optional[Type["DatabaseItemType"]] = None,
220
+ ttl: Optional[int] = None,
221
+ path: Optional[Union[Path, str]] = None,
222
+ vector: bool = False,
223
+ vector_size: Optional[int] = None,
224
+ # Tantivy-specific parameters
225
+ fast: bool = True,
226
+ # Unified settings parameters
227
+ settings: Optional[Union["TantivyCollectionIndexSettings", "QdrantCollectionIndexSettings"]] = None,
228
+ query_settings: Optional[Union["TantivyCollectionIndexQuerySettings", "QdrantCollectionIndexQuerySettings"]] = None,
229
+ # Vector/Qdrant-specific parameters
230
+ distance_metric: "DistanceMetric" = "dot",
231
+ embedding_function: Optional[Callable[[Any], List[float]]] = None,
232
+ ) -> Union["TantivyCollectionIndex", "QdrantCollectionIndex"]:
233
+ """
234
+ Create a data collection of the specified type. Collections are a unified
235
+ interface for creating searchable, vectorizable data stores.
236
+
237
+ Args:
238
+ name: Name of the collection
239
+ schema: Optional schema type for validation
240
+ ttl: Default TTL for items in seconds
241
+ path: File path for storage (None = in-memory)
242
+ vector: Whether this is a vector collection (True) or text search collection (False)
243
+ vector_size: Size of vectors (required for vector collections)
244
+
245
+ # Tantivy parameters (for non-vector collections):
246
+ fast: Whether to use fast schema building & indexing
247
+
248
+ # Unified parameters:
249
+ settings: Collection settings (TantivyCollectionIndexSettings or QdrantCollectionIndexSettings)
250
+ query_settings: Query behavior settings (TantivyCollectionIndexQuerySettings or QdrantCollectionIndexQuerySettings)
251
+
252
+ # Qdrant parameters (for vector collections):
253
+ distance_metric: Distance metric for similarity search
254
+ embedding_model: The embedding model to use (e.g., 'openai/text-embedding-3-small')
255
+ embedding_dimensions: Number of dimensions for embeddings
256
+ embedding_api_key: API key for the embedding service
257
+ embedding_base_url: Base URL for the embedding service
258
+
259
+ Returns:
260
+ A TantivyCollectionIndex or QdrantCollectionIndex instance
261
+ """
262
+ return Collection(
263
+ name=name,
264
+ schema=schema,
265
+ ttl=ttl,
266
+ path=path,
267
+ vector=vector,
268
+ vector_size=vector_size,
269
+ fast=fast,
270
+ settings=settings,
271
+ query_settings=query_settings,
272
+ distance_metric=distance_metric,
273
+ embedding_function=embedding_function,
274
+ )
@@ -0,0 +1,37 @@
1
+ """hammad.data.collections.indexes"""
2
+
3
+ from typing import TYPE_CHECKING
4
+ from ...._internal import create_getattr_importer
5
+
6
+ if TYPE_CHECKING:
7
+ from .tantivy.index import TantivyCollectionIndex
8
+ from .qdrant.index import QdrantCollectionIndex
9
+
10
+ from .tantivy.settings import (
11
+ TantivyCollectionIndexSettings,
12
+ TantivyCollectionIndexQuerySettings,
13
+ )
14
+ from .qdrant.settings import (
15
+ QdrantCollectionIndexSettings,
16
+ QdrantCollectionIndexQuerySettings,
17
+ DistanceMetric,
18
+ )
19
+
20
+
21
+ __all__ = (
22
+ "TantivyCollectionIndex",
23
+ "QdrantCollectionIndex",
24
+ "TantivyCollectionIndexSettings",
25
+ "TantivyCollectionIndexQuerySettings",
26
+ "QdrantCollectionIndexSettings",
27
+ "QdrantCollectionIndexQuerySettings",
28
+ "DistanceMetric",
29
+ )
30
+
31
+
32
+ __getattr__ = create_getattr_importer(__all__)
33
+
34
+
35
+ def __dir__() -> list[str]:
36
+ """Get the attributes of the hammad.data.collections.indexes module."""
37
+ return list(__all__)
@@ -0,0 +1 @@
1
+ """hammad.lib.data.collections.indexes.qdrant"""