Skip to content

refactor(py): migrate plugins, update samples and add tombstone publisher#5644

Open
huangjeff5 wants to merge 46 commits into
reorg/py-core-onlyfrom
reorg/py-plugins
Open

refactor(py): migrate plugins, update samples and add tombstone publisher#5644
huangjeff5 wants to merge 46 commits into
reorg/py-core-onlyfrom
reorg/py-plugins

Conversation

@huangjeff5

@huangjeff5 huangjeff5 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Description

This PR migrates all 11 Genkit integration/plugin packages from py/plugins/* to flat packages under py/packages/genkit-*, updates imports across all tests and samples, and introduces the PyPI tombstone publishing mechanism.

This PR is stacked on top of PR 1 (#5643) and completes the Python SDK package reorganization.

There were some small fixes I made along the way too:

  • Google GenAI plugin was running blocking sync functions on the main event loop, now we move those to background threads
  • ModelGarden plugin specifies Anthropic plugin as explicit dependency now (to import the Anthropic types that the plugin already referenced).

Product Reasoning

This PR carries out the renaming and flat imports migration for the model provider integrations and framework integrations:

  1. Renaming for Semantic Accuracy: Integrations are renamed from genkit-plugin-<name> to genkit-<name> (e.g. genkit-googlecloud, genkit-django). This accurately represents that these packages are framework extensions and infrastructure adapters, rather than traditional "plugins" that extend the SDK core.
  2. Predictable Flat Imports: Imports are updated from nested namespaces (genkit.plugins.<name>) to flat, distinct top-level packages (e.g. from genkit_googleai import GoogleAI, from genkit_vertexai import VertexAI). This solves VS Code/Pyright import resolution bugs, improves developer experience, and aligns with standard Python conventions.
  3. Clean Monorepo & Zero Legacy Shim Clutter: Rather than checking 11 legacy shim folders and duplicate package metadata files into the main branch to handle backward compatibility (which would clutter the monorepo forever), we use a "One-Time Publish & Forget" Scripted Strategy. Legacies are dynamically generated and packaged at release time on a temporary release branch, leaving our codebase 100% clean.

Public Migration Plan

To ensure a smooth transition for existing Genkit Python consumers, the v0.8.0 release introduces a structured deprecation and migration path.

1. Package Dependency Updates (requirements.txt / pyproject.toml)

Legacy distribution names (genkit-plugin-*) are replaced with flat, top-level distribution packages (genkit-*):

Legacy Package (<=0.7.x) New Package (>=0.8.0)
genkit-plugin-anthropic genkit-anthropic
genkit-plugin-compat-oai genkit-openai
genkit-plugin-google-genai genkit-googleai
genkit-plugin-google-cloud genkit-googlecloud
genkit-plugin-middleware genkit-middleware
genkit-plugin-ollama genkit-ollama
genkit-plugin-vertex-ai genkit-vertexai
genkit-plugin-django genkit-django
genkit-plugin-fastapi genkit-fastapi
genkit-plugin-flask genkit-flask
genkit-plugin-evaluators genkit-evaluators

2. Python Import Updates

Nested namespace imports (genkit.plugins.<provider>) transition to top-level module namespaces (genkit_<provider>):

# Anthropic
from genkit_anthropic import Anthropic

# Google GenAI / Gemini API
from genkit_googleai import GoogleAI

# Google Cloud Vertex AI
from genkit_googleai import VertexAI

# Google Cloud Telemetry/Logging
from genkit_googlecloud import enable_googlecloud_telemetry
# NOTE: method was renamed from `enable_gcp_telemetry`

# OpenAI Compatible
from genkit_openai import OpenAI

# Ollama
from genkit_ollama import Ollama

# Middleware
from genkit_middleware import Middleware, Retry, Skills

# Web Framework Integrations
from genkit_fastapi import genkit_fastapi_handler
from genkit_flask import genkit_flask_handler

3. Core SDK Parity (genkit)

No changes are required for core SDK imports (from genkit import Genkit, ai, core). Core exports and API boundaries remain unchanged.

4. End-User Upgrade Experience & Fail-Fast Safety Net

When existing applications upgrade to v0.8.0, their experience depends on how their package dependencies are managed:

  • Most Likely Scenario (Unpinned / Loose Requirements + Explicit Upgrade): For projects specifying unpinned dependencies (genkit-plugin-google-genai>=0.7.0) that run uv lock --upgrade or automated CI/CD builds without checked-in lockfiles, package managers resolve the legacy package to version 0.8.0 (our published tombstone shim). The tombstone automatically installs the replacement flat package (genkit-googleai). At app startup or unit test collection (pytest), the legacy import statement (from genkit.plugins.google_genai import GoogleAI) immediately halts execution with an actionable error:
    ImportError: The 'genkit-plugin-google-genai' package has been renamed to 'genkit-googleai'. Please update your requirements to 'genkit-googleai' and your imports to 'import genkit_googleai'.
    
    In automated CI/CD pipelines (GitHub Actions, Cloud Build, Vercel), the build exits immediately with code 1, triggering a build failure notification containing exact remediation instructions before broken code reaches production.
  • Pinned Lockfiles (uv.lock / poetry.lock): Existing applications deployed with locked dependency graphs remain pinned to 0.7.x and experience zero impact or disruption until explicitly upgraded.

Key Changes in PR 2

  • Plugin Relocation and Renaming: Moved all 11 packages from py/plugins/<name> to py/packages/genkit-<name>, renaming target Python modules (e.g. genkit_googleai, genkit_vertexai, genkit_googlecloud).
  • Workspace-wide Import Alignment: Updated all imports across core, plugins, tests, and samples to import from flat top-level packages.
  • Tombstone Generation Script: Added py/scripts/publish_tombstones.py which dynamically builds and publishes deprecated package shims to PyPI.
  • Workspace Dependency Lock: Updated py/pyproject.toml workspace members and generated a deterministic uv.lock reflecting the clean, flat distribution layout.
  • Smoke Tests Updated: Aligned package structure smoke tests to verify renamed imports and package metadata outputs.

@huangjeff5 huangjeff5 requested a review from a team as a code owner June 27, 2026 17:36
@github-actions github-actions Bot added docs Improvements or additions to documentation python Python config root labels Jun 27, 2026

@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 introduces several new packages and integrations, including plugins for Anthropic, Django, FastAPI, Flask, Google Cloud, and rule-based evaluators, alongside updating script paths in captainhook.json and justfile. The review feedback highlights critical issues where synchronous blocking calls (such as _list_genai_models) are executed inside async methods, which can freeze the asyncio event loop. Additionally, the blocking op.result() call in VeoModel should be awaited, and Server-Sent Events (SSE) error messages in the Flask, Django, and FastAPI handlers must be terminated with a double newline (\n\n) to prevent client hangs. Finally, several pyproject.toml files contain outdated Changelog URLs, and a log message in gcp_logger.py references an incorrect function name.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread py/packages/genkit-flask/src/genkit_flask/handler.py Outdated
Comment thread py/packages/genkit-googleai/src/genkit_googleai/models/veo.py Outdated
Comment thread py/packages/genkit-googleai/src/genkit_googleai/google.py
Comment thread py/packages/genkit-googleai/src/genkit_googleai/google.py Outdated
Comment thread py/packages/genkit-googleai/src/genkit_googleai/google.py
Comment thread py/packages/genkit-googleai/pyproject.toml Outdated
Comment thread py/packages/genkit-google-cloud/pyproject.toml Outdated
Comment thread py/packages/genkit-anthropic/pyproject.toml Outdated
Comment thread py/packages/genkit-fastapi/pyproject.toml
Comment thread py/packages/genkit-django/pyproject.toml Outdated
@huangjeff5 huangjeff5 changed the title reorg(py): migrate plugins, update samples and add tombstone publisher refactor(py): migrate plugins, update samples and add tombstone publisher Jun 27, 2026
@huangjeff5

Copy link
Copy Markdown
Contributor Author

I have successfully addressed all of Gemini Code Assist's review feedback and the renaming consistency request for PR 2:

  1. Synchronous Blocking Call (_list_genai_models) inside Async Methods: Wrapped the dynamic discovery model listing queries with await asyncio.to_thread(_list_genai_models, ...) in all plugin init and list_actions async methods, avoiding event loop blocks.
  2. Blocking op.result() in VeoModel: Directly awaited the async op.result() method in veo.py instead of invoking it synchronously.
  3. SSE Double-Newline Termination: Appended the protocol-required \n\n double newlines to all server-sent event (SSE) error yields inside FastAPI, Flask, and Django handlers to prevent client-side hanging.
  4. Outdated Changelog URLs: Updated all package metadata links in pyproject.toml files to point to the new py/packages/genkit-* directories instead of the old py/plugins/ paths.
  5. gcp_logger.py Warning References: Corrected the log output and warning hints in gcp_logger.py to reference add_gcp_telemetry() and gcp_logger.initialize() instead of old/incorrect function names.
  6. Rename genkit_vertex_ai to genkit_vertexai: Renamed the Vertex AI package import module name to genkit_vertexai (renaming the directory in src/ and updating all internal and smoke test references) to ensure consistency with genkit_googleai.

All GHA checks and formatting checks for PR 2 are passing and green!

@huangjeff5

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@huangjeff5

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 reorganizes the Genkit Python SDK by renaming the plugin packages from genkit-plugin-* to genkit-* and updating all internal imports, dependencies, tests, and samples accordingly. It also introduces a script to publish deprecated tombstone packages to PyPI to facilitate migration. The review feedback highlights a potential runtime TypeError in veo.py when directly awaiting a non-awaitable result, a robustness issue in the tombstone publisher script when locating newly built wheel files, and a recommendation to allow exceptions to propagate naturally in the publishing script to preserve tracebacks for debugging.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread py/packages/genkit-googleai/src/genkit_googleai/models/veo.py
Comment thread py/scripts/publish_tombstones.py Outdated
Comment thread py/scripts/publish_tombstones.py Outdated

@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 reorganizes the Genkit Python SDK by renaming the plugin packages (e.g., removing the "genkit-plugin-" prefix) and moving them from the "plugins/" directory to "packages/". It also introduces a script to publish deprecated tombstone packages to PyPI. The review feedback highlights a critical runtime error in the "veo.py" model where a synchronous blocking call "op.result()" is incorrectly awaited, recommending the use of "asyncio.to_thread" instead. Additionally, the feedback suggests improving error handling in the tombstone publishing script by letting exceptions propagate rather than catching them silently.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread py/packages/genkit-googleai/src/genkit_googleai/models/veo.py
Comment thread py/scripts/publish_tombstones.py Outdated
…ync and async LRO results non-blockingly in veo.py and make tombstone script wheel building robust
@huangjeff5

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@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 reorganizes the Genkit Python SDK by renaming and moving plugin packages from genkit-plugin-* to simpler names like genkit-anthropic and genkit-googleai, updating all imports, configurations, and samples accordingly. It also adds a script to generate deprecated tombstone packages to assist with user migration. Feedback on these changes highlights redundant pass blocks in the tombstone script, a potential pre-commit hook failure due to the removal of tox dependencies, and a packaging issue where the regular core genkit package might prevent the tombstone packages from raising the intended custom ImportError.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread py/scripts/publish_tombstones.py Outdated
Comment thread py/scripts/publish_tombstones.py Outdated
Comment thread captainhook.json Outdated
Comment thread py/scripts/publish_tombstones.py Outdated
@huangjeff5

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@huangjeff5

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 reorganizes the Genkit Python SDK by renaming the genkit-plugin-* packages to genkit-* and updating all internal import paths, tests, and samples accordingly. It also removes legacy directories and introduces a script to publish deprecated tombstone packages to PyPI. Feedback on these changes highlights two main issues: first, the removal of the tests directory from testpaths in py/pyproject.toml will cause critical smoke tests to be skipped; second, using uv publish in the tombstone publishing script may fail on older versions of uv, so using twine upload is recommended for better backward compatibility.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread py/pyproject.toml Outdated
Comment thread py/scripts/publish_tombstones.py Outdated

@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 reorganizes the Genkit Python SDK by renaming several plugin packages (e.g., changing genkit-plugin-google-genai to genkit-googleai) and updating their corresponding import paths across packages, tests, and samples. It also introduces a script to publish deprecated tombstone packages to PyPI for migration purposes. However, two issues were identified: the uv build command in the new tombstone publishing script uses an unsupported --default-index option which will cause it to fail, and the removal of tests from testpaths in py/pyproject.toml will prevent smoke tests from being run during test discovery.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread py/scripts/publish_tombstones.py Outdated
Comment thread py/pyproject.toml Outdated
…ipt when available to prevent CI spawn failures
…schemas so TelemetryLabels emits as typed dict map alias
…del validation prioritizes TextPart over DataPart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config docs Improvements or additions to documentation python Python root

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant