Simple JSON config and data storage for Python apps, games, bots, tools, and servers.
Project description
AutoConfigPy
AutoConfigPy is a small Python library for JSON config files and simple game/app data.
It is made for Python apps, games, launchers, bots, tools, and servers where you want clean settings and save files without rewriting JSON boilerplate every time.
Install
For local testing from this folder:
pip install -e .
After publishing to PyPI:
pip install autoconfigpy
Fast Data API
This is the simple API for saving player coins, usernames, settings, and other small data.
from autoconfigpy import write_data, read_data, add_data
write_data("data/players.json", "players.alex.coins", 100)
add_data("data/players.json", "players.alex.coins", 50)
coins = read_data("data/players.json", "players.alex.coins", 0)
print(coins) # 150
That automatically creates data/players.json:
{
"players": {
"alex": {
"coins": 150
}
}
}
DataFile API
Use DataFile when you want to keep using the same JSON file.
from autoconfigpy import DataFile
players = DataFile("data/players.json")
players.write("players.alex.username", "Alex")
players.write("players.alex.coins", 100)
players.add("players.alex.coins", 25)
players.subtract("players.alex.coins", 10)
print(players.read("players.alex.coins", 0))
print(players.exists("players.alex.username"))
Config API
Use Config for app settings and more controlled config files.
from autoconfigpy import Config
cfg = Config("settings.json", defaults={
"app.name": "My App",
"window.width": 900,
"window.height": 600,
"theme": "dark",
"volume": 80,
})
print(cfg.get("app.name"))
print(cfg.get("window.width"))
cfg.set("theme", "light")
cfg.set("player.coins", 250)
cfg.save()
Features
- Auto-creates missing JSON files
- Auto-creates missing folders
- Dot-path keys like
player.coins - Read, write, add, subtract, delete, and exists helpers
- Defaults that do not overwrite user settings
- Required keys
- Backups
- Environment variable loading
- Autosave mode
- Reset one key or the whole config
- Dictionary-style access
- No required dependencies
Examples
Run these from the project folder:
python examples/player_coins.py
python examples/basic_usage.py
python examples/server_config.py
python examples/quick_data_store.py
Test
python -m unittest discover tests
Build for PyPI
Install build tools:
python -m pip install --upgrade build twine
Build the package:
python -m build
Check it:
python -m twine check dist/*
Upload to TestPyPI first:
python -m twine upload --repository testpypi dist/*
Then upload to real PyPI:
python -m twine upload dist/*
Important before publishing
Open pyproject.toml and change the GitHub links if your repository URL is different.
If PyPI says the name is taken, change this line:
name = "autoconfigpy"
For example:
name = "autoconfigpy-alex"
The import can still stay:
from autoconfigpy import Config
License
MIT
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
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 autoconfigpy-0.2.0.tar.gz.
File metadata
- Download URL: autoconfigpy-0.2.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d33ccbf20076a581d308efa19826da560d8d38a68d7171246a06871845fd63c2
|
|
| MD5 |
06d2c3790a5fea0c77172e02cad66e22
|
|
| BLAKE2b-256 |
0d9d4aeaeccc4f504694eeb9a37b92c874175a6d128475ef4ef822ea7d1d9460
|
File details
Details for the file autoconfigpy-0.2.0-py3-none-any.whl.
File metadata
- Download URL: autoconfigpy-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
337646118ac4c140c173658e5257b9badaa242640e872d2f2fbccd975a909e8e
|
|
| MD5 |
901058d69717e0763bd276917477e8aa
|
|
| BLAKE2b-256 |
4e0dfe3a02a2360239f22db75abd71afda68e3632f105f69c34c4ea7321e5db4
|