Skip to main content

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)

Release files for piver 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for piver 0.0.1
File Size Uploaded
piver-0.0.1.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for piver 0.0.1
File Interpreter ABI Platform
piver-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size:20.9 kB

Release files / piver-0.0.1.tar.gz

Download URL piver-0.0.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d94768a2061c8fd691be0ba6b24ae3f4d655ee33c3eeed32994ccca491f718c9
BLAKE2b-256 checksum
How to use checksums
9e24d91f8773c69813ab7543907b535e1ade3b4388a14817eff5b59c2ca8367c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.6

Release files / piver-0.0.1-py3-none-any.whl

Download URL piver-0.0.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8a037318a1ad5429c04fd76ac8393f4ea21ed23f74f0dc7a81638ab7dc230f3
BLAKE2b-256 checksum
How to use checksums
c547c56c5dadfd3775a470c036abbc316469835db5959276062fdc75fb7fe0a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page