: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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aio_yamlconfig-0.2.0.tar.gz | 3.4 kB | Without provenance | Details for aio_yamlconfig-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aio_yamlconfig-0.2.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for aio_yamlconfig-0.2.0-py2.py3-none-any.whl |
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 |
Security for aio_yamlconfig 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.