Skip to main content
The pyconfigs/connections.py file allows you to define database connections for your Squirrels project using Python. This provides greater flexibility than the YAML-based configuration in squirrels.yml, enabling dynamic connection strings, conditional logic, and access to resource files if needed.
Connections can also be defined in the squirrels.yml file. Connections defined in squirrels.yml are loaded first, then connections.py runs (if exists) and can add or override connections.
Always define the default connection name for data models or data source parameters that do not specify a connection name explicitly.The default connection name is default unless set differently by the environment variable SQRL_CONNECTIONS__DEFAULT_NAME_USED.

File structure

The connections.py file must define a main function with the following signature:
pyconfigs/connections.py

The ConnectionsArgs object

The sqrl argument is a ConnectionsArgs object that provides useful properties for building connection strings dynamically.

Creating connections

Add connections by assigning ConnectionProperties objects to the connections dictionary:
pyconfigs/connections.py
You can also store other values in the connections dictionary that are not ConnectionProperties objects, as long as the key is not used as the database connection name for data models or data source parameters.This can be useful for storing artifacts (such as ML models or API clients) in memory at server startup time. These can then be accessed in the context.py file or Python data models.

Connection types

Squirrels supports four connection types via ConnectionTypeEnum: For details on URI formats for each connection type, see URI formats.

Examples

SQLite connection

pyconfigs/connections.py

PostgreSQL connection

pyconfigs/connections.py

DuckDB connection

pyconfigs/connections.py

Multiple connections with environment-based logic

pyconfigs/connections.py

High-performance connection with ConnectorX

pyconfigs/connections.py

Custom connection objects

You can also add custom connection objects (such as pre-configured database clients) to the dictionary:
pyconfigs/connections.py