Skip to main content
.. image:: https://img.shields.io/pypi/v/aio_yamlconfig.svg
:target: https://pypi.org/project/aio_yamlconfig

.. image:: https://img.shields.io/travis/rrader/aio_yamlconfig/master.svg
:target: http://travis-ci.org/rrader/aio_yamlconfig

.. image:: https://img.shields.io/pypi/pyversions/aio_yamlconfig.svg

.. image:: https://img.shields.io/pypi/dm/aio_yamlconfig.svg


aio_yamlconfig
========

Quick Start
------------------

Install from PYPI:

.. code:: shell

pip install aio_yamlconfig

OR (less popular) via setup.py:

.. code:: shell

python -m setup install

YAML configuration parser with validation using `Trafaret <http://trafaret.readthedocs.org/en/latest/>`_.

In the easiest setup without config validation, configure your ``aiohttp`` application with:

.. code:: python
:number-lines:

CONFIG_FILE = os.path.join(os.path.dirname(__file__), "config.yaml")
loop.run_until_complete(aio_yamlconfig.setup(app,
config_files=[CONFIG_FILE],
base_dir=os.path.dirname(__file__)))

Assume you have ``config.yaml``:

.. code:: yaml
:number-lines:

DEBUG: True
TEMPLATES_DIR: !BaseDir path/to/templates

Then you can access your config as:

.. code:: python
:number-lines:

if app.config['DEBUG']:
print('some debug information')

Notice the ``!BaseDir`` tag. ``aio_yamlconfig`` can do some config transformations for you, in this case it will prepend
the base directory (passed as ``base_dir`` to ``setup()``) to your path. The variable ``app.config['TEMPLATES_DIR']`` will contain
the full path to directory with your templates.

Validation
--------------------

To validate your config we use the great library Trafaret. You can read more about it `in the docs <http://trafaret.readthedocs.org/en/latest/>`_.
Here I'll give you a simple example of its usage.

Let's write the validator for ``config.yaml`` above. We'd like to ensure that ``DEBUG`` value is boolean, and that
directory of the path ``TEMPLATES_DIR`` really exists:

.. code:: python
:number-lines:

import trafaret as t
from aio_yamlconfig.trafarets import ExistingDirectory

CONFIG_TRAFARET = t.Dict({
t.Key('TEMPLATES_DIR'): ExistingDirectory,
t.Key('DEBUG'): t.Bool
})


To enable such validation pass the ``trafaret_validator`` to ``setup()`` function:

.. code:: python
:number-lines:

loop.run_until_complete(aio_yamlconfig.setup(app,
config_files=[CONFIG_FILE],
trafaret_validator=CONFIG_TRAFARET,
base_dir=os.path.dirname(__file__)))

Metadata

Release files for aio_yamlconfig 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aio_yamlconfig 0.2.0
File Size Uploaded
aio_yamlconfig-0.2.0.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aio_yamlconfig 0.2.0
File Interpreter ABI Platform
aio_yamlconfig-0.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 9.3 kB

Release files / aio_yamlconfig-0.2.0.tar.gz

Download URL aio_yamlconfig-0.2.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e5812675c2c9003b84940d84721a0267e29673c41234de6513f9e766c8cf06ea
BLAKE2b-256 checksum
How to use checksums
fef2e6650a5eac42893eb0d68bc9fe91283c4d0dee5535d446b91f2064e7dc28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aio_yamlconfig-0.2.0-py2.py3-none-any.whl

Download URL aio_yamlconfig-0.2.0-py2.py3-none-any.whl
Size 5.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
69d034a4f8e68d2c2e1413bba266752e691ccf671ef3b9edf8990b79f11eb613
BLAKE2b-256 checksum
How to use checksums
d0d5cb4ca872e8bc0330674e200454b6980dfd3dd63a4676f52aef5d5cc70636
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

1 release file

0.1.0

1 release file

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