Skip to main content

Add service URL parsing support for environs

Project description

Travis-CI

environs-serviceurl is a Python library that extends the environs library with support for turning service urls like postgres://user:pass@host:port/database into Python dictionaries.

Install

$ pip install environs-serviceurl

Usage

# export DATABASE_URL=postgres://me:sekrit@postgres.example.com:5432/catpics
# export REDIS_URL=redis://redis.example.com?dbid=3

from environs import Env
from environs_serviceurl import service_url

env = Env()
env.add_parser('service_url', service_url)

# Parse a service url.
postgres_config = env.service_url('DATABASE_URL')
# {'host': 'postgres.example.com',
#  'port': 5432,
#  'user': 'me',
#  'password': 'sekrit',
#  'extras': 'catpics'}

# Give the extras a specific name
postgres_config = env.service_url('DATABASE_URL', extras_name='database')
# {'host': 'postgres.example.com',
#  'port': 5432,
#  'user': 'me',
#  'password': 'sekrit',
#  'database': 'catpics'}

# Parse a service url with defaults, using query params for extra values.
redis_config = env.service_url('REDIS_URL', 'redis://localhost/', defaults={
    'host': 'service.example.com', 'port': 6379, 'dbid': 0})
# {'host': 'redis.example.com',
#  'port': 6379,
#  'user': None,
#  'password': None,
#  'extras': None,
#  'dbid': '3'}

Limitations

There’s currently no way to do casting on any extras or query string paramaters. They will always be returned as string types.

License

MIT. See the LICENSE file for details.

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

environs-serviceurl-1.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

environs_serviceurl-1.0.1-py2.py3-none-any.whl (4.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file environs-serviceurl-1.0.1.tar.gz.

File metadata

File hashes

Hashes for environs-serviceurl-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e324784ae9932d17bdd58a032e04dce8e891fad3ebca1f9d43110dcee76bb5cb
MD5 d8bf86e8408b951a82f3b30a6d5da876
BLAKE2b-256 a7287c8be86279abb7c0a3d6372916879ccecac88da1c1b018838aa67ed83a36

See more details on using hashes here.

File details

Details for the file environs_serviceurl-1.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for environs_serviceurl-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 840849a6b3557c880c5dcbeee77010a1425e2a5fcc5eb1fe09e924f4a2d9f419
MD5 3146c0a17ec9f265a22dd057c5efdd0a
BLAKE2b-256 e9ddcd034dbfb594c7ba57f6339aa6b7ecf64108b9031d0bb016bae64b2020f1

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