Skip to main content

connparse

Connparse parses database connection strings, DSNs, URLs, file paths, and cloud storage URIs into one predictable Python dict.

Connparse is useful when your app accepts connection strings from different systems and you want to pull out the host, port, database, bucket, path, credentials, query options, and a safe redacted string.

Supported sources include PostgreSQL, MySQL, MariaDB, SQLite, DuckDB, ClickHouse, Redis, Memcached, Elasticsearch, MongoDB, CockroachDB, QuestDB, YugabyteDB, TiDB, Valkey, Dragonfly, OpenSearch, FerretDB, ElastiCache, DocumentDB, SQL Server, Oracle, Snowflake, Cassandra, BigQuery, Redshift, Aurora, Neo4j, Trino, Databricks, DynamoDB, StarRocks, SAP HANA, Athena, Spanner, Google Cloud Storage, Azure Blob, Azure Data Lake Storage, Azure Files, Azure Cosmos DB, Business Central, TallyPrime, Amazon S3, and local file paths.

Install

pip install connparse

Basic Usage

from connparse import parse

result = parse("postgres://user:pass@localhost:5432/app?sslmode=require")

if not result["ok"]:
    print(result["errors"])
else:
    print(result["value"])

Result:

{
  "scheme": "postgres",
  "type": "database",
  "authority": {
    "host": "localhost",
    "port": 5432
  },
  "resource": {
    "type": "database",
    "name": "app"
  },
  "path": "",
  "query": {
    "sslmode": "require"
  },
  "fragment": null,
  "credentials": {
    "username": "user",
    "password": "pass"
  },
  "options": {},
  "raw": "postgres://user:pass@localhost:5432/app?sslmode=require",
  "safe": "postgres://user:***@localhost:5432/app?sslmode=require"
}

Recommended Usage

Use parse() for form handling, validation, and showing parsed connection details to users.

result = parse(input)

if result["ok"]:
    address = result["value"]
    save_connection(
        host=address["authority"].get("host"),
        port=address["authority"].get("port"),
        database=address["resource"]["name"],
        safe_label=address["safe"],
    )

Use safe for logs and UI labels. Do not log raw or credentials unless the user explicitly asks to reveal secrets.

logger.info("connection=%s", result["value"]["safe"])

Use parse_normalize() when you need a stable identity for dedupe, cache keys, or config comparison.

from connparse import parse_normalize

parse_normalize("postgresql://LOCALHOST:5432/app?sslmode=require")["value"]["canonical"]
# "postgres://localhost/app?sslmode=require"

Use provider when the string does not clearly identify the source type.

parse("host=db.example.com port=5432 dbname=app user=alice", {
    "provider": "postgres",
})

parse("https://clickhouse.example.com:8443/default", {
    "provider": "clickhouse",
})

Use strict when you want unknown query parameters to fail validation.

parse("postgres://localhost/app?unexpected=1", {"strict": True})

Examples

Source Input Parsed result
PostgreSQL postgres://user:pass@localhost:5432/app?sslmode=require authority.host = "localhost", authority.port = 5432, resource.name = "app", query.sslmode = "require"
MySQL mysql://root:secret@127.0.0.1/shop?charset=utf8mb4 authority.host = "127.0.0.1", authority.port = 3306, resource.name = "shop", query.charset = "utf8mb4"
MariaDB mariadb://root:secret@mariadb.example.com:3306/app authority.host = "mariadb.example.com", authority.port = 3306, resource.name = "app"
SQLite sqlite::memory: scheme = "sqlite", resource.name = ":memory:", path = ":memory:", options.memory = true
DuckDB duckdb:///tmp/analytics.duckdb?access_mode=read_only scheme = "duckdb", path = "/tmp/analytics.duckdb", query.access_mode = "read_only"
ClickHouse jdbc:clickhouse:http://localhost:8123/analytics?ssl=false authority.host = "localhost", authority.port = 8123, resource.name = "analytics", options.protocol = "http"
Memcached memcached://cache.example.com authority.host = "cache.example.com", authority.port = 11211, type = "cache"
Redis rediss://:pass@cache.example.com/0 authority.host = "cache.example.com", authority.port = 6379, resource.name = "0", options.tls = true
Elasticsearch elasticsearch+https://elastic:secret@es.example.com:9243/logs?api_key=abc authority.host = "es.example.com", authority.port = 9243, resource.name = "logs", credentials.api_key = "abc"
MongoDB mongodb+srv://user:pass@cluster.mongodb.net/app?retryWrites=true authority.host = "cluster.mongodb.net", resource.name = "app", query.retryWrites = "true", options.srv = true
CockroachDB cockroach://root@servername:26257/mydb?sslmode=disable authority.host = "servername", authority.port = 26257, resource.name = "mydb", options.compatible_with = "postgres"
QuestDB https::addr=questdb.example.com:9000;username=admin;password=quest;auto_flush_rows=5000; authority.host = "questdb.example.com", authority.port = 9000, query.auto_flush_rows = "5000", options.ingestion = true
YugabyteDB yugabyte://yugabyte:yugabyte@localhost:5433/yugabyte?loadBalance=any authority.host = "localhost", authority.port = 5433, resource.name = "yugabyte", query.loadBalance = "any"
S3 s3://my-bucket/path/to/file.csv?versionId=123 authority.bucket = "my-bucket", resource.name = "my-bucket", path = "path/to/file.csv"
File file:///tmp/data.csv#header scheme = "file", path = "/tmp/data.csv", fragment = "header"

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

connparse-0.9.0.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

connparse-0.9.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file connparse-0.9.0.tar.gz.

File metadata

  • Download URL: connparse-0.9.0.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for connparse-0.9.0.tar.gz
Algorithm Hash digest
SHA256 871ad3e385a735f5975913b83afd198ce2cc8b7782967c967ed513d5ddd94a41
MD5 c0f58efb9a47eae4126e0d4fd8edb969
BLAKE2b-256 ffc0c23c5a13c86c38275003bdc863a30cbb457f2343642cd3b5fd29311ddefd

See more details on using hashes here.

Provenance

The following attestation bundles were made for connparse-0.9.0.tar.gz:

Publisher: release.yml on clidey/connparse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file connparse-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: connparse-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for connparse-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 01f8815efd434cf9e521684740938f2aed159848542cfae69b13c05606110f36
MD5 3e03f7ac9807888dff5ed73a0ce8d361
BLAKE2b-256 175e6b190d4a4e68adff42fa32a3ebdbb79ab4aaa4f14b4d73e834fb35f4f7f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for connparse-0.9.0-py3-none-any.whl:

Publisher: release.yml on clidey/connparse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page