launchflow.gcp.compute_engine
ComputeEngine
1class ComputeEngine(GCPResource[T])
A Compute Engine VM running a Docker container.
Example usage:
1import launchflow as lf
2
3compute_engine = lf.gcp.ComputeEngine("my-compute-engine", vm_config=lf.gcp.compute_engine.VMConfig(
4 additional_outputs={"my_output": "my_value"},
5 docker_cfg=lf.gcp.compute_engine.DockerConfig(
6 image="my-docker-image",
7 args=[],
8 environment_variables={"MY_ENV_VAR": "my_value"},
9 ),
10 firewall_cfg=lf.gcp.compute_engine.FirewallConfig(expose_ports=[80]),
11))
__init__
1def __init__(name: str, vm_config: VMConfig) -> None
Create a Compute Engine resource. Args:
name
(str): The name of the resource. This must be globally unique.vm_config
(VMConfig): The configuration for the VM.additional_outputs
(dict): Additional outputs to be returned by the resource.docker_cfg
(DockerConfig): The configuration for the Docker container.image
(str): The Docker image to run.args
(List[str]): The arguments to pass to the Docker container.environment_variables
(dict): Environment variables to set in the Docker container.
firewall_cfg
(FirewallConfig): The configuration for the firewall rules.expose_ports
(List[int]): The ports to expose in the firewall.
ComputeEnginePostgres
1class ComputeEnginePostgres(ComputeEngine[ComputeEnginePostgresConnectionInfo]
2 )
A Postgres instance running on a VM in Google Compute Engine.
Example usage:
1from sqlalchemy import text
2import launchflow as lf
3
4postgres_compute_engine = lf.gcp.ComputeEnginePostgres("ce-postgres-mn-test-2")
5engine = postgres_compute_engine.sqlalchemy_engine()
6
7with engine.connect() as connection:
8 print(connection.execute(text("SELECT 1")).fetchone()) # prints (1,)
__init__
1def __init__(name: str, *, password: Optional[str] = None) -> None
Create a new Compute Engine Postgres resource.
Args:
name
(str): The name of the Postgres VM resource. This must be globally unique.password
(str): The password for the Postgres DB. If not provided, a random password will be generated.
sqlalchemy_engine
1def sqlalchemy_engine(**engine_kwargs)
Returns a SQLAlchemy engine for connecting to a postgres instance hosted on GCP compute engine.
Args:
**engine_kwargs
: Additional keyword arguments to pass tosqlalchemy.create_engine
.
Example usage:
1import launchflow as lf
2db = lf.gcp.ComputeEnginePostgres("my-pg-db")
3engine = db.sqlalchemy_engine()
sqlalchemy_async_engine
1async def sqlalchemy_async_engine(**engine_kwargs)
Returns an async SQLAlchemy engine for connecting to a postgres instance hosted on GCP compute engine.
Args:
**engine_kwargs
: Additional keyword arguments to pass tocreate_async_engine
.
Example usage:
1import launchflow as lf
2db = lf.gcp.ComputeEnginePostgres("my-pg-db")
3engine = await db.sqlalchemy_async_engine()
ComputeEngineRedis
1class ComputeEngineRedis(ComputeEngine[ComputeEngineRedisConnectionInfo])
A Redis resource running on a VM in Google Compute Engine.
Args:
name
(str): The name of the Redis VM resource. This must be globally unique.password
(str): The password for the Redis DB. If not provided, a random password will be generated.
Example usage:
1import launchflow as lf
2
3redis = lf.gcp.ComputeEngineRedis("my-redis-instance")
4
5# Set a key-value pair
6client = redis.redis()
7client.set("my-key", "my-value")
8
9# Async compatible
10async_client = await redis.redis_async()
11await async_client.set("my-key", "my-value")
redis
1def redis(*, decode_responses: bool = True)
Get a Generic Redis Client object from the redis-py library.
Returns:
- The Generic Redis Client from the redis-py library.
redis_async
1async def redis_async(*, decode_responses: bool = True)
Get an Async Redis Client object from the redis-py library.
Returns:
- The Async Redis Client object from the redis-py library.