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

Community

Need help, want to report a bug, or have an idea for a new feature?

Join the community Discord for support, updates, bug reports, and suggestions for AutoConfigPy, Easy2D, and other related libraries:

https://discord.gg/BuDs8jVQUP

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.5.tar.gz (14.2 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.5-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: autoconfigpy-0.2.5.tar.gz
  • Upload date:
  • Size: 14.2 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.5.tar.gz
Algorithm Hash digest
SHA256 055846d40dfb12e93acc5b1c05d7999761629ab76135b747233a02f5cb63d497
MD5 83d4d90f0acb7ed75c8bc8fbd4736343
BLAKE2b-256 793ea1fce804a4a7846ccf779d143ec57231be6658acf91e99b9f17b1f173881

See more details on using hashes here.

File details

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

File metadata

  • Download URL: autoconfigpy-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 10.8 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3c042a6b405640bcfbe2868fbfed5af4edcdc419da669d697f64ffa20218ecd6
MD5 8322c12af006d422989685b8c7f5d73a
BLAKE2b-256 bac570838aebb3355fc6975e611f4c3ff5cd4457b4cb24a2c63f87aaac5d6488

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