dagster-vertexai
A dagster module that provides integration with Google Cloud Vertex AI.
Installation
The dagster_vertexai module is available as a PyPI package - install with your preferred python
environment manager (We recommend uv).
source .venv/bin/activate
uv pip install dagster-vertexai
Example Usage
In addition to wrapping the Vertex AI GenerativeModel class (get_model/get_model_for_asset methods), this resource logs the usage of the Vertex AI API to the asset metadata (both number of calls, and tokens). This is achieved by wrapping the GenerativeModel.generate_content method.
Note that the usage will only be logged to the asset metadata from an Asset context - not from an Op context. Also note that only the synchronous API usage metadata will be automatically logged - not the streaming or batching API.
from dagster import AssetExecutionContext, Definitions, EnvVar, asset
from dagster_vertexai import VertexAIResource
@asset(compute_kind="vertexai")
def vertexai_asset(context: AssetExecutionContext, vertexai: VertexAIResource):
with vertexai.get_model(context) as model:
response = model.generate_content(
"Generate a short sentence on tests"
)
return response.text
defs = Definitions(
assets=[vertexai_asset],
resources={
"vertexai": VertexAIResource(
project_id=EnvVar("VERTEX_AI_PROJECT_ID"),
location=EnvVar("VERTEX_AI_LOCATION"),
generative_model_name="gemini-1.5-flash-001"
),
},
)
Configuration
The VertexAIResource supports the following configuration options:
project_id: Your Google Cloud project IDlocation: The Google Cloud region (e.g., "us-central1")generative_model_name: The name of the generative model (e.g., "gemini-1.5-flash-001")google_credentials(optional): JSON string of service account credentials. If not provided, uses Application Default Credentialsapi_endpoint(optional): Custom API endpoint URL
Authentication
Authentication is handled via Application Default Credentials (ADC) by default. To authenticate:
gcloud auth application-default login
Alternatively, you can provide service account credentials via the google_credentials parameter.
Multi-Asset Usage
For multi-assets, use the get_model_for_asset method to specify which asset the usage metadata should be logged to:
from dagster import AssetExecutionContext, AssetKey, AssetSpec, MaterializeResult, multi_asset
@multi_asset(
specs=[AssetSpec("summary"), AssetSpec("analysis")]
)
def vertexai_multi_asset(context: AssetExecutionContext, vertexai: VertexAIResource):
# Generate summary
with vertexai.get_model_for_asset(context, AssetKey("summary")) as model:
summary = model.generate_content("Summarize this data...")
# Generate analysis
with vertexai.get_model_for_asset(context, AssetKey("analysis")) as model:
analysis = model.generate_content("Analyze this data...")
yield MaterializeResult(asset_key="summary", metadata={"content": summary.text})
yield MaterializeResult(asset_key="analysis", metadata={"content": analysis.text})
Development
The Makefile provides the tools required to test and lint your local installation
make test
make ruff
make check
Release files for dagster-vertexai 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dagster_vertexai-0.0.2.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dagster_vertexai-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / dagster_vertexai-0.0.2.tar.gz
| Download URL | dagster_vertexai-0.0.2.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e76872c14b9b67e80911a86317f4ea72143180caa95693e05450259cc27b192a
|
|
BLAKE2b-256 checksum How to use checksums |
95cc19dcff7a4e982f144701e4b4a21150af486262374301760a55c159a31890
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / dagster_vertexai-0.0.2-py3-none-any.whl
| Download URL | dagster_vertexai-0.0.2-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e40da905faf73f21f936ef2204226a73f5fd2a151301d61444164482659a4a9
|
|
BLAKE2b-256 checksum How to use checksums |
8897b3b0fba1fe633f38e9a4610ad34a18401782f149c15ca0d49430e0c287fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|