Skip to main content

parse dsn urls

Project description

Parse dsn connection url strings. I kept duplicating dsn parsing code for things like prom and morp, and I realized I was going to need many more dsn urls in the future so I decided to create something a little more modular.

This is a generic version of dj-database-url.

So, now you can create dsns like this:

scheme://user:pass@host:port/path?query=query_val#fragment

For example, let’s look at a prom dsn:

prom.interface.postgres.Interface://testuser:testpw@localhost/testdb

Now let’s parse it:

import dsnparse

dsn = "prom.interface.postgres.Interface://testuser:testpw@localhost:1234/testdb"
r = dsnparse.parse(dsn)

print r.scheme # prom.interface.postgres.Interface
print r.username # testuser
print r.password # testpw
print r.host # localhost
print r.hostloc # localhost:1234
print r.paths # ['testdb']

Also, dsnparse can easily use environment variables:

r = dsnparse.parse_environ('ENVIRONMENT_VARIABLE_NAME')

I tried to keep the interface very similar to urlparse so it will feel familiar to use.

Install

Use pip:

pip install dsnparse

or use github:

pip install git+https://github.com/Jaymon/dsnparse#egg=dsnparse

License

MIT

Project details


Download files

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

Source Distribution

dsnparse-0.1.4.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file dsnparse-0.1.4.tar.gz.

File metadata

  • Download URL: dsnparse-0.1.4.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dsnparse-0.1.4.tar.gz
Algorithm Hash digest
SHA256 7899406a47de69a69bb6e2636f9bc60c7fe4a21c48782c3bccff90100fc54b4e
MD5 0e34f457d1b3b834646780ff12eb2b47
BLAKE2b-256 24a1bd1407d4a23cb115ace90ea234f1744e2c6076190274b74216b8554e0a9b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page