Skip to main content

Import JSON/YAML like importing .py files

Project description

Build Status Supported Python versions Latest Version Development Status

ezcf stands for easy configuration, it allows you to import JSON/YAML like importing .py files, which is very useful for reading conf files with these formats.

OK, stop talking, show us some code!

On the left is what you’ll normally do, on the right is the ezcf way. Much more elegant isn’t it?

Install

pip install ezcf

If you run into error: yaml.h: No such file or directory, don’t worry, you can still use ezcf without any problem.

Sample Usage

ezcf supports all kinds of valid import statements, here’s an example:

├── subdir
│   ├── __init__.py
│   └── sample_yaml.yaml
├── test_normal.py
└── sample_json.json

Various ways to use configurations in sample_yaml.yaml and sample_json.json:

import ezcf

from subdir.sample_yaml import *
# or
from subdir.sample_yaml import something
# or
import subdir.sample_yaml as sy

from sample_json import *
# or
from sample_json import something
# or
import sample_json as sj

You can assume they’re just regular python files.(Currently ezcf only supports files with utf-8 encoding)

What about relative import? Yes, ezcf supports relative import, as long as you use it correctly. See tests2 for an example.

Something to note before using ezcf:

  1. ezcf is still in developement. If you find any bug, please report it in issues;

  2. Be careful importing YAML which contains multiple documents: if there exists keys with the same name, only one of them will be loaded;

  3. Namespace package is not supported yet, pull requests are welcome.

Roadmap

  • [x] Use dot to seperate folder/subfolder/file

  • [x] Unicode support

  • [x] JSON support

  • [x] YAML support

  • [ ] INI support

  • [ ] Auto encoding detect?

  • [x] CI

  • [ ] coverage

  • [x] pypi

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

ezcf-0.0.1.post1.zip (9.1 kB view hashes)

Uploaded Source

Built Distribution

ezcf-0.0.1.post1-py2.py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 2 Python 3

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