hammad-python 0.0.14__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 (101) 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 -1
  4. hammad/ai/__init__.py +0 -1
  5. hammad/ai/_utils.py +0 -142
  6. hammad/ai/completions/__init__.py +0 -45
  7. hammad/ai/completions/client.py +0 -684
  8. hammad/ai/completions/create.py +0 -710
  9. hammad/ai/completions/settings.py +0 -100
  10. hammad/ai/completions/types.py +0 -792
  11. hammad/ai/completions/utils.py +0 -486
  12. hammad/ai/embeddings/__init__.py +0 -35
  13. hammad/ai/embeddings/client/__init__.py +0 -1
  14. hammad/ai/embeddings/client/base_embeddings_client.py +0 -26
  15. hammad/ai/embeddings/client/fastembed_text_embeddings_client.py +0 -200
  16. hammad/ai/embeddings/client/litellm_embeddings_client.py +0 -288
  17. hammad/ai/embeddings/create.py +0 -159
  18. hammad/ai/embeddings/types.py +0 -69
  19. hammad/cache/__init__.py +0 -40
  20. hammad/cache/base_cache.py +0 -181
  21. hammad/cache/cache.py +0 -169
  22. hammad/cache/decorators.py +0 -261
  23. hammad/cache/file_cache.py +0 -80
  24. hammad/cache/ttl_cache.py +0 -74
  25. hammad/cli/__init__.py +0 -33
  26. hammad/cli/animations.py +0 -573
  27. hammad/cli/plugins.py +0 -781
  28. hammad/cli/styles/__init__.py +0 -55
  29. hammad/cli/styles/settings.py +0 -139
  30. hammad/cli/styles/types.py +0 -358
  31. hammad/cli/styles/utils.py +0 -480
  32. hammad/data/__init__.py +0 -56
  33. hammad/data/collections/__init__.py +0 -34
  34. hammad/data/collections/base_collection.py +0 -58
  35. hammad/data/collections/collection.py +0 -452
  36. hammad/data/collections/searchable_collection.py +0 -556
  37. hammad/data/collections/vector_collection.py +0 -596
  38. hammad/data/configurations/__init__.py +0 -35
  39. hammad/data/configurations/configuration.py +0 -564
  40. hammad/data/databases/__init__.py +0 -21
  41. hammad/data/databases/database.py +0 -902
  42. hammad/data/models/__init__.py +0 -44
  43. hammad/data/models/base/__init__.py +0 -35
  44. hammad/data/models/base/fields.py +0 -546
  45. hammad/data/models/base/model.py +0 -1078
  46. hammad/data/models/base/utils.py +0 -280
  47. hammad/data/models/pydantic/__init__.py +0 -55
  48. hammad/data/models/pydantic/converters.py +0 -632
  49. hammad/data/models/pydantic/models/__init__.py +0 -28
  50. hammad/data/models/pydantic/models/arbitrary_model.py +0 -46
  51. hammad/data/models/pydantic/models/cacheable_model.py +0 -79
  52. hammad/data/models/pydantic/models/fast_model.py +0 -318
  53. hammad/data/models/pydantic/models/function_model.py +0 -176
  54. hammad/data/models/pydantic/models/subscriptable_model.py +0 -63
  55. hammad/data/types/__init__.py +0 -41
  56. hammad/data/types/file.py +0 -358
  57. hammad/data/types/multimodal/__init__.py +0 -24
  58. hammad/data/types/multimodal/audio.py +0 -96
  59. hammad/data/types/multimodal/image.py +0 -80
  60. hammad/data/types/text.py +0 -1066
  61. hammad/formatting/__init__.py +0 -38
  62. hammad/formatting/json/__init__.py +0 -21
  63. hammad/formatting/json/converters.py +0 -152
  64. hammad/formatting/text/__init__.py +0 -63
  65. hammad/formatting/text/converters.py +0 -723
  66. hammad/formatting/text/markdown.py +0 -131
  67. hammad/formatting/yaml/__init__.py +0 -26
  68. hammad/formatting/yaml/converters.py +0 -5
  69. hammad/logging/__init__.py +0 -35
  70. hammad/logging/decorators.py +0 -834
  71. hammad/logging/logger.py +0 -954
  72. hammad/mcp/__init__.py +0 -50
  73. hammad/mcp/client/__init__.py +0 -1
  74. hammad/mcp/client/client.py +0 -523
  75. hammad/mcp/client/client_service.py +0 -393
  76. hammad/mcp/client/settings.py +0 -178
  77. hammad/mcp/servers/__init__.py +0 -1
  78. hammad/mcp/servers/launcher.py +0 -1161
  79. hammad/performance/__init__.py +0 -36
  80. hammad/performance/imports.py +0 -231
  81. hammad/performance/runtime/__init__.py +0 -32
  82. hammad/performance/runtime/decorators.py +0 -142
  83. hammad/performance/runtime/run.py +0 -299
  84. hammad/py.typed +0 -0
  85. hammad/service/__init__.py +0 -49
  86. hammad/service/create.py +0 -532
  87. hammad/service/decorators.py +0 -285
  88. hammad/typing/__init__.py +0 -407
  89. hammad/web/__init__.py +0 -43
  90. hammad/web/http/__init__.py +0 -1
  91. hammad/web/http/client.py +0 -944
  92. hammad/web/models.py +0 -245
  93. hammad/web/openapi/__init__.py +0 -1
  94. hammad/web/openapi/client.py +0 -740
  95. hammad/web/search/__init__.py +0 -1
  96. hammad/web/search/client.py +0 -988
  97. hammad/web/utils.py +0 -472
  98. hammad_python-0.0.14.dist-info/METADATA +0 -70
  99. hammad_python-0.0.14.dist-info/RECORD +0 -99
  100. {hammad_python-0.0.14.dist-info → hammad_python-0.0.15.dist-info}/WHEEL +0 -0
  101. {hammad_python-0.0.14.dist-info → hammad_python-0.0.15.dist-info}/licenses/LICENSE +0 -0
@@ -1,280 +0,0 @@
1
- """hammad.base.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
@@ -1,55 +0,0 @@
1
- """hammad.models.pydantic
2
-
3
- Contains both models and pydantic **specific** utiltiies / resources
4
- meant for general case usage."""
5
-
6
- from typing import TYPE_CHECKING
7
- from ....performance.imports import create_getattr_importer
8
-
9
- if TYPE_CHECKING:
10
- from .models import (
11
- ArbitraryModel,
12
- CacheableModel,
13
- FastModel,
14
- FunctionModel,
15
- SubscriptableModel,
16
- )
17
- from .converters import (
18
- convert_to_pydantic_model,
19
- convert_to_pydantic_field,
20
- convert_dataclass_to_pydantic_model,
21
- convert_dict_to_pydantic_model,
22
- convert_function_to_pydantic_model,
23
- convert_sequence_to_pydantic_model,
24
- convert_type_to_pydantic_model,
25
- create_confirmation_pydantic_model,
26
- create_selection_pydantic_model,
27
- )
28
-
29
-
30
- __all__ = (
31
- # hammad.models.pydantic.models
32
- "ArbitraryModel",
33
- "CacheableModel",
34
- "FastModel",
35
- "FunctionModel",
36
- "SubscriptableModel",
37
- # hammad.models.pydantic.converters
38
- "convert_to_pydantic_model",
39
- "convert_to_pydantic_field",
40
- "convert_dataclass_to_pydantic_model",
41
- "convert_dict_to_pydantic_model",
42
- "convert_function_to_pydantic_model",
43
- "convert_sequence_to_pydantic_model",
44
- "convert_type_to_pydantic_model",
45
- "create_confirmation_pydantic_model",
46
- "create_selection_pydantic_model",
47
- )
48
-
49
-
50
- __getattr__ = create_getattr_importer(__all__)
51
-
52
-
53
- def __dir__() -> list[str]:
54
- """Get the attributes of the models module."""
55
- return list(__all__)