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,20 @@
1
+ """hammad.formatting"""
2
+
3
+ from typing import TYPE_CHECKING
4
+ from .._internal import create_getattr_importer
5
+
6
+ if TYPE_CHECKING:
7
+ from . import json
8
+ from . import text
9
+ from . import yaml
10
+
11
+ __all__ = (
12
+ "json",
13
+ "text",
14
+ "yaml",
15
+ )
16
+
17
+ __getattr__ = create_getattr_importer(__all__)
18
+
19
+ def __dir__() -> list[str]:
20
+ return list(__all__)
@@ -0,0 +1,27 @@
1
+ """hammad.formatting.json"""
2
+
3
+ from typing import TYPE_CHECKING
4
+ from ..._internal import create_getattr_importer
5
+
6
+ if TYPE_CHECKING:
7
+ from .converters import (
8
+ convert_to_json_schema,
9
+ convert_to_json,
10
+ encode_json,
11
+ decode_json,
12
+ )
13
+
14
+ __all__ = (
15
+ "convert_to_json_schema",
16
+ "convert_to_json",
17
+ "encode_json",
18
+ "decode_json",
19
+ )
20
+
21
+
22
+ __getattr__ = create_getattr_importer(__all__)
23
+
24
+
25
+ def __dir__() -> list[str]:
26
+ """Get the attributes of the json module."""
27
+ return list(__all__)
@@ -0,0 +1,158 @@
1
+ """hammad.formatting.json.converters
2
+
3
+ Contains various utility functions used when working with JSON data."""
4
+
5
+ import dataclasses
6
+ from typing import Any
7
+ import msgspec
8
+ from msgspec.json import encode as encode_json, decode as decode_json
9
+
10
+ from ...typing import get_type_description, inspection # type: ignore
11
+
12
+ __all__ = (
13
+ "SchemaError",
14
+ "convert_to_json_schema",
15
+ "encode",
16
+ "decode",
17
+ )
18
+
19
+
20
+ class SchemaError(Exception):
21
+ """An exception raised when a schema utility raises an error."""
22
+
23
+
24
+ def convert_to_json_schema(t: Any) -> dict:
25
+ """Converts various objects, types, and interfaces into
26
+ a JSON schema.
27
+
28
+ Args:
29
+ t: The object, type, or interface to convert to a JSON schema.
30
+
31
+ Returns:
32
+ A JSON schema as a dictionary.
33
+ """
34
+ from dataclasses import is_dataclass, fields as dataclass_fields
35
+ import inspect
36
+ from typing import get_type_hints
37
+
38
+ schema = {"type": "object", "properties": {}}
39
+
40
+ # Handle msgspec Struct
41
+ try:
42
+ if isinstance(t, type) and issubclass(t, msgspec.Struct):
43
+ struct_info = msgspec.structs.fields(t)
44
+ for field in struct_info:
45
+ field_type = field.type
46
+ field_schema = {
47
+ "type": get_type_description(field_type),
48
+ "description": f"Field of type {get_type_description(field_type)}",
49
+ }
50
+ if field.default is not msgspec.NODEFAULT:
51
+ field_schema["default"] = field.default
52
+ schema["properties"][field.name] = field_schema
53
+ return schema
54
+ except (ImportError, AttributeError):
55
+ pass
56
+
57
+ # Handle Pydantic models
58
+ try:
59
+ from pydantic import BaseModel
60
+
61
+ if isinstance(t, type) and issubclass(t, BaseModel):
62
+ pydantic_schema = (
63
+ t.model_json_schema() if hasattr(t, "model_json_schema") else t.schema()
64
+ )
65
+ return pydantic_schema
66
+ except ImportError:
67
+ pass
68
+
69
+ # Handle dataclasses
70
+ if is_dataclass(t):
71
+ if isinstance(t, type):
72
+ # Class-level dataclass
73
+ for field in dataclass_fields(t):
74
+ field_type = field.type
75
+ field_schema = {
76
+ "type": get_type_description(field_type),
77
+ "description": f"Field of type {get_type_description(field_type)}",
78
+ }
79
+ if field.default is not dataclasses.MISSING:
80
+ field_schema["default"] = field.default
81
+ elif field.default_factory is not dataclasses.MISSING:
82
+ field_schema["default"] = "factory function"
83
+ schema["properties"][field.name] = field_schema
84
+ else:
85
+ # Instance-level dataclass
86
+ for field in dataclass_fields(t):
87
+ field_type = field.type
88
+ field_schema = {
89
+ "type": get_type_description(field_type),
90
+ "description": f"Field of type {get_type_description(field_type)}",
91
+ "value": getattr(t, field.name, None),
92
+ }
93
+ schema["properties"][field.name] = field_schema
94
+ return schema
95
+
96
+ # Handle regular classes with type hints (including abstract classes)
97
+ if inspect.isclass(t):
98
+ try:
99
+ type_hints = get_type_hints(t)
100
+ for name, type_hint in type_hints.items():
101
+ schema["properties"][name] = {
102
+ "type": get_type_description(type_hint),
103
+ "description": f"Field of type {get_type_description(type_hint)}",
104
+ }
105
+ except (NameError, AttributeError):
106
+ pass
107
+ return schema
108
+
109
+ # Handle dictionary
110
+ if isinstance(t, dict):
111
+ for key, value in t.items():
112
+ schema["properties"][key] = {
113
+ "type": type(value).__name__,
114
+ "description": f"Field of type {type(value).__name__}",
115
+ "example": value,
116
+ }
117
+ return schema
118
+
119
+ # Handle basic types and type hints
120
+ origin = inspection.get_origin(t)
121
+ if origin is not None:
122
+ args = inspection.get_args(t)
123
+ if origin is list and args:
124
+ return {"type": "array", "items": {"type": get_type_description(args[0])}}
125
+ elif origin is dict and len(args) == 2:
126
+ return {
127
+ "type": "object",
128
+ "additionalProperties": {"type": get_type_description(args[1])},
129
+ "description": f"Object with {get_type_description(args[0])} keys",
130
+ }
131
+ elif origin is tuple and args:
132
+ return {
133
+ "type": "array",
134
+ "items": [{"type": get_type_description(arg)} for arg in args],
135
+ "minItems": len(args),
136
+ "maxItems": len(args),
137
+ }
138
+ elif inspection.is_union_type(t):
139
+ if inspection.is_optional_type(t):
140
+ non_none_args = [arg for arg in args if arg is not type(None)]
141
+ if non_none_args:
142
+ return {
143
+ "type": get_type_description(non_none_args[0]),
144
+ "nullable": True,
145
+ }
146
+ else:
147
+ return {"anyOf": [{"type": get_type_description(arg)} for arg in args]}
148
+ elif inspection.is_literal_type(t) and args:
149
+ return {"enum": list(args)}
150
+
151
+ # Default to string representation of type
152
+ return {"type": get_type_description(t)}
153
+
154
+
155
+ def convert_to_json(
156
+ target : Any,
157
+ ) -> str:
158
+ return encode_json(target).decode()
@@ -0,0 +1,63 @@
1
+ """hammad.formatting.text
2
+
3
+ Contains resources for working with text / markdown formatting."""
4
+
5
+ from typing import TYPE_CHECKING
6
+ from ..._internal import create_getattr_importer
7
+
8
+ if TYPE_CHECKING:
9
+ from .converters import (
10
+ convert_collection_to_text,
11
+ convert_dataclass_to_text,
12
+ convert_dict_to_text,
13
+ convert_docstring_to_text,
14
+ convert_function_to_text,
15
+ convert_pydantic_to_text,
16
+ convert_type_to_text,
17
+ convert_to_text,
18
+ )
19
+ from .markdown import (
20
+ markdown_blockquote,
21
+ markdown_bold,
22
+ markdown_code,
23
+ markdown_code_block,
24
+ markdown_heading,
25
+ markdown_horizontal_rule,
26
+ markdown_italic,
27
+ markdown_link,
28
+ markdown_list_item,
29
+ markdown_table,
30
+ markdown_table_row,
31
+ )
32
+
33
+
34
+ __all__ = (
35
+ # hammad.text.converters
36
+ "convert_collection_to_text",
37
+ "convert_dataclass_to_text",
38
+ "convert_dict_to_text",
39
+ "convert_docstring_to_text",
40
+ "convert_function_to_text",
41
+ "convert_pydantic_to_text",
42
+ "convert_type_to_text",
43
+ "convert_to_text",
44
+ # hammad.text.markdown
45
+ "markdown_blockquote",
46
+ "markdown_bold",
47
+ "markdown_code",
48
+ "markdown_code_block",
49
+ "markdown_heading",
50
+ "markdown_horizontal_rule",
51
+ "markdown_italic",
52
+ "markdown_link",
53
+ "markdown_list_item",
54
+ "markdown_table",
55
+ "markdown_table_row",
56
+ )
57
+
58
+
59
+ __getattr__ = create_getattr_importer(__all__)
60
+
61
+
62
+ def __dir__() -> list[str]:
63
+ return list(__all__)