Skip to content

py: make plugin internals private with underscore-prefixed modules #215

Open

Description

@huangjeff5

Problem

Python plugins treat __all__ in __init__.py as their public surface, but most ship internal code in modules without a leading underscore. Every plugin ships py.typed, so by the typing spec's library-interface rules those names are public. Pyright and Pylance accept the import without warning, and IDE auto-import offers it.

# Not in genkit_google_genai.__all__, but public by the spec and offered by auto-import
from genkit_google_genai.models.gemini import KnownGemini, GeminiModel, SUPPORTED_MODELS

This came up on genkit-ai/genkit#6506. Removing the model-id enums from genkit_google_genai.__all__ left them importable from genkit_google_genai.models.gemini, so dropping a root export didn't make anything internal. genkit-ai/genkit#6506 deleted the enums outright, but the Known* Literals have to stay because the gemini_model(name: KnownGemini | str) signatures need them. They're still reachable through models.*.

Mechanism

Core genkit already follows the convention: internals live in genkit._core and genkit._ai, and genkit-ai/genkit#6508 adds a ruff rule that blocks other packages from importing them. genkit-a2ui, genkit-middleware, and genkit-otel already keep every internal module underscored. The rest don't:

  • genkit-google-genai: constants.py, evaluators/, google.py, models/
  • genkit-openai: models/, openai_plugin.py, typing.py
  • genkit-anthropic: config.py, model_info.py, models.py, plugin.py, utils.py
  • genkit-amazon-bedrock: config.py, converters.py, embedders.py, image.py, model_info.py, models.py, plugin.py, rerank.py, stream.py, transport.py
  • genkit-ollama: constants.py, embedders.py, models.py, plugin_api.py
  • genkit-vertexai: constants.py, model_garden/
  • genkit-evaluators: plugin.py
  • genkit-django / fastapi / flask: handler.py
  • genkit-google-cloud: exp/, session_store/, telemetry/. These may be intentional public subpackages; decide per subpackage.

Proposal

  1. Underscore-prefix internal modules in each plugin (e.g. genkit_google_genai/models/ → _models/), so __all__ is the whole public surface.
  2. Before renaming, re-export from the package root anything users legitimately reach through a submodule today. Grep samples, docsite, and skills for from genkit_<plugin>.<module> import.
  3. Extend the chore(py): plugins and samples import genkit only through public modules genkit#6508 ruff rule so samples and other packages can't import genkit_<plugin>._*.
  4. Land one PR per plugin. Each is breaking only for direct submodule imports.

Open questions

  • Is genkit-google-cloud's exp/, session_store/, and telemetry/ meant to be public? If so, those stay and get their own __all__.
  • Should genkit_ollama.plugin_api be public? Its name suggests it was meant to be.

Activity

  1. MichaelDoyle commented on Nov 18, 2026

    @MichaelDoyle
    Contributor

    It looks like plugin internals across py/packages/genkit-*/src/*/ have now been made private with underscore-prefixed modules (via PRs genkit-ai/genkit#6506, genkit-ai/genkit#6586, genkit-ai/genkit#6710, etc.). Is this ready to close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions