hammad-python 0.0.29__py3-none-any.whl → 0.0.31__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.
- ham/__init__.py +10 -0
- {hammad_python-0.0.29.dist-info → hammad_python-0.0.31.dist-info}/METADATA +6 -32
- hammad_python-0.0.31.dist-info/RECORD +6 -0
- hammad/__init__.py +0 -84
- hammad/_internal.py +0 -256
- hammad/_main.py +0 -226
- hammad/cache/__init__.py +0 -40
- hammad/cache/base_cache.py +0 -181
- hammad/cache/cache.py +0 -169
- hammad/cache/decorators.py +0 -261
- hammad/cache/file_cache.py +0 -80
- hammad/cache/ttl_cache.py +0 -74
- hammad/cli/__init__.py +0 -33
- hammad/cli/animations.py +0 -573
- hammad/cli/plugins.py +0 -867
- hammad/cli/styles/__init__.py +0 -55
- hammad/cli/styles/settings.py +0 -139
- hammad/cli/styles/types.py +0 -358
- hammad/cli/styles/utils.py +0 -634
- hammad/data/__init__.py +0 -90
- hammad/data/collections/__init__.py +0 -49
- hammad/data/collections/collection.py +0 -326
- hammad/data/collections/indexes/__init__.py +0 -37
- hammad/data/collections/indexes/qdrant/__init__.py +0 -1
- hammad/data/collections/indexes/qdrant/index.py +0 -723
- hammad/data/collections/indexes/qdrant/settings.py +0 -94
- hammad/data/collections/indexes/qdrant/utils.py +0 -210
- hammad/data/collections/indexes/tantivy/__init__.py +0 -1
- hammad/data/collections/indexes/tantivy/index.py +0 -426
- hammad/data/collections/indexes/tantivy/settings.py +0 -40
- hammad/data/collections/indexes/tantivy/utils.py +0 -176
- hammad/data/configurations/__init__.py +0 -35
- hammad/data/configurations/configuration.py +0 -564
- hammad/data/models/__init__.py +0 -50
- hammad/data/models/extensions/__init__.py +0 -4
- hammad/data/models/extensions/pydantic/__init__.py +0 -42
- hammad/data/models/extensions/pydantic/converters.py +0 -759
- hammad/data/models/fields.py +0 -546
- hammad/data/models/model.py +0 -1078
- hammad/data/models/utils.py +0 -280
- hammad/data/sql/__init__.py +0 -24
- hammad/data/sql/database.py +0 -576
- hammad/data/sql/types.py +0 -127
- hammad/data/types/__init__.py +0 -75
- hammad/data/types/file.py +0 -431
- hammad/data/types/multimodal/__init__.py +0 -36
- hammad/data/types/multimodal/audio.py +0 -200
- hammad/data/types/multimodal/image.py +0 -182
- hammad/data/types/text.py +0 -1308
- hammad/formatting/__init__.py +0 -33
- hammad/formatting/json/__init__.py +0 -27
- hammad/formatting/json/converters.py +0 -158
- hammad/formatting/text/__init__.py +0 -63
- hammad/formatting/text/converters.py +0 -723
- hammad/formatting/text/markdown.py +0 -131
- hammad/formatting/yaml/__init__.py +0 -26
- hammad/formatting/yaml/converters.py +0 -5
- hammad/genai/__init__.py +0 -217
- hammad/genai/a2a/__init__.py +0 -32
- hammad/genai/a2a/workers.py +0 -552
- hammad/genai/agents/__init__.py +0 -59
- hammad/genai/agents/agent.py +0 -1973
- hammad/genai/agents/run.py +0 -1024
- hammad/genai/agents/types/__init__.py +0 -42
- hammad/genai/agents/types/agent_context.py +0 -13
- hammad/genai/agents/types/agent_event.py +0 -128
- hammad/genai/agents/types/agent_hooks.py +0 -220
- hammad/genai/agents/types/agent_messages.py +0 -31
- hammad/genai/agents/types/agent_response.py +0 -125
- hammad/genai/agents/types/agent_stream.py +0 -327
- hammad/genai/graphs/__init__.py +0 -125
- hammad/genai/graphs/_utils.py +0 -190
- hammad/genai/graphs/base.py +0 -1828
- hammad/genai/graphs/plugins.py +0 -316
- hammad/genai/graphs/types.py +0 -638
- hammad/genai/models/__init__.py +0 -1
- hammad/genai/models/embeddings/__init__.py +0 -43
- hammad/genai/models/embeddings/model.py +0 -226
- hammad/genai/models/embeddings/run.py +0 -163
- hammad/genai/models/embeddings/types/__init__.py +0 -37
- hammad/genai/models/embeddings/types/embedding_model_name.py +0 -75
- hammad/genai/models/embeddings/types/embedding_model_response.py +0 -76
- hammad/genai/models/embeddings/types/embedding_model_run_params.py +0 -66
- hammad/genai/models/embeddings/types/embedding_model_settings.py +0 -47
- hammad/genai/models/language/__init__.py +0 -57
- hammad/genai/models/language/model.py +0 -1098
- hammad/genai/models/language/run.py +0 -878
- hammad/genai/models/language/types/__init__.py +0 -40
- hammad/genai/models/language/types/language_model_instructor_mode.py +0 -47
- hammad/genai/models/language/types/language_model_messages.py +0 -28
- hammad/genai/models/language/types/language_model_name.py +0 -239
- hammad/genai/models/language/types/language_model_request.py +0 -127
- hammad/genai/models/language/types/language_model_response.py +0 -217
- hammad/genai/models/language/types/language_model_response_chunk.py +0 -56
- hammad/genai/models/language/types/language_model_settings.py +0 -89
- hammad/genai/models/language/types/language_model_stream.py +0 -600
- hammad/genai/models/language/utils/__init__.py +0 -28
- hammad/genai/models/language/utils/requests.py +0 -421
- hammad/genai/models/language/utils/structured_outputs.py +0 -135
- hammad/genai/models/model_provider.py +0 -4
- hammad/genai/models/multimodal.py +0 -47
- hammad/genai/models/reranking.py +0 -26
- hammad/genai/types/__init__.py +0 -1
- hammad/genai/types/base.py +0 -215
- hammad/genai/types/history.py +0 -290
- hammad/genai/types/tools.py +0 -507
- hammad/logging/__init__.py +0 -35
- hammad/logging/decorators.py +0 -834
- hammad/logging/logger.py +0 -1018
- hammad/mcp/__init__.py +0 -53
- hammad/mcp/client/__init__.py +0 -35
- hammad/mcp/client/client.py +0 -624
- hammad/mcp/client/client_service.py +0 -400
- hammad/mcp/client/settings.py +0 -178
- hammad/mcp/servers/__init__.py +0 -26
- hammad/mcp/servers/launcher.py +0 -1161
- hammad/runtime/__init__.py +0 -32
- hammad/runtime/decorators.py +0 -142
- hammad/runtime/run.py +0 -299
- hammad/service/__init__.py +0 -49
- hammad/service/create.py +0 -527
- hammad/service/decorators.py +0 -283
- hammad/types.py +0 -288
- hammad/typing/__init__.py +0 -435
- hammad/web/__init__.py +0 -43
- hammad/web/http/__init__.py +0 -1
- hammad/web/http/client.py +0 -944
- hammad/web/models.py +0 -275
- hammad/web/openapi/__init__.py +0 -1
- hammad/web/openapi/client.py +0 -740
- hammad/web/search/__init__.py +0 -1
- hammad/web/search/client.py +0 -1023
- hammad/web/utils.py +0 -472
- hammad_python-0.0.29.dist-info/RECORD +0 -135
- {hammad → ham}/py.typed +0 -0
- {hammad_python-0.0.29.dist-info → hammad_python-0.0.31.dist-info}/WHEEL +0 -0
- {hammad_python-0.0.29.dist-info → hammad_python-0.0.31.dist-info}/licenses/LICENSE +0 -0
hammad/data/models/utils.py
DELETED
@@ -1,280 +0,0 @@
|
|
1
|
-
"""hammad.data.models.utils"""
|
2
|
-
|
3
|
-
from functools import lru_cache
|
4
|
-
from typing import Any, Callable, Optional, Union, Tuple, Dict
|
5
|
-
|
6
|
-
from msgspec.structs import Struct
|
7
|
-
|
8
|
-
from .fields import FieldInfo, field, Field
|
9
|
-
from .model import Model
|
10
|
-
|
11
|
-
|
12
|
-
__all__ = (
|
13
|
-
"create_model",
|
14
|
-
"get_field_info",
|
15
|
-
"is_field",
|
16
|
-
"is_model",
|
17
|
-
"validator",
|
18
|
-
)
|
19
|
-
|
20
|
-
|
21
|
-
def create_model(
|
22
|
-
__model_name: str,
|
23
|
-
*,
|
24
|
-
__base__: Optional[Union[type, Tuple[type, ...]]] = None,
|
25
|
-
__module__: Optional[str] = None,
|
26
|
-
__qualname__: Optional[str] = None,
|
27
|
-
__doc__: Optional[str] = None,
|
28
|
-
__validators__: Optional[Dict[str, Any]] = None,
|
29
|
-
__config__: Optional[type] = None,
|
30
|
-
**field_definitions: Any,
|
31
|
-
) -> type[Model]:
|
32
|
-
"""Create a Model dynamically with Pydantic-compatible interface.
|
33
|
-
|
34
|
-
This function provides a drop-in replacement for pydantic.create_model()
|
35
|
-
that creates Model classes instead of pydantic BaseModel classes.
|
36
|
-
|
37
|
-
Args:
|
38
|
-
__model_name: Name of the model class to create
|
39
|
-
__base__: Base class(es) to inherit from. If None, uses Model.
|
40
|
-
Can be a single class or tuple of classes.
|
41
|
-
__module__: Module name for the created class
|
42
|
-
__qualname__: Qualified name for the created class
|
43
|
-
__doc__: Docstring for the created class
|
44
|
-
__validators__: Dictionary of validators (for compatibility - not fully implemented)
|
45
|
-
__config__: Configuration class (for compatibility - not fully implemented)
|
46
|
-
**field_definitions: Field definitions as keyword arguments.
|
47
|
-
Each can be:
|
48
|
-
- A type annotation (e.g., str, int)
|
49
|
-
- A tuple of (type, default_value)
|
50
|
-
- A tuple of (type, Field(...))
|
51
|
-
- A Field instance
|
52
|
-
|
53
|
-
Returns:
|
54
|
-
A new Model class with the specified fields
|
55
|
-
|
56
|
-
Examples:
|
57
|
-
# Simple model with basic types
|
58
|
-
User = create_model('User', name=str, age=int)
|
59
|
-
|
60
|
-
# Model with defaults
|
61
|
-
Config = create_model('Config',
|
62
|
-
host=(str, 'localhost'),
|
63
|
-
port=(int, 8080))
|
64
|
-
|
65
|
-
# Model with field constraints
|
66
|
-
Product = create_model('Product',
|
67
|
-
name=str,
|
68
|
-
price=(float, field(gt=0)),
|
69
|
-
tags=(List[str], field(default_factory=list)))
|
70
|
-
|
71
|
-
# Model with custom base class
|
72
|
-
class BaseEntity(Model):
|
73
|
-
id: int
|
74
|
-
created_at: str
|
75
|
-
|
76
|
-
User = create_model('User',
|
77
|
-
name=str,
|
78
|
-
email=str,
|
79
|
-
__base__=BaseEntity)
|
80
|
-
"""
|
81
|
-
# Handle base class specification
|
82
|
-
if __base__ is not None and __config__ is not None:
|
83
|
-
raise ValueError(
|
84
|
-
"Cannot specify both '__base__' and '__config__' - "
|
85
|
-
"use a base class with the desired configuration instead"
|
86
|
-
)
|
87
|
-
|
88
|
-
# Determine base classes
|
89
|
-
if __base__ is None:
|
90
|
-
bases = (Model,)
|
91
|
-
elif isinstance(__base__, tuple):
|
92
|
-
# Ensure all bases are compatible
|
93
|
-
for base in __base__:
|
94
|
-
if not (issubclass(base, Model) or issubclass(base, Struct)):
|
95
|
-
raise ValueError(
|
96
|
-
f"Base class {base} must be a subclass of Model or msgspec.Struct"
|
97
|
-
)
|
98
|
-
bases = __base__
|
99
|
-
else:
|
100
|
-
if not (issubclass(__base__, Model) or issubclass(__base__, Struct)):
|
101
|
-
raise ValueError(
|
102
|
-
f"Base class {__base__} must be a subclass of Model or msgspec.Struct"
|
103
|
-
)
|
104
|
-
bases = (__base__,)
|
105
|
-
|
106
|
-
# Build class dictionary
|
107
|
-
class_dict = {}
|
108
|
-
annotations = {}
|
109
|
-
|
110
|
-
# Set metadata
|
111
|
-
if __doc__ is not None:
|
112
|
-
class_dict["__doc__"] = __doc__
|
113
|
-
if __module__ is not None:
|
114
|
-
class_dict["__module__"] = __module__
|
115
|
-
if __qualname__ is not None:
|
116
|
-
class_dict["__qualname__"] = __qualname__
|
117
|
-
|
118
|
-
# Process field definitions in two passes to ensure proper ordering
|
119
|
-
# First pass: collect required and optional fields separately
|
120
|
-
required_fields = {}
|
121
|
-
optional_fields = {}
|
122
|
-
|
123
|
-
for field_name, field_definition in field_definitions.items():
|
124
|
-
if field_name.startswith("__") and field_name.endswith("__"):
|
125
|
-
# Skip special attributes that were passed as field definitions
|
126
|
-
continue
|
127
|
-
|
128
|
-
# Parse field definition
|
129
|
-
is_optional = False
|
130
|
-
|
131
|
-
if isinstance(field_definition, tuple):
|
132
|
-
if len(field_definition) == 2:
|
133
|
-
field_type, field_value = field_definition
|
134
|
-
annotations[field_name] = field_type
|
135
|
-
|
136
|
-
# Check if field_value is a Field instance or field
|
137
|
-
if hasattr(field_value, "__class__") and (
|
138
|
-
"field" in field_value.__class__.__name__.lower()
|
139
|
-
or hasattr(field_value, "default")
|
140
|
-
or callable(getattr(field_value, "__call__", None))
|
141
|
-
):
|
142
|
-
# It's a field descriptor
|
143
|
-
optional_fields[field_name] = field_value
|
144
|
-
else:
|
145
|
-
# It's a default value - create a field with this default
|
146
|
-
optional_fields[field_name] = field(default=field_value)
|
147
|
-
is_optional = True
|
148
|
-
else:
|
149
|
-
raise ValueError(
|
150
|
-
f"Field definition for '{field_name}' must be a 2-tuple of (type, default/Field)"
|
151
|
-
)
|
152
|
-
elif hasattr(field_definition, "__origin__") or hasattr(
|
153
|
-
field_definition, "__class__"
|
154
|
-
):
|
155
|
-
# It's a type annotation (like str, int, List[str], etc.) - required field
|
156
|
-
annotations[field_name] = field_definition
|
157
|
-
required_fields[field_name] = None
|
158
|
-
else:
|
159
|
-
# It's likely a default value without type annotation
|
160
|
-
# We'll infer the type from the value
|
161
|
-
annotations[field_name] = type(field_definition)
|
162
|
-
optional_fields[field_name] = field(default=field_definition)
|
163
|
-
is_optional = True
|
164
|
-
|
165
|
-
# Second pass: add fields in correct order (required first, then optional)
|
166
|
-
# This ensures msgspec field ordering requirements are met
|
167
|
-
for field_name, field_value in required_fields.items():
|
168
|
-
if field_value is not None:
|
169
|
-
class_dict[field_name] = field_value
|
170
|
-
|
171
|
-
for field_name, field_value in optional_fields.items():
|
172
|
-
class_dict[field_name] = field_value
|
173
|
-
|
174
|
-
# Set annotations in proper order (required fields first, then optional)
|
175
|
-
ordered_annotations = {}
|
176
|
-
|
177
|
-
# Add required field annotations first
|
178
|
-
for field_name in required_fields:
|
179
|
-
if field_name in annotations:
|
180
|
-
ordered_annotations[field_name] = annotations[field_name]
|
181
|
-
|
182
|
-
# Add optional field annotations second
|
183
|
-
for field_name in optional_fields:
|
184
|
-
if field_name in annotations:
|
185
|
-
ordered_annotations[field_name] = annotations[field_name]
|
186
|
-
|
187
|
-
class_dict["__annotations__"] = ordered_annotations
|
188
|
-
|
189
|
-
# Handle validators (basic implementation for compatibility)
|
190
|
-
if __validators__:
|
191
|
-
# Store validators for potential future use
|
192
|
-
class_dict["_validators"] = __validators__
|
193
|
-
# Note: Full validator implementation would require more complex integration
|
194
|
-
|
195
|
-
# Create the dynamic class
|
196
|
-
try:
|
197
|
-
DynamicModel = type(__model_name, bases, class_dict)
|
198
|
-
except Exception as e:
|
199
|
-
raise ValueError(f"Failed to create model '{__model_name}': {e}") from e
|
200
|
-
|
201
|
-
return DynamicModel
|
202
|
-
|
203
|
-
|
204
|
-
@lru_cache(maxsize=None)
|
205
|
-
def get_field_info(field: Any) -> Optional[FieldInfo]:
|
206
|
-
"""Extract FieldInfo from a field descriptor with caching."""
|
207
|
-
if isinstance(field, tuple) and len(field) == 2:
|
208
|
-
_, field_info = field
|
209
|
-
if isinstance(field_info, FieldInfo):
|
210
|
-
return field_info
|
211
|
-
elif hasattr(field, "_field_info"):
|
212
|
-
return field._field_info
|
213
|
-
elif hasattr(field, "field_info"):
|
214
|
-
return field.field_info
|
215
|
-
elif isinstance(field, Field):
|
216
|
-
return field.field_info
|
217
|
-
elif hasattr(field, "__class__") and field.__class__.__name__ == "FieldDescriptor":
|
218
|
-
return field.field_info
|
219
|
-
return None
|
220
|
-
|
221
|
-
|
222
|
-
def is_field(field: Any) -> bool:
|
223
|
-
"""Check if a field is a field."""
|
224
|
-
return get_field_info(field) is not None
|
225
|
-
|
226
|
-
|
227
|
-
def is_model(model: Any) -> bool:
|
228
|
-
"""Check if a model is a model."""
|
229
|
-
# Check if it's an instance of Model
|
230
|
-
if isinstance(model, Model):
|
231
|
-
return True
|
232
|
-
|
233
|
-
# Check if it's a Model class (not instance)
|
234
|
-
if isinstance(model, type) and issubclass(model, Model):
|
235
|
-
return True
|
236
|
-
|
237
|
-
# Check for Model characteristics using duck typing
|
238
|
-
# Look for key Model/msgspec.Struct attributes and methods
|
239
|
-
if hasattr(model, "__struct_fields__") and hasattr(model, "model_dump"):
|
240
|
-
# Check for Model-specific methods
|
241
|
-
if (
|
242
|
-
hasattr(model, "model_copy")
|
243
|
-
and hasattr(model, "model_validate")
|
244
|
-
and hasattr(model, "model_to_pydantic")
|
245
|
-
):
|
246
|
-
return True
|
247
|
-
|
248
|
-
# Check if it's an instance of any msgspec Struct with Model methods
|
249
|
-
try:
|
250
|
-
if isinstance(model, Struct) and hasattr(model, "model_dump"):
|
251
|
-
return True
|
252
|
-
except ImportError:
|
253
|
-
pass
|
254
|
-
|
255
|
-
return False
|
256
|
-
|
257
|
-
|
258
|
-
def validator(
|
259
|
-
*fields: str, pre: bool = False, post: bool = False, always: bool = False
|
260
|
-
):
|
261
|
-
"""Decorator to create a validator for specific fields.
|
262
|
-
|
263
|
-
Args:
|
264
|
-
*fields: Field names to validate
|
265
|
-
pre: Whether this is a pre-validator
|
266
|
-
post: Whether this is a post-validator
|
267
|
-
always: Whether to run even if the value is not set
|
268
|
-
|
269
|
-
Returns:
|
270
|
-
Decorator function
|
271
|
-
"""
|
272
|
-
|
273
|
-
def decorator(func: Callable) -> Callable:
|
274
|
-
func._validator_fields = fields
|
275
|
-
func._validator_pre = pre
|
276
|
-
func._validator_post = post
|
277
|
-
func._validator_always = always
|
278
|
-
return func
|
279
|
-
|
280
|
-
return decorator
|
hammad/data/sql/__init__.py
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
"""hammad.data.sql"""
|
2
|
-
|
3
|
-
from typing import TYPE_CHECKING
|
4
|
-
from ..._internal import create_getattr_importer
|
5
|
-
|
6
|
-
if TYPE_CHECKING:
|
7
|
-
from .types import DatabaseItemType, DatabaseItem
|
8
|
-
from .database import Database, create_database
|
9
|
-
|
10
|
-
|
11
|
-
__all__ = (
|
12
|
-
"DatabaseItemType",
|
13
|
-
"DatabaseItem",
|
14
|
-
"Database",
|
15
|
-
"create_database",
|
16
|
-
)
|
17
|
-
|
18
|
-
|
19
|
-
__getattr__ = create_getattr_importer(__all__)
|
20
|
-
|
21
|
-
|
22
|
-
def __dir__() -> list[str]:
|
23
|
-
"""Get the attributes of the hammad.data.sql module."""
|
24
|
-
return list(__all__)
|