Skip to content

API Docs

geneva.connect

connect(
    uri: str | Path,
    *,
    region: str | None = None,
    api_key: Credential | str | None = None,
    host_override: str | None = None,
    storage_options: dict[str, str] | None = None,
    checkpoint: str | CheckpointStore | None = None,
    **kwargs,
) -> Connection

Connect to Geneva.

Examples:

>>> import geneva
>>> conn = geneva.connect("db://my_dataset")
>>> tbl = conn.open_table("youtube_dataset")

Parameters:

  • uri (str | Path) –

    LanceDB Database URI, or a S3/GCS path

  • region (str | None, default: None ) –

    LanceDB cloud region. Set to None on LanceDB Enterprise

  • api_key (Credential | str | None, default: None ) –

    API key to connect to the DB instance.

  • host_override (str | None, default: None ) –

    Set to the host of the enterprise stack

Returns:

  • Connection - A LanceDB connection
Source code in geneva/db.py
def connect(
    uri: str | Path,
    *,
    region: str | None = None,
    api_key: Credential | str | None = None,
    host_override: str | None = None,
    storage_options: dict[str, str] | None = None,
    checkpoint: str | CheckpointStore | None = None,
    **kwargs,
) -> Connection:
    """Connect to Geneva.

    Examples
    --------
        >>> import geneva
        >>> conn = geneva.connect("db://my_dataset")
        >>> tbl = conn.open_table("youtube_dataset")

    Parameters
    ----------
    uri: geneva URI, or Path
        LanceDB Database URI, or a S3/GCS path
    region: str | None
        LanceDB cloud region. Set to `None` on LanceDB Enterprise
    api_key: str | None
        API key to connect to the DB instance.
    host_override: str | None
        Set to the host of the enterprise stack

    Returns
    -------
    Connection - A LanceDB connection

    """

    # load values from config if not provided via arguments
    config = _GenavaConnectionConfig.get()
    region = region or config.region
    api_key = api_key or config.api_key
    api_key = Credential(api_key) if isinstance(api_key, str) else api_key
    host_override = host_override or config.host_override

    # handle local relative paths
    is_local = isinstance(uri, Path) or get_uri_scheme(uri) == "file"
    if is_local:
        if isinstance(uri, str):
            uri = Path(uri)
        uri = uri.expanduser().absolute()
        Path(uri).mkdir(parents=True, exist_ok=True)

    if checkpoint is None:
        checkpoint = str(URL(str(uri)) / "ckp")
    if isinstance(checkpoint, str):
        checkpoint_store = CheckpointStore.from_uri(checkpoint)
    else:
        checkpoint_store = checkpoint
    return Connection(
        str(uri),
        region=region,
        api_key=api_key,
        host_override=host_override,
        storage_options=storage_options,
        checkpoint_store=checkpoint_store,
        **kwargs,
    )