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.

Supported File Types

Currently ezcf supports JSON, YAML and INI with extension json, yaml, yml, ini.

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
print(sy.something)

from sample_json import *
# or
from sample_json import something
# or
import sample_json as sj
print(sj.something)

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. So it’s better not to use multiple documents;

  3. All values in .ini files are kept as it is and loaded as a string;

  4. 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

  • [x] INI support

  • [ ] XML 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.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ezcf-0.0.2-py2.py3-none-any.whl (8.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ezcf-0.0.2.tar.gz.

File metadata

  • Download URL: ezcf-0.0.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ezcf-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f3918bdaac480cb7b65690e9d6c05b71cce02453ebb0676e16f4ba0688161034
MD5 997506b704fec26e89db17d38c3f3b30
BLAKE2b-256 6fd68ca9670b9843212973ffb1a388d8f713b103cd8c46add0e74fe2e1ea6705

See more details on using hashes here.

File details

Details for the file ezcf-0.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for ezcf-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 351df38ff4680060dfeb0cb583671c58437543ddef3f94a38577bf94c9c0b249
MD5 6066ce46824e03ac7c7db0baa0764409
BLAKE2b-256 ae3f76a4bce117dee1086bd347d4d521b8d4bd35d75ba1e691607da632e99d63

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page