Skip to main content

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

autoconfigpy-0.2.4.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

autoconfigpy-0.2.4-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file autoconfigpy-0.2.4.tar.gz.

File metadata

  • Download URL: autoconfigpy-0.2.4.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for autoconfigpy-0.2.4.tar.gz
Algorithm Hash digest
SHA256 4d79b97af2c10e01e7f97de30bbe97f031b77a3626a11cff444e4e5fe030fa67
MD5 ed72d7486387449bcd73d3417519a265
BLAKE2b-256 82f608ff648e3ac98a0d715bb7edbf2666ea415c0891fe40858abf776686cced

See more details on using hashes here.

File details

Details for the file autoconfigpy-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: autoconfigpy-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for autoconfigpy-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9b43bfc31a903abc7b924bbd96fe55eb18329a1d8c237279ab488389b323ca3d
MD5 7999648dd19a1132426963580a6fb8c3
BLAKE2b-256 02774696fefea485e4086a3ebb60377408db3df2f9820073f89a91ce4ea5a358

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