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:
intfloatboolstr
-
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
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
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 varfile-0.1.0.tar.gz.
File metadata
- Download URL: varfile-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdd4fe02036c169a05860e314236604f38edca65c00eb3e8d59b34b1269a9f44
|
|
| MD5 |
a44dac271764bb7981cbe436e55becc7
|
|
| BLAKE2b-256 |
43c78a64f19e810b3bb04dc17dc300d577a7972f2989af8747ac6c132e57a369
|
File details
Details for the file varfile-0.1.0-py3-none-any.whl.
File metadata
- Download URL: varfile-0.1.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8059acac4545452cb94be7459313c432d13904773f1dd199a20b1bae0126a701
|
|
| MD5 |
d92713c4afe101cf6432c2d21ba9b06a
|
|
| BLAKE2b-256 |
975e967615735ee9eaf017197646ad8f4bbaccfd328e1f96ec7e837ac0cf3957
|