Skip to main content

The key-value file format with sections

Project description

License: MIT PyPI package version Downloads

KvF

The key-value file format with sections

Overview

A config file (config.kvf) with sections encoded with the Paradict text format:

# this comment is part of the
# unnamed section

[section 1]
id = 42
name = 'alex'
books = (dict)
    sci-fi = (list)
        'book 1'
        'book 2'
    thriller = (list)
        'book 3'

Reading a config file:

import kvf


MY_CONFIG = {"section 1": {"id": 42,
                           "name": "alex",
                           "books": {"sci-fi": ["book 1", 
                                                "book 2"],
                                     "thriller": ["book 3"]}}}


# read a config file
my_config = kvf.get_config("/path/to/config.kvf")
# my_config is a dictionary object.
# Each key-value item of the dict represents
# a section where the key is the header (string)
# and the value is the body (dictionary) 


# test
assert my_config["section 1"] == MY_CONFIG["section 1"]


# load the config from a file object
with open("path/to/config.kvf", "r", encoding="utf-8") as file:
    my_config = kvf.load(file)

    
# test
assert my_config["section 1"] == MY_CONFIG["section 1"]

Writing a config file:

import kvf


MY_CONFIG = {"section 1": {"id": 42,
                           "name": "alex",
                           "books": {"sci-fi": ["book 1", 
                                                "book 2"],
                                     "thriller": ["book 3"]}}}


# write a config file
kvf.put_config(MY_CONFIG, "path/to/config.kvf")


# write config to a file object
with open("/path/to/config.kvf", "w", encoding="utf-8") as file:
    kvf.dump(MY_CONFIG, file)

Testing and contributing

Feel free to open an issue to report a bug, suggest some changes, show some useful code snippets, or discuss anything related to this project. You can also directly email me.

Setup your development environment

Following are instructions to setup your development environment

# create and activate a virtual environment
python -m venv venv
source venv/bin/activate

# clone the project then change into its directory
git clone https://github.com/pyrustic/kvf.git
cd kvf

# install the package locally (editable mode)
pip install -e .

# run tests
python -m tests

# deactivate the virtual environment
deactivate

Back to top

Installation

KvF is cross-platform. It is built on Ubuntu and should work on Python 3.5 or newer.

Create and activate a virtual environment

python -m venv venv
source venv/bin/activate

Install for the first time

pip install kvf

Upgrade the package

pip install kvf --upgrade --upgrade-strategy eager

Deactivate the virtual environment

deactivate

Back to top

About the author

Hello world, I'm Alex, a tech enthusiast ! Feel free to get in touch with me !




Back to top

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

kvf-0.0.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

kvf-0.0.3-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file kvf-0.0.3.tar.gz.

File metadata

  • Download URL: kvf-0.0.3.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for kvf-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f4885b1bbe66c8c20fdabe5cedeb3c0e5d12a54ac495f9e5fcf6fed0e0c51b73
MD5 1c983403b6aa78a09459af04a1624d60
BLAKE2b-256 9cf8e1826c156d4f97cf4662a6110cbbcfd91b5e5570c8a88bf0a8270718621e

See more details on using hashes here.

File details

Details for the file kvf-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: kvf-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for kvf-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9d666e51cae512e3f95c55b77524e34d0095b278c81f96f7bbc7d37b5bd545c6
MD5 a5eda742e06fd6dbf8bbcc0c0e801cd8
BLAKE2b-256 a8db4a8d3b1fef45cabcadf36f9a2231b2cde3dddd3a58ab1723119c7fbce34f

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