A Python library for reading and managing configuration files.
Project description
Piver 📌
A Python library for reading and managing configuration files, similar to Golang's spf13/viper.
README.md also provides a Chinese version
Supported Configuration File Types 📝
✅ = Available, 🚧 = Under Development
- ✅ json
- ✅ yaml
- ✅ toml
- 🚧 ini
- 🚧 hcl
- 🚧 envfile
- 🚧 java properties
- ✅ from environment variables
- ✅ from parameters
- 🚧 from network
- ......
Features ✨
Ready to Use Out of the Box
Just a simple configuration is needed to get started, eliminating the need to manually write code to read configuration files, allowing you to focus more on project development rather than spending time on tedious tasks.
Automatic Local Configuration File Search and Load
Piver can automatically search for and load the required configuration files in the target path you configure, making it easy to access configuration entries in your project.
Default Value Support
Piver can use your custom default values when a configuration item cannot be retrieved.
Environment Variables and Command Line Parameters Support
Piver can also load configuration files by reading environment variables and command line parameters.
Priority: Command Line Parameters > Environment Variables > Configuration Files
Installation 🚚
If you want to use Piver in your Python project, you need to install it first.
Install using pip
pip install piver
Install using poetry
poetry add piver
Usage 🍱
Piver is global, meaning it's best to load the configuration file early in the project's lifecycle; otherwise, trying to access configuration items before loading the configuration file will raise a ConfigNotInitializedError.
Configure Piver
First, tell Piver the basic information of the configuration file: name, scan location, and format. If you provide a file with an extension to Piver, you do not need to explicitly tell it the file format; it will automatically infer it.
Next, use read_in_config() to read the configuration file.
Finally, use get() to retrieve content, with the target key as a string, using . to separate levels.
import piver
piver.add_config_path(".") # add current directory to config path
piver.set_config_type("toml") # set config file type to toml
piver.set_config_name("example") # set config file name to example
piver.read_in_config() # read in config file MUST
print(f"Dsn is: {piver.get('database.dsn')}") # get value of database.dsn
Author
ZichengHuang 黄子程
lfcypo (Zicheng Huang)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file piver-0.0.1.tar.gz.
File metadata
- Download URL: piver-0.0.1.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d94768a2061c8fd691be0ba6b24ae3f4d655ee33c3eeed32994ccca491f718c9
|
|
| MD5 |
bfa86a222d68b2364fa598f2dc092821
|
|
| BLAKE2b-256 |
9e24d91f8773c69813ab7543907b535e1ade3b4388a14817eff5b59c2ca8367c
|
File details
Details for the file piver-0.0.1-py3-none-any.whl.
File metadata
- Download URL: piver-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8a037318a1ad5429c04fd76ac8393f4ea21ed23f74f0dc7a81638ab7dc230f3
|
|
| MD5 |
68c9dc6aedbc7477d4e144de1666bc4d
|
|
| BLAKE2b-256 |
c547c56c5dadfd3775a470c036abbc316469835db5959276062fdc75fb7fe0a8
|