Skip to content

refactor(py)!: plugin packages expose only their top-level module - #6671

Merged
huangjeff5 merged 7 commits into
mainfrom
chore/py-plugin-layout
Oct 10, 2026
Merged

huangjeff5 merged 7 commits into
mainfrom
chore/py-plugin-layout

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Plugin packages now expose only their package root (plus exp where a plugin has experimental pieces). Imports from the root keep working unchanged:

from genkit_amazon_bedrock import Bedrock
from genkit_ollama import Ollama
from genkit_flask import genkit_flask_handler
from genkit_vertexai import ModelGarden
from genkit_google_cloud import enable_google_cloud_telemetry
from genkit_google_cloud.exp import FirestoreSessionStore
from genkit_fastapi.exp import serve_agent

Importing a submodule path now raises ModuleNotFoundError:

  • genkit_amazon_bedrock.{config, converters, embedders, image, model_info, models, plugin, rerank, stream, transport}
  • genkit_ollama.{constants, embedders, models, plugin_api}
  • genkit_flask.handler, genkit_django.handler, genkit_fastapi.handler
  • genkit_evaluators.plugin
  • genkit_google_cloud.telemetry, genkit_google_cloud.session_store
  • genkit_vertexai.model_garden, genkit_vertexai.constants
# before
from genkit_vertexai.model_garden import ModelGarden
from genkit_ollama.models import OllamaConfig

# after
from genkit_vertexai import ModelGarden
from genkit_ollama import OllamaConfig

Decisions

  • Everything you need is on the package root (and exp for experimental pieces), so a submodule import was never needed. Moving the internals behind the root lets them change without breaking your app.
  • Private subpackages have no __init__.py: genkit_vertexai._model_garden, genkit_openai._models, genkit_google_genai._models (and _context_caching), genkit_google_genai._evaluators, genkit_google_cloud._telemetry, and core's genkit._ai._formats. An __init__.py re-export made an internal package look like an API. Imports go to the defining module, e.g. genkit._ai._formats._builtin.built_in_formats. Wheels still ship the modules.
  • Logger names follow module paths. A log filter on genkit_fastapi.handler or genkit_google_cloud.telemetry.* now needs genkit_fastapi._handler / genkit_google_cloud._telemetry.*. Better: filter on the package prefix, e.g. genkit_fastapi.

Layout only; no behavior changes. The Bedrock and Ollama surface changes that used to ride along are split out into the PRs stacked on top.

@github-actions github-actions Bot added docs Improvements or additions to documentation python Python config chore labels Oct 8, 2026
@huangjeff5
huangjeff5 added this pull request to stack #6670 October 8, 2026 06:50

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request performs a comprehensive refactoring across multiple Genkit Python packages (including genkit-amazon-bedrock, genkit-django, genkit-evaluators, genkit-fastapi, genkit-flask, genkit-google-cloud, genkit-ollama, and genkit-vertexai) to mark internal modules as private by prefixing their filenames and imports with an underscore (_). It also updates all corresponding references in source code, tests, and configuration files (such as pyproject.toml), and simplifies public imports in documentation (e.g., importing ModelGarden directly from genkit_vertexai). I have no feedback to provide as there are no review comments.

@huangjeff5
huangjeff5 force-pushed the chore/py-plugin-layout branch from 3a11d40 to 8c2891c Compare October 8, 2026 22:04
@huangjeff5
huangjeff5 removed this pull request from stack #6670 October 9, 2026 01:23
@huangjeff5
huangjeff5 force-pushed the chore/py-plugin-layout branch from c496460 to c764a9b Compare October 9, 2026 02:52
@huangjeff5
huangjeff5 changed the base branch from chore/py-export-cut to chore/py-surface-trim October 9, 2026 02:52
@huangjeff5
huangjeff5 added this pull request to stack #6705 October 9, 2026 02:52
@huangjeff5
huangjeff5 force-pushed the chore/py-plugin-layout branch from c764a9b to 542d5a9 Compare October 9, 2026 02:54
@huangjeff5
huangjeff5 force-pushed the chore/py-plugin-layout branch from 542d5a9 to 14df3f6 Compare October 9, 2026 02:56
@huangjeff5
huangjeff5 force-pushed the chore/py-plugin-layout branch from 14df3f6 to ec39a5e Compare October 9, 2026 03:47
@huangjeff5
huangjeff5 requested a review from apascal07 October 9, 2026 03:57
@huangjeff5
huangjeff5 force-pushed the chore/py-plugin-layout branch 5 times, most recently from aa22719 to d0ec735 Compare October 9, 2026 06:32
built_in_formats moves to _formats/_builtin.py; imports point at defining modules.
@huangjeff5
huangjeff5 force-pushed the chore/py-plugin-layout branch from dbde3f7 to 8070dd8 Compare October 9, 2026 06:52
# Conflicts:
#	py/packages/genkit-google-cloud/src/genkit_google_cloud/telemetry/__init__.py
#	py/packages/genkit-vertexai/tests/model_garden/anthropic_generate_test.py
#	py/packages/genkit-vertexai/tests/model_garden/client_test.py
#	py/packages/genkit-vertexai/tests/model_garden/model_garden_test.py

@apascal07 apascal07 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

py/pyproject.toml lines 483-487 turn off ty unresolved-import for all of packages/genkit-vertexai/** because of the model_garden relative imports this PR removes; ty check . passes at this head without it, and leaving it lets a broken vertexai import through. Line 252 ignores F401 for packages/genkit/src/genkit/_ai/__init__.py, which does not exist.

@huangjeff5

Copy link
Copy Markdown
Contributor Author

@apascal07 dropped both pyproject overrides in 1c5a2b1: the vertexai ty unresolved-import override and the stale _ai/__init__.py F401 entry. ty check . is still clean.

# Conflicts:
#	py/packages/genkit-amazon-bedrock/src/genkit_amazon_bedrock/__init__.py
#	py/packages/genkit-amazon-bedrock/tests/plugin_test.py
#	py/packages/genkit-ollama/tests/plugin_api_test.py
@huangjeff5
huangjeff5 merged commit ed40ffb into main Oct 10, 2026
26 checks passed
@huangjeff5
huangjeff5 deleted the chore/py-plugin-layout branch October 10, 2026 01:05
cabljac added a commit that referenced this pull request Oct 12, 2026
…lic surface

The Python plugins on main export only what a caller needs and take
flat keyword arguments instead of nested option objects (#6671, #6706).
The client now does the same.

define_mcp_client and McpClient take command, args, env and cwd as
keyword arguments and build the stdio config internally. The provider
name is also the tool name prefix, as in the Go plugin, so tool_prefix
and the tool_prefix property go away, and the name has to satisfy the
tool name rule as well as the selector rule. disabled goes away: not
calling define_mcp_client does the same.

create_mcp_client goes away. An unregistered client has no use on its
own while generate(tools=) takes names rather than actions, and McpClient
is still there for the host to build clients without registering each.
dynamic_action_provider becomes private: no caller outside the package
needs it.

The package exports McpClient and define_mcp_client. Errors are
GenkitError with a status, as for the other plugins after #6710, so the
error classes are no longer exported. A test pins the exported names,
replacing the smoke test main deleted.
cabljac added a commit that referenced this pull request Oct 12, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
cabljac added a commit that referenced this pull request Oct 13, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
hilariie pushed a commit that referenced this pull request Oct 16, 2026
…lic surface

The Python plugins on main export only what a caller needs and take
flat keyword arguments instead of nested option objects (#6671, #6706).
The client now does the same.

define_mcp_client and McpClient take command, args, env and cwd as
keyword arguments and build the stdio config internally. The provider
name is also the tool name prefix, as in the Go plugin, so tool_prefix
and the tool_prefix property go away, and the name has to satisfy the
tool name rule as well as the selector rule. disabled goes away: not
calling define_mcp_client does the same.

create_mcp_client goes away. An unregistered client has no use on its
own while generate(tools=) takes names rather than actions, and McpClient
is still there for the host to build clients without registering each.
dynamic_action_provider becomes private: no caller outside the package
needs it.

The package exports McpClient and define_mcp_client. Errors are
GenkitError with a status, as for the other plugins after #6710, so the
error classes are no longer exported. A test pins the exported names,
replacing the smoke test main deleted.
cabljac added a commit that referenced this pull request Oct 19, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
cabljac added a commit that referenced this pull request Oct 19, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
cabljac added a commit that referenced this pull request Oct 19, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
cabljac added a commit that referenced this pull request Oct 20, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
cabljac added a commit that referenced this pull request Oct 22, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
cabljac added a commit that referenced this pull request Oct 22, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
hilariie pushed a commit that referenced this pull request Oct 29, 2026
…lic surface

The Python plugins on main export only what a caller needs and take
flat keyword arguments instead of nested option objects (#6671, #6706).
The client now does the same.

define_mcp_client and McpClient take command, args, env and cwd as
keyword arguments and build the stdio config internally. The provider
name is also the tool name prefix, as in the Go plugin, so tool_prefix
and the tool_prefix property go away, and the name has to satisfy the
tool name rule as well as the selector rule. disabled goes away: not
calling define_mcp_client does the same.

create_mcp_client goes away. An unregistered client has no use on its
own while generate(tools=) takes names rather than actions, and McpClient
is still there for the host to build clients without registering each.
dynamic_action_provider becomes private: no caller outside the package
needs it.

The package exports McpClient and define_mcp_client. Errors are
GenkitError with a status, as for the other plugins after #6710, so the
error classes are no longer exported. A test pins the exported names,
replacing the smoke test main deleted.
hilariie pushed a commit that referenced this pull request Oct 29, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
hilariie pushed a commit that referenced this pull request Oct 30, 2026
…ping

The host follows the same surface rules as the client: no exported
nested config, flat keyword arguments, and only names a caller needs
(#6671, #6706).

define_mcp_host and McpHost take mcp_servers=, a mapping in the shape of
the mcpServers block Claude Desktop and Cursor read, so a block loaded
from one of those files passes straight through. Each entry is validated
into the internal stdio config, so a misspelt key still fails without
echoing values. connect takes command, args, env and cwd as keyword
arguments, as define_mcp_client does.

The mapping key is the server name and its tool name prefix, as in the
Go plugin. Keys are unique, so the shared-prefix check and tool_prefix
go away. McpHostServer and create_mcp_host go away, server_names goes
(tests read the host's clients), and dynamic_action_provider becomes
private.

The package now exports McpClient, McpHost, define_mcp_client and
define_mcp_host, which the exports test pins.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore config docs Improvements or additions to documentation python Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants