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 dsnparse3
dsn = "prom.interface.postgres.Interface://testuser:testpw@localhost:1234/testdb"
r = dsnparse3.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')
Use pip:
pip install dsnparse3
MIT