Class BigtableEngine (0.6.0)

BigtableEngine(
    key: object,
    client: typing.Optional[
        google.cloud.bigtable.data._async.client.BigtableDataClientAsync
    ],
    loop: typing.Optional[asyncio.events.AbstractEventLoop],
    thread: typing.Optional[threading.Thread],
)

Manages the client and execution context, handling the

async/sync conversion via a background event loop.

This class is the core of the async/sync interoperability, providing a reusable component that can be shared across multiple store instances to conserve resources.

Properties

async_client

The data client property of this class.

Methods

BigtableEngine

BigtableEngine(
    key: object,
    client: typing.Optional[
        google.cloud.bigtable.data._async.client.BigtableDataClientAsync
    ],
    loop: typing.Optional[asyncio.events.AbstractEventLoop],
    thread: typing.Optional[threading.Thread],
)

Initializes the engine with a running event loop and a client.

Parameters
Name Description
key object

object to prevent direct constructor usage.

client BigtableDataClientAsync

The async Bigtable data client.

loop Optional[asyncio.AbstractEventLoop]

The asyncio event loop running in the background thread.

thread Optional[Thread]

The background thread hosting the event loop.

__start_background_loop

__start_background_loop(
    project_id: typing.Optional[str],
    credentials: typing.Optional[google.auth.credentials.Credentials] = None,
    client_options: typing.Optional[typing.Any] = None,
    **kwargs: typing.Any
) -> concurrent.futures._base.Future

Creates and starts the default background loop and thread

_create

_create(
    project_id: typing.Optional[str] = None,
    loop: typing.Optional[asyncio.events.AbstractEventLoop] = None,
    thread: typing.Optional[threading.Thread] = None,
    client: typing.Optional[
        google.cloud.bigtable.data._async.client.BigtableDataClientAsync
    ] = None,
    credentials: typing.Optional[google.auth.credentials.Credentials] = None,
    client_options: typing.Optional[typing.Any] = None,
    **kwargs: typing.Any
) -> langchain_google_bigtable.engine.BigtableEngine

Asynchronously instantiates the BigtableEngine Object

_run_as_async

_run_as_async(coro: typing.Any) -> typing.Any

Runs a coroutine on the background loop without blocking the main loop.

This is used for calling from an existing asynchronous context.

_run_as_sync

_run_as_sync(coro: typing.Any) -> typing.Any

Runs a coroutine on the background loop and waits for the result.

This is the core mechanism for providing a synchronous API.

async_initialize

async_initialize(
    project_id: typing.Optional[str] = None,
    credentials: typing.Optional[google.auth.credentials.Credentials] = None,
    client_options: typing.Optional[typing.Any] = None,
    **kwargs: typing.Any
) -> langchain_google_bigtable.engine.BigtableEngine

Creates a BigtableEngine instance with a background event loop and a new data client asynchronously

Parameters
Name Description
project_id Optional[str]

Google Cloud Project ID.

credentials Optional[google.auth.credentials.Credentials]

credentials to pass into the data client for this engine.

client_options Optional[Any]

Client options used to set user options for the client.

close

close() -> None

Closes the underlying client for this specific engine instance.

get_async_table

get_async_table(
    instance_id: str,
    table_id: str,
    app_profile_id: typing.Optional[str] = None,
    **kwargs: typing.Any
) -> google.cloud.bigtable.data._async.client.TableAsync

Returns the table using this class's client

initialize

initialize(
    project_id: typing.Optional[str] = None,
    credentials: typing.Optional[google.auth.credentials.Credentials] = None,
    client_options: typing.Optional[typing.Any] = None,
    **kwargs: typing.Any
) -> langchain_google_bigtable.engine.BigtableEngine

Creates a BigtableEngine instance with a background event loop and a new data client synchronously.

Parameters
Name Description
project_id Optional[str]

Google Cloud Project ID.

credentials Optional[google.auth.credentials.Credentials]

credentials to pass into the data client for this engine.

client_options Optional[Any]

Client options used to set user options for the client.

shutdown_default_loop

shutdown_default_loop() -> None

Closes the default class-level shared loop and terminates the thread associated with it.

Note: Calling this method will prevent any new BigtableEngine instances from using the shared event loop. Additionally, after this method is called it will not be possible to run more coroutines in the previous loop.

Exceptions
Type Description
Exception If the thread does not terminate within the timeout period.