How do I properly set up a python configure page for my project? or What's the best way to create a p

22 Replies, 1102 Views

Subject: What's the best way to create a python configure page for custom settings?

Hey folks!

I'm working on a project and need to set up a python configure page to handle user settings. Not sure if I'm overcomplicating it or missing something obvious.

Do y'all have any go-to methods? Like, should I use configparser, JSON, or something else? Also, how do you make it *easy* for users to edit without breaking stuff?

Kinda stuck here—any tips or examples would be awesome.

Thanks in advance!

(PS: If there's a "standard" way to build a python configure page, pls lmk. I don't wanna reinvent the wheel!)
I'd say JSON is the way to go for a python configure page—super easy to read and edit.

You can use the `json` module to load/save settings, and if you wanna make it user-friendly, throw in some basic validation.

Check out `pydantic` for fancy validation stuff. Works like a charm!
Honestly, configparser is underrated for simple stuff.

If your settings are basic key-value pairs, it’s built-in and does the job. No need to overcomplicate.

But if you’ve got nested configs, yeah, JSON or YAML might be better.
For a python configure page, I’d recommend TOML! It’s human-readable and has great lib support (`tomllib` in Py3.11+).

Plus, it’s what `pyproject.toml` uses, so it’s kinda becoming a standard.

Here’s a quick example:
```python
import tomllib
with open("config.toml", "rb") as f:
config = tomllib.load(f)
```
Why not just use environment variables? `python-dotenv` makes it stupid simple.

Less file editing for users, and it’s super portable.

But if you *need* a file, JSON + `jsonschema` for validation is my go-to.
Dude, if you want a full-blown UI for your python configure page, try `PySimpleGUI`.

You can whip up a settings window in like 20 lines. Users get dropdowns, checkboxes, etc.—no manual file edits.

Game-changer for non-tech users.
YAML fan here! `ruamel.yaml` preserves comments and formatting, so users won’t wreck the file accidentally.

Way cleaner than JSON for complex configs.

Example:
```yaml
# settings.yaml
theme: dark
plugins: [cool, stuff]
```
If you’re worried about users breaking things, maybe split the config into two files:

1. Defaults (read-only, shipped with your app)
2. User overrides (editable)

Merge them at runtime. `configparser` or `json` both work for this.
Wow, thanks for all the suggestions!

I tried JSON + `pydantic` like some of you said, and it’s working great so far.

But now I’m curious—any tips for auto-generating docs from the config? Like, so users know what each setting does without digging into code?

(Also, `PySimpleGUI` looks dope—gonna play with that next!)
For a python configure page, I’d avoid reinventing the wheel.

Django’s settings system is *chef’s kiss*—maybe steal ideas from there?

Or just use `dynaconf` if you want something standalone. Handles multiple formats and env vars.



Users browsing this thread: 1 Guest(s)