Page MenuHomePhabricator

Use configparser or tomllib for config files instead of other Python file
Open, LowestPublicFeature

Description

Proposals

  • rename config2.py to config.py and implement loading all global and user-defined settings
  • global bot settings can be located in pywikibot/config.toml (preferred) or pywikibot/config.ini
  • user-defined settings can be located in user-config.toml (preferred) or user-config.ini
  • script-related settings including L10N can be located in scripts_config.toml (preferred) or scripts_config.ini
  • optionally support user-config.py for backward compatibility, but mark as legacy and remove this ability later
  • drop user-config.py support. This might be a great advantage using PAWS or on toolforge
  • enable site-related settings e.g. from wiki page

Advantages and risks

Feature.toml (preferred).iniuser-config.py (legacy)
Safe from arbitrary code execution✅ Yes✅ Yes❌ No
Risk of malicious logic❌ Minimal❌ Minimal⚠️ High if untrusted input
Parse safety✅ Safe✅ Safe⚠️ Risky (uses exec or eval)
Flexibility / programmability⚠️ Limited (static values only)❌ Limited✅ Full Python power
Nested structures✅ Supported via tables/arrays❌ Very limited✅ Arbitrary
Datatypes support✅ Standardized, type-safe❌ Strings only, must parse✅ Any Python type
Readability / usability✅ Human-readable, structured✅ Easy for simple configs⚠️ Python knowledge required
Automation / CI/CD✅ Easy✅ Easy⚠️ Harder

Disadvantages

  • Python 3.11 or external toml like tomli required for the toml files

Event Timeline

Xqt triaged this task as Lowest priority.May 19 2019, 9:08 AM
Xqt changed the subtype of this task from "Task" to "Feature Request".

Change 511692 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [IMPR] add a new ConfigParserBot class

https://gerrit.wikimedia.org/r/511692

Change 511692 merged by jenkins-bot:
[pywikibot/core@master] [IMPR] add a new ConfigParserBot class

https://gerrit.wikimedia.org/r/511692

Change 731267 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [IMPR] Provide ConfigParserBot for several scripts

https://gerrit.wikimedia.org/r/731267

Change 731267 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] Provide ConfigParserBot for several scripts

https://gerrit.wikimedia.org/r/731267

Xqt renamed this task from Use configparser for config files instead of other variants to Use configparser or tomllib for config files instead of other Python file.Oct 11 2025, 2:16 PM
Xqt updated the task description. (Show Details)