Connectors API
ConnectionManager
aitaem.connectors.connection.ConnectionManager
Manages multiple backend connections and routes queries.
Responsibilities
- Load connections from YAML configuration
- Environment variable substitution
- Store and retrieve connectors by backend type
- Parse source URIs and route to appropriate connector
Source code in aitaem/connectors/connection.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
__init__
from_yaml
classmethod
Load all connections from YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaml_path
|
str
|
Path to YAML configuration file |
required |
Returns:
| Type | Description |
|---|---|
ConnectionManager
|
ConnectionManager instance with loaded connections |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If YAML file doesn't exist |
ConfigurationError
|
If YAML is invalid or missing required fields |
Source code in aitaem/connectors/connection.py
add_connection
Add single connection by creating and storing IbisConnector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend_type
|
str
|
Backend type ('duckdb', 'bigquery', etc.) |
required |
connector
|
IbisConnector | None
|
Optional pre-existing IbisConnector instance. If provided, it is stored directly without creating a new connection. |
None
|
**config
|
Any
|
Backend-specific configuration (used only when connector is None) - DuckDB: path (str), read_only (bool, optional) - BigQuery: project_id (str), dataset_id (str, optional) |
{}
|
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
If a connection for backend_type already exists, or if required config fields are missing. |
UnsupportedBackendError
|
If backend_type is not supported |
ValueError
|
If configuration is invalid |
Source code in aitaem/connectors/connection.py
get_connection
Get connector by backend type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend_type
|
str
|
Backend type ('duckdb', 'bigquery', etc.) |
required |
Returns:
| Type | Description |
|---|---|
IbisConnector
|
IbisConnector for the specified backend |
Raises:
| Type | Description |
|---|---|
ConnectionNotFoundError
|
If backend not configured |
Source code in aitaem/connectors/connection.py
get_connection_for_source
Parse URI and return appropriate connector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_uri
|
str
|
Source URI (e.g., 'duckdb://analytics.db/events') |
required |
Returns:
| Type | Description |
|---|---|
IbisConnector
|
IbisConnector for the backend specified in URI |
Raises:
| Type | Description |
|---|---|
InvalidURIError
|
If URI is malformed |
ConnectionNotFoundError
|
If backend not configured |
Source code in aitaem/connectors/connection.py
parse_source_uri
staticmethod
Parse source URI into (backend, database, table).
Format: backend://database_identifier/table_name
DuckDB Examples
- 'duckdb://analytics.db/events' → ('duckdb', 'analytics.db', 'events')
- 'duckdb://:memory:/events' → ('duckdb', ':memory:', 'events')
- 'duckdb:///abs/path/db/events' → ('duckdb', '/abs/path/db', 'events')
BigQuery Examples
- 'bigquery://my-project.dataset.table' → ('bigquery', 'my-project', 'dataset.table')
- 'bigquery://project/dataset.table' → ('bigquery', 'project', 'dataset.table')
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
Source URI |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str, str]
|
Tuple of (backend_type, database_identifier, table_name) |
Raises:
| Type | Description |
|---|---|
InvalidURIError
|
If URI is malformed |
Source code in aitaem/connectors/connection.py
close_all
Backend Configuration
Each backend type has a corresponding configuration dataclass. These are the authoritative definitions of what fields each backend accepts — required fields have no default, optional fields do.
ConnectionManager.add_connection() and ConnectionManager.from_yaml() both validate the supplied config against the relevant dataclass and raise ConfigurationError with a clear message and YAML snippet if a required field is missing.
DuckDB
aitaem.connectors.backend_specs.DuckDBConfig
dataclass
Connection configuration for a DuckDB backend.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
File path to the DuckDB database, or |
read_only |
bool
|
Open the database in read-only mode. Defaults to |
Source code in aitaem/connectors/backend_specs.py
BigQuery
aitaem.connectors.backend_specs.BigQueryConfig
dataclass
Connection configuration for a BigQuery backend.
Authentication uses Application Default Credentials (ADC). Run
gcloud auth application-default login or set the
GOOGLE_APPLICATION_CREDENTIALS environment variable before connecting.
Attributes:
| Name | Type | Description |
|---|---|---|
project_id |
str
|
GCP project ID that owns the BigQuery datasets. Required. |
dataset_id |
str | None
|
Default dataset used when a table name is not fully-qualified. Optional. |
Source code in aitaem/connectors/backend_specs.py
PostgreSQL
aitaem.connectors.backend_specs.PostgresConfig
dataclass
Connection configuration for a PostgreSQL backend.
Attributes:
| Name | Type | Description |
|---|---|---|
database |
str
|
Name of the PostgreSQL database to connect to. Required. |
user |
str
|
PostgreSQL username. Required. |
password |
str
|
Password for the given user. Required.
Use |
host |
str
|
Hostname or IP address of the PostgreSQL server.
Defaults to |
port |
int
|
TCP port the PostgreSQL server listens on. Defaults to |
Source code in aitaem/connectors/backend_specs.py
validate_backend_config
aitaem.connectors.backend_specs.validate_backend_config
Validate a config dict against the backend's dataclass spec.
Instantiates the backend's config dataclass from the provided dict, ignoring any extra keys that are not part of the dataclass (they may be pass-through kwargs consumed directly by the Ibis backend).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend_type
|
str
|
Backend identifier (e.g. 'duckdb', 'bigquery', 'postgres') |
required |
config
|
dict[str, Any]
|
Configuration dictionary from connections.yaml or add_connection() |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Instantiated config dataclass (e.g. PostgresConfig) |
Raises:
| Type | Description |
|---|---|
UnsupportedBackendError
|
If backend_type is not in BACKEND_SPECS |
ConfigurationError
|
If a required field is missing or has the wrong type |