hammad-python 0.0.21__py3-none-any.whl → 0.0.23__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.
hammad/__init__.py CHANGED
@@ -6,45 +6,29 @@ from typing import TYPE_CHECKING
6
6
  from ._internal import create_getattr_importer as __hammad_importer__
7
7
 
8
8
  if TYPE_CHECKING:
9
- # hammad.cache
10
- from .cache import cached, Cache
11
-
12
- # hammad.cli
13
- from .cli import print, animate, input
14
-
15
- # hammad.formatting
16
- from .formatting.json import convert_to_json_schema
17
- from .formatting.text import convert_to_text, convert_type_to_text
18
-
19
- # hammad.logging
20
- from .logging.logger import Logger, create_logger
21
- from .logging.decorators import trace, trace_cls, trace_function, trace_http
22
-
23
-
24
- __all__ = [
25
- # hammad.cache
26
- "cached",
27
- "Cache",
28
- # hammad.cli
9
+ from ._main._fn import fn
10
+ from ._main._new import new
11
+ from ._main._run import run
12
+ from ._main._to import to
13
+ from .cli import print, input, animate
14
+
15
+
16
+ __all__ = (
17
+ # top level namespace modules for
18
+ # super duper fast access to things and stuff
19
+ "run",
20
+ "new",
21
+ "to",
22
+ "fn",
23
+ # cli
29
24
  "print",
30
- "animate",
31
25
  "input",
32
- # hammad.formatting
33
- "convert_to_json_schema",
34
- "convert_to_text",
35
- "convert_type_to_text",
36
- # hammad.logging
37
- "Logger",
38
- "create_logger",
39
- "trace",
40
- "trace_cls",
41
- "trace_function",
42
- "trace_http",
43
- ]
26
+ "animate",
27
+ )
44
28
 
45
29
 
46
30
  __getattr__ = __hammad_importer__(__all__)
47
31
 
48
32
 
49
33
  def __dir__() -> list[str]:
50
- return __all__
34
+ return list(__all__)
hammad/_internal.py CHANGED
@@ -108,7 +108,25 @@ def _parse_type_checking_imports(source_code: str) -> dict[str, tuple[str, str]]
108
108
  # Process imports in this block
109
109
  for stmt in node.body:
110
110
  if isinstance(stmt, ast.ImportFrom) and stmt.module:
111
- module_path = f".{stmt.module}"
111
+ # Only add '.' prefix for relative imports
112
+ # If stmt.level > 0, it's already a relative import
113
+ # If stmt.level == 0 and module doesn't start with '.', it's absolute
114
+ if stmt.level > 0:
115
+ # Already relative import
116
+ module_path = "." * stmt.level + (stmt.module or "")
117
+ elif stmt.module.startswith("."):
118
+ # Explicit relative import
119
+ module_path = stmt.module
120
+ elif any(
121
+ stmt.module.startswith(name)
122
+ for name in ["litellm", "openai", "instructor", "httpx"]
123
+ ):
124
+ # Known absolute third-party imports
125
+ module_path = stmt.module
126
+ else:
127
+ # Default to relative import for internal modules
128
+ module_path = f".{stmt.module}"
129
+
112
130
  for alias in stmt.names:
113
131
  original_name = alias.name
114
132
  local_name = alias.asname or original_name
@@ -0,0 +1,4 @@
1
+ """hammad._main
2
+
3
+ Main entrypoint for the `hammad` package.
4
+ """
hammad/_main/_fn.py ADDED
@@ -0,0 +1,20 @@
1
+ """hammad._fn
2
+
3
+ Namespace resource for **DECORATORS** used at the top level
4
+ of the `hammad` package."""
5
+
6
+
7
+ class fn:
8
+ """Top level namespace resource for decorators. This can
9
+ be used as `@hammad.fn.cached`, hammad.fn...`. All functions within
10
+ this module are decorators."""
11
+
12
+ from ..cache import cached, auto_cached
13
+ from ..genai import define_tool
14
+ from ..logging import trace, trace_cls, trace_function, trace_http
15
+ from ..service import (
16
+ serve,
17
+ )
18
+
19
+
20
+ __all__ = "fn"
hammad/_main/_new.py ADDED
@@ -0,0 +1,52 @@
1
+ """hammad._new
2
+
3
+ Main entrypoint for the `new` resource.
4
+ """
5
+
6
+
7
+ class new:
8
+ """Global factory resource for creating various objects available
9
+ throughout the package. You can find most things in here."""
10
+
11
+ from ..cache import create_cache as cache
12
+ from ..data.configurations import (
13
+ read_configuration_from_dotenv as configuration_from_dotenv,
14
+ read_configuration_from_file as configuration_from_file,
15
+ read_configuration_from_url as configuration_from_url,
16
+ read_configuration_from_os_vars as configuration_from_os_vars,
17
+ read_configuration_from_os_prefix as configuration_from_os_prefix,
18
+ )
19
+ from ..data.collections import (
20
+ create_collection as collection,
21
+ )
22
+ from ..data.sql import (
23
+ create_database as database,
24
+ )
25
+ from ..data.types import Text as text, Audio as audio, Image as image, File as file
26
+ from ..genai import (
27
+ create_embedding_model as embedding_model,
28
+ create_language_model as language_model,
29
+ create_agent as agent,
30
+ )
31
+ from ..logging import create_logger as logger
32
+ from ..mcp import (
33
+ MCPClient as mcp_client,
34
+ MCPServerSseSettings as mcp_server_sse_settings,
35
+ MCPClientSseSettings as mcp_client_sse_settings,
36
+ MCPClientStreamableHttpSettings as mcp_client_http_settings,
37
+ MCPServerStreamableHttpSettings as mcp_server_streamable_http_settings,
38
+ MCPServerStdioSettings as mcp_server_stdio_settings,
39
+ MCPClientStdioSettings as mcp_client_stdio_settings,
40
+ )
41
+ from ..service import (
42
+ create_service as service,
43
+ async_create_service as async_service,
44
+ )
45
+ from ..web import (
46
+ create_http_client as http_client,
47
+ create_openapi_client as openapi_client,
48
+ create_search_client as search_client,
49
+ )
50
+
51
+
52
+ __all__ = "new"
hammad/_main/_run.py ADDED
@@ -0,0 +1,50 @@
1
+ """hammad._run
2
+
3
+ Main entrypoint for the `run` command and resource at the
4
+ top level of the hammad package.
5
+ """
6
+
7
+
8
+ class run:
9
+ """Top level namespace resource for running various things and stuff."""
10
+
11
+ from ..genai import (
12
+ # agents
13
+ run_agent as agent,
14
+ run_agent_iter as agent_iter,
15
+ async_run_agent as async_agent,
16
+ async_run_agent_iter as async_agent_iter,
17
+ # models
18
+ run_embedding_model as embedding_model,
19
+ async_run_embedding_model as async_embedding_model,
20
+ run_language_model as language_model,
21
+ async_run_language_model as async_language_model,
22
+ run_image_edit_model as image_edit_model,
23
+ async_run_image_edit_model as async_image_edit_model,
24
+ run_image_generation_model as image_generation_model,
25
+ async_run_image_generation_model as async_image_generation_model,
26
+ run_image_variation_model as image_variation_model,
27
+ async_run_image_variation_model as async_image_variation_model,
28
+ run_reranking_model as reranking_model,
29
+ async_run_reranking_model as async_reranking_model,
30
+ run_transcription_model as transcription_model,
31
+ async_run_transcription_model as async_transcription_model,
32
+ run_tts_model as tts_model,
33
+ async_run_tts_model as async_tts_model,
34
+ )
35
+ from ..mcp import launch_mcp_servers as mcp_servers
36
+ from ..runtime import (
37
+ run_parallel as parallel,
38
+ run_sequentially as sequentially,
39
+ run_with_retry as with_retry,
40
+ )
41
+ from ..web import (
42
+ read_web_page as web_reader,
43
+ read_web_pages as web_reader_batch,
44
+ run_web_search as web_search,
45
+ run_news_search as news_search,
46
+ run_web_request as web_request,
47
+ )
48
+
49
+
50
+ __all__ = ["run"]
hammad/_main/_to.py ADDED
@@ -0,0 +1,19 @@
1
+ """hammad._to
2
+
3
+ Top level namspace resource for converters."""
4
+
5
+
6
+ class to:
7
+ """Converter resource"""
8
+
9
+ from ..data import (
10
+ convert_to_pydantic_field as pydantic_field,
11
+ convert_to_pydantic_model as pydantic_model,
12
+ )
13
+ from ..formatting.json import (
14
+ convert_to_json_schema as json_schema,
15
+ )
16
+ from ..formatting.text import convert_to_text as text
17
+
18
+
19
+ __all__ = "to"
hammad/data/__init__.py CHANGED
@@ -21,6 +21,7 @@ if TYPE_CHECKING:
21
21
  )
22
22
  from .collections import (
23
23
  Collection,
24
+ create_collection,
24
25
  TantivyCollectionIndex,
25
26
  QdrantCollectionIndex,
26
27
  TantivyCollectionIndexSettings,
@@ -54,8 +55,12 @@ __all__ = (
54
55
  "validator",
55
56
  "is_field",
56
57
  "is_model",
58
+ "convert_to_pydantic_model",
59
+ "convert_to_pydantic_field",
60
+ "is_pydantic_model_class",
57
61
  # hammad.data.collections
58
62
  "Collection",
63
+ "create_collection",
59
64
  "TantivyCollectionIndex",
60
65
  "QdrantCollectionIndex",
61
66
  "TantivyCollectionIndexSettings",
@@ -68,6 +73,11 @@ __all__ = (
68
73
  "Database",
69
74
  # hammad.data.configurations
70
75
  "Configuration",
76
+ "read_configuration_from_file",
77
+ "read_configuration_from_url",
78
+ "read_configuration_from_os_vars",
79
+ "read_configuration_from_os_prefix",
80
+ "read_configuration_from_dotenv",
71
81
  )
72
82
 
73
83
 
@@ -4,7 +4,10 @@ from typing import TYPE_CHECKING
4
4
  from ..._internal import create_getattr_importer
5
5
 
6
6
  if TYPE_CHECKING:
7
- from .collection import Collection
7
+ from .collection import (
8
+ Collection,
9
+ create_collection,
10
+ )
8
11
 
9
12
  from .indexes import (
10
13
  TantivyCollectionIndex,
@@ -25,6 +28,7 @@ if TYPE_CHECKING:
25
28
  __all__ = (
26
29
  # hammad.data.collections.collection
27
30
  "Collection",
31
+ "create_collection",
28
32
  # hammad.data.collections.indexes
29
33
  "TantivyCollectionIndex",
30
34
  "QdrantCollectionIndex",
@@ -5,13 +5,14 @@ from ..._internal import create_getattr_importer
5
5
 
6
6
  if TYPE_CHECKING:
7
7
  from .types import DatabaseItemType, DatabaseItem
8
- from .database import Database
8
+ from .database import Database, create_database
9
9
 
10
10
 
11
11
  __all__ = (
12
12
  "DatabaseItemType",
13
13
  "DatabaseItem",
14
14
  "Database",
15
+ "create_database",
15
16
  )
16
17
 
17
18
 
hammad/genai/__init__.py CHANGED
@@ -13,6 +13,7 @@ if TYPE_CHECKING:
13
13
  AgentContext,
14
14
  AgentMessages,
15
15
  AgentResponseChunk,
16
+ create_agent,
16
17
  )
17
18
  from .agents.run import (
18
19
  run_agent,
@@ -27,6 +28,7 @@ if TYPE_CHECKING:
27
28
  EmbeddingModelSettings,
28
29
  run_embedding_model,
29
30
  async_run_embedding_model,
31
+ create_embedding_model,
30
32
  )
31
33
  from .models.language import (
32
34
  LanguageModel,
@@ -40,6 +42,7 @@ if TYPE_CHECKING:
40
42
  LanguageModelStream,
41
43
  run_language_model,
42
44
  async_run_language_model,
45
+ create_language_model,
43
46
  )
44
47
  from .models.reranking import run_reranking_model, async_run_reranking_model
45
48
  from .models.multimodal import (
@@ -78,6 +81,7 @@ __all__ = [
78
81
  "AgentContext",
79
82
  "AgentMessages",
80
83
  "AgentResponseChunk",
84
+ "create_agent",
81
85
  # hammad.genai.agents.run
82
86
  "run_agent",
83
87
  "run_agent_iter",
@@ -90,6 +94,7 @@ __all__ = [
90
94
  "EmbeddingModelSettings",
91
95
  "run_embedding_model",
92
96
  "async_run_embedding_model",
97
+ "create_embedding_model",
93
98
  # hammad.genai.models.language
94
99
  "LanguageModel",
95
100
  "LanguageModelInstructorMode",
@@ -102,6 +107,7 @@ __all__ = [
102
107
  "LanguageModelStream",
103
108
  "run_language_model",
104
109
  "async_run_language_model",
110
+ "create_language_model",
105
111
  # hammad.genai.models.reranking
106
112
  "run_reranking_model",
107
113
  "async_run_reranking_model",
@@ -5,7 +5,10 @@ from ..._internal import create_getattr_importer
5
5
 
6
6
 
7
7
  if TYPE_CHECKING:
8
- from .agent import Agent
8
+ from .agent import (
9
+ Agent,
10
+ create_agent,
11
+ )
9
12
 
10
13
  # Types
11
14
  from .types.agent_context import AgentContext
@@ -22,6 +25,7 @@ if TYPE_CHECKING:
22
25
  __all__ = [
23
26
  # hammad.genai.agents.agent
24
27
  "Agent",
28
+ "create_agent",
25
29
  # hammad.genai.agents.types.agent_context
26
30
  "AgentContext",
27
31
  # hammad.genai.agents.types.agent_event