Skip to main content

A simple parser for .var variable files with object-mapping support

Project description

varfile

varfile is a fast, lightweight, zero-dependency Python library for working with .var configuration files. It combines the simplicity of INI-style configs with Python-friendly object access, automatic type conversion, and easy file editing.

Features

  • Dot Notation Access Access configuration values naturally:

    config.Database.host
    

    instead of:

    config["Database"]["host"]
    
  • Automatic Type Conversion Values are automatically converted to the appropriate Python types:

    • int
    • float
    • bool
    • str
  • Easy Editing Modify values directly in memory and save them back to disk with a single command.

  • Robust Parsing Handles comments, special characters, URLs containing #, and other common edge cases.

  • Clean Serialization Preserves formatting conventions such as lowercase booleans (true / false) when writing files.


Installation

Install with pip:

pip install varfile

Or with uv:

uv add varfile

or

uv pip install varfile

Quick Start

1. Create a .var File

Create a file named demo.var:

# Global settings
app_name = "Varfile Demo"
environment = "development"
debug_mode = true
max_users = 150

[Database]
host = "127.0.0.1"
port = 5432
timeout = 45.8
enabled = false
url = "https://varfiletest.com/#user1"

2. Read Configuration Values

Load a file and access values using dot notation:

import varfile

config = varfile.load("demo.var")

print(config.app_name)          # Varfile Demo
print(config.max_users)         # 150
print(config.Database.port)     # 5432
print(config.Database.enabled)  # False

3. Modify and Save Values

Update values in memory and write them back to the file:

import varfile

config = varfile.load("demo.var")

config.max_users = 100
config.Database.port = 5000

varfile.dump(config, "demo.var")

print("Configuration updated successfully!")

4. Create a Configuration From Scratch

You can also build configuration files programmatically:

import varfile

config = varfile.VarConfig()

config.new_setting = "Hello World"
config.user_count = 1

config.FeatureToggle = {
    "dark_mode": True,
    "beta_tester": False
}

varfile.dump(config, "new_config.var")

Generated new_config.var:

new_setting = "Hello World"
user_count = 1

[FeatureToggle]
dark_mode = true
beta_tester = false

API Reference

Function / Class Description
varfile.load(filepath) Load a .var file from disk and return a VarConfig object.
varfile.dump(config, filepath) Save a VarConfig object to a .var file.
varfile.loads(string_data) Parse .var content from a string.
varfile.dumps(config) Convert a configuration object into .var formatted text.
varfile.VarConfig() Create a new empty configuration container with dot notation support.

Why varfile?

Many configuration formats are either too limited or unnecessarily complex. varfile aims to provide a middle ground:

  • Easy to read
  • Easy to edit
  • Python-friendly
  • No external dependencies
  • Clean object-style access

Whether you're building a small script or a larger application, varfile keeps configuration management simple.

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

varfile-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

varfile-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file varfile-0.1.1.tar.gz.

File metadata

  • Download URL: varfile-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for varfile-0.1.1.tar.gz
Algorithm Hash digest
SHA256 49ddd22e9228f87a91d603427f31e7b197dbe8fd3483981c1c61e14bebc43ecb
MD5 f7f87e5dd48b7cfd7051a2132da2d9b5
BLAKE2b-256 75604273be3c5efaa2521dc76eaa177f3dbd175993f7f3ef701f726c101b4339

See more details on using hashes here.

File details

Details for the file varfile-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: varfile-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for varfile-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 811eb2b93a94b7f64cf9855f80d36d6c1a2dc749ef278c395f7f20e63b008fdd
MD5 c39d30f270d0db60c1bc7b35a55cdb87
BLAKE2b-256 1c9bbc856f9097143f3f29fd1d49717552b362601008223b51fba8a263b5a238

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