> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pysquirrels.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ConnectionProperties

> Properties for database connections

A class for holding the properties of a database connection. The class is usually created in the `pyconfigs/connections.py` file.

This class can be imported from the `squirrels.connections` or the `squirrels` module.

## Constructor

Creates a `ConnectionProperties` object.

```python theme={null}
def __init__(
    self, *, type: ConnectionTypeEnum = ConnectionTypeEnum.SQLALCHEMY, 
    uri: str, label: str | None = None, 
    sa_create_engine_args: dict[str, Any] = {}
) -> None:
```

<Expandable title="arguments" defaultOpen>
  <ResponseField name="type" type="ConnectionTypeEnum" default="ConnectionTypeEnum.SQLALCHEMY">
    The type of connection as [ConnectionTypeEnum](/references/python/connections/ConnectionTypeEnum).

    <Warning>
      The `ConnectionTypeEnum.ADBC` and `ConnectionTypeEnum.CONNECTORX` connection types do not support placeholders in the SQL query.
    </Warning>
  </ResponseField>

  <ResponseField name="uri" type="str" required>
    The URI for the connection. The URI format varies by database and connection type.

    For details on URI formats for each connection type, see [URI formats](/concepts/connections#uri-formats).
  </ResponseField>

  <ResponseField name="label" type="str | None" default="None">
    Optional label for the connection. If the label is not provided, the connection name will be used as the label.
  </ResponseField>

  <ResponseField name="sa_create_engine_args" type="dict[str, Any]" default="{}">
    Additional arguments to pass to SQLAlchemy's create\_engine function. Only used if the connection type is `ConnectionTypeEnum.SQLALCHEMY`.
  </ResponseField>
</Expandable>

## Examples

Below is an example of a `pyconfigs/connections.py` file that uses `ConnectionProperties` to define a SQLite database connection.

```python highlight={13-17} theme={null}
from typing import Any
from squirrels import arguments as args, connections as cn


def main(connections: dict[str, cn.ConnectionProperties | Any], sqrl: args.ConnectionsArgs) -> None:
    """
    Define sqlalchemy engines by adding them to the "connections" dictionary
    """
    ## SQLAlchemy URL for a connection engine
    conn_str: str = "sqlite:////absolute/path/to/database.db"

    ## Assigning names to connection engines
    connections["default"] = cn.ConnectionProperties(
        label="SQLite Database", 
        type=cn.ConnectionTypeEnum.SQLALCHEMY, 
        uri=conn_str
    )
```

The following are additional examples of creating `ConnectionProperties` objects.

### SQLAlchemy connection with engine arguments

```python theme={null}
# Connection with custom SQLAlchemy engine settings
postgres_conn = ConnectionProperties(
    uri="postgresql://user:password@localhost:5432/mydb",
    label="Production Database",
    sa_create_engine_args={
        "pool_size": 10,
        "pool_pre_ping": True
    }
)
```

### DuckDB connection

```python theme={null}
# DuckDB native connection
duckdb_conn = ConnectionProperties(
    type=ConnectionTypeEnum.DUCKDB,
    uri="/path/to/database.duckdb",
    label="DuckDB database"
)

# You can also connect to other databases using DuckDB
# such as PostgreSQL, MySQL, and SQLite.
postgres_conn = ConnectionProperties(
    type=ConnectionTypeEnum.DUCKDB,
    uri="postgresql://username@hostname/dbname",
    label="PostgreSQL database"
)

sqlite_conn = ConnectionProperties(
    type=ConnectionTypeEnum.DUCKDB,
    uri="sqlite:/path/to/database.db",
    label="SQLite database"
)
```

### ADBC connection

```python theme={null}
# Arrow Database Connectivity connection
adbc_conn = ConnectionProperties(
    type=ConnectionTypeEnum.ADBC,
    uri="postgresql://user:password@localhost:5432/mydb",
    label="High Performance ADBC"
)
```

### ConnectorX connection

```python theme={null}
# Fast data loading with ConnectorX
cx_conn = ConnectionProperties(
    type=ConnectionTypeEnum.CONNECTORX,
    uri="postgresql://user:password@localhost:5432/mydb",
    label="Fast Loading Connection"
)
```
