URL¶
deep_db_agents.url ¶
Database URL parsing.
Two supported forms:
- Network DBs (
mysql,postgres,mongodb,neo4j…):<scheme>://<host>:<port>. - File-based DBs (
sqlite,duckdb):<scheme>://<path>where<path>is the file path (or directory, for the DuckDB data lake) following the SQLAlchemy convention:sqlite:///rel.dbis relative to the working dir,sqlite:////abs.dbis absolute,sqlite://:memory:is in-memory.
ParsedUrl
dataclass
¶
ParsedUrl(scheme: str, host: str | None, port: int | None, path: str | None = None)
Components of a database URL.
scheme is normalized to lowercase and is what selects the dialect.
host/port are set for network DBs; path is set for file-based DBs
(with :memory: for in-memory databases). A trailing slash in path
indicates a directory (DuckDB data lake).
Attributes:
| Name | Type | Description |
|---|---|---|
scheme |
str
|
The normalized (lowercase) URL scheme. |
host |
str | None
|
Hostname for network databases, or |
port |
int | None
|
Port for network databases, or |
path |
str | None
|
File/directory path for file-based databases, or |
parse_db_url ¶
parse_db_url(db_url: str) -> ParsedUrl
Extract the components from a <scheme>://<host>:<port> or <scheme>://<path> URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_url
|
str
|
The database URL to parse. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ParsedUrl |
ParsedUrl
|
The parsed URL components. |
Raises:
| Type | Description |
|---|---|
InvalidDbUrlError
|
If |
Examples:
>>> parse_db_url("mysql://localhost:3306")
ParsedUrl(scheme='mysql', host='localhost', port=3306, path=None)
>>> parse_db_url("sqlite:///data/app.db")
ParsedUrl(scheme='sqlite', host=None, port=None, path='data/app.db')
Source code in src/deep_db_agents/url.py
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 | |