Skip to main content

No project description provided

Project description

keiconf

PyPI - Version PyPI - Python Version Hatch - Version

Repo - PRs Repo - Issues

A small, minimalist application json configuration tool for small projects.

Uses only stdlib if that matters to you.


Table of Contents

Why tho?

Fair question.

I originally started this project as an excuse to use Hatch and write a pyproject.toml no-distutils/setuptools python project and see how green the grass was.

I've typically been unhappy with the configuration options for python in a way I can't articulate very well, and I just wanted a simple json file read with some guiderails. Some quick user-side discovery to find my platform's config path and get going.

This project isn't meant to be a fully featured configuration system to slap into your next big webservice, it's just a small system to slap on your next prototype or small project.

Installation

pip install keiconf

Usage

from keiconf import KeiConf

k = KeiConf(filepath="path/to/file.json")
k.get("your_key")
k.get("path.to.your.nested_key")
k.start() # start watching config file for changes

Params

KeiConf(filepath, indent=2, fail_on_missing_key=False, create_if_not_exist=False, watch_for_changes=False)
  • filepath:str
    • The path to your target configuration file
    • ex. /path/to/file.json
  • indent:int
    • The json indentation to use for the written file
    • ex. 2
  • fail_on_missing_keys:bool
    • If True, will raise a KeyError if a key is missing, which you can catch and exit on.
    • If False, will return nothing
  • create_if_not_exist:bool
    • if True, will create the missing path directories and empty configuration file if it does not exist
    • if False will fail naturally on opening nonexistent configuration file
  • watch_for_changes:bool
    • if True will launch the config file watcher on init
    • if False will not launch the config file watcher on init
    • See Config File Watcher for more information

Config File Watcher

If your KeiConf instance is started with watch_for_changes=True then a threaded file watcher will load changes to your configuration file as it sees them (within keiconf._CHANGE_WATCH_INTERVAL).

If your KeiConf instance is started with watch_for_changes=False then the threaded file watcher is not created automatically.

You can stop and start the file watcher manually via the start() and stop() functions. It can be start()'ed even if you launched with watch_for_changes=False

k = KeiConf(...)
k.start() # starts the file watcher if it isn't already
k.stop() # stops a running file watcher if it is running

The file watcher and loader is protected by a threading.Lock()

Development

Development/Testing/Contribution requires hatch. Hatch provides the project management, environment abstraction, dependency resolution, and dev/test entrypoints.

python3 -m pip install hatch

although it is recommended to install hatch via pipx

python3 -m pip install pipx
python3 -m pipx ensurepath
python3 -m pipx install hatch

Limitations

  • Need to investigate behavior with lists

FAQ

  • Why not dot notation / attribute reference?
    • A: I looked into this as I was interested in possibly doing it, but it looked rather lengthy to implement and involved modifying the base class quite a bit or using wrappers and I just wasn't sure that was in the spirit of minimalism. The get() function uses a string dot notation get("path.to.key") as a sort of middle ground. --- I may revisit in the future.

License

keiconf is distributed under the terms of the MIT license.

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

keiconf-0.0.1.tar.gz (8.0 kB view hashes)

Uploaded Source

Built Distribution

keiconf-0.0.1-py3-none-any.whl (7.7 kB view hashes)

Uploaded 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