Simple JSON config and data storage for Python apps, games, bots, tools, and servers.
Project description
# AutoConfigPy
AutoConfigPy is a lightweight JSON config and data-storage library for Python apps, games, bots, tools, and servers.
It automatically handles creating folders, creating JSON files, reading data, writing data, adding numbers, incrementing values, appending list items, removing list items, backups, defaults, and update checks.
## Installation
```bash
pip install autoconfigpy
Quick Example
from autoconfigpy import DataFile
data = DataFile("data/players.json")
data.write("players.player1.coins", 100)
data.add("players.player1.coins", 50)
data.increment("players.player1.level")
data.append("players.player1.inventory", "gold_sword")
data.append("players.player1.inventory", "health_potion")
data.remove("players.player1.inventory", "health_potion")
print(data.read("players.player1.coins", 0))
print(data.read("players.player1.level", 1))
print(data.read("players.player1.inventory", []))
Output:
150
1
['gold_sword']
Created JSON:
{
"players": {
"player1": {
"coins": 150,
"level": 1,
"inventory": [
"gold_sword"
]
}
}
}
DataFile Usage
DataFile is the easiest way to work with one JSON file.
from autoconfigpy import DataFile
data = DataFile("data/save.json")
data.write("game.score", 100)
data.add("game.score", 25)
data.subtract("game.score", 10)
score = data.read("game.score", 0)
print(score)
Function-Style Usage
You can also use AutoConfigPy without creating a DataFile object.
from autoconfigpy import write_data, read_data, add_data, append_data
write_data("data/players.json", "players.player1.coins", 100)
add_data("data/players.json", "players.player1.coins", 25)
append_data("data/players.json", "players.player1.inventory", "gold_sword")
coins = read_data("data/players.json", "players.player1.coins", 0)
print(coins)
Output:
125
Config Usage
Use Config when you want defaults, required keys, environment loading, backups, and manual save control.
from autoconfigpy import Config
cfg = Config("settings.json", defaults={
"window.width": 1280,
"window.height": 720,
"theme": "dark",
})
print(cfg.get("window.width"))
cfg.set("theme", "light")
cfg.save()
Created JSON:
{
"window": {
"width": 1280,
"height": 720
},
"theme": "light"
}
Lists
AutoConfigPy can manage lists inside JSON files.
from autoconfigpy import DataFile
data = DataFile("data/save.json")
data.append("player.inventory", "sword")
data.append("player.inventory", "shield")
data.remove("player.inventory", "shield")
print(data.read("player.inventory", []))
Output:
['sword']
Backups
from autoconfigpy import Config
cfg = Config("settings.json")
backup_path = cfg.backup()
print(backup_path)
Required Keys
from autoconfigpy import Config
cfg = Config("settings.json")
api_key = cfg.require("api.key")
If the key is missing, AutoConfigPy raises an error.
Update Check
AutoConfigPy can check PyPI and tell the user if a newer version is available.
from autoconfigpy import check_for_updates
check_for_updates()
Example output when an update exists:
Update available for autoconfigpy: 0.2.1 -> 0.2.2
Run: python -m pip install --upgrade autoconfigpy
Example output when current:
autoconfigpy is up to date. Current version: 0.2.2
This does not install updates automatically. It only tells the user what command to run.
License
AutoConfigPy is released under the MIT License.
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.3.tar.gz.
File metadata
- Download URL: autoconfigpy-0.2.3.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37dccf6d20a266f04ad0f0384065a6c37bada5e4938268a3b356e3385b5618b2
|
|
| MD5 |
8f0375e14a21c64604e57abb91e95a4d
|
|
| BLAKE2b-256 |
bfa9d7423c2e5be33e35e5b7aa5da7b294210fd07c887e0d65268014fe77fabc
|
File details
Details for the file autoconfigpy-0.2.3-py3-none-any.whl.
File metadata
- Download URL: autoconfigpy-0.2.3-py3-none-any.whl
- Upload date:
- Size: 10.1 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 |
96ba74073db1c092d28549953d96b3bcffe95b1a8a354698c6c74ab467f3c4cc
|
|
| MD5 |
6bf696e2868101a34aaf9788cc9d7a6d
|
|
| BLAKE2b-256 |
ef32458f2c9366f1e9cd390099c2f292e1bd63134f69e6727070056626509a9a
|