Skip to main content

Read and write configuration values in a WordPress "wp-config.php" file.

Project description



A Python package for reading and writing configuration values in a WordPress wp-config.php file.


A default wp-config.php might look like this:

define( 'DB_NAME', 'database_name_here' );

wpconfigr will help you update the file to:

define( 'SOMETHING_ENTIRELY_NEW', 'garnet' );
define( 'DB_NAME', 'my_blog' );

wpconfigr exposes two functions:

  • set(key, value) will update a property of name key if it exists, otherwise will create it.
  • get(key) will return the value of the property of name key, or None if it doesn't exist.


pip install wpconfigr

Command-line usage

Writing values to wp-config.php

Named parameters:

  • --filename: Full path and filename of the wp-config.php file.
  • --key: Name of the property to create/update.
  • --value: String value to set.
  • --set-true: Set the value to boolean true.
  • --set-false: Set the value to boolean false.
  • --log-level: (Optional) Log level.
python -m wpconfigr --filename  /www/wp-config.php \
                    --key       DB_NAME \
                    --value     my_blog \
                    --log-level info

Reading values from wp-config.php

As above, but do not specify a value (via the --value, --set-true or --set-false arguments).

python -m wpconfigr --filename /www/wp-config.php \
                    --key      DB_NAME

Code usage

To update a string holding wp-config.php content:

from wpconfigr import WpConfigString

config = WpConfigString(config_string)
config.set('DB_NAME', 'my_blog')
updated_config_string = config.content

To directly update a wp-config.php file:

from wpconfigr import WpConfigFile

config = WpConfigFile(filename)
config.set('DB_NAME', 'my_blog')
# File is updated immediately after each property update.

To read a property value:

db_name = config.get('DB_NAME')



wp-configr requires Python 3.x.

Installing dependencies

pip install -e .[dev]

Running tests



v1.4 - 2018-12-06

  • Fixed bug where commented properties were read and updated.

v1.3 - 2018-12-02

  • Added --set-true and --set-false command-line flags.

v1.2 - 2018-12-02

  • No longer re-writes the configuration file if nothing has changed.

v1.1 - 2018-12-02

  • Added logging.
    • Test runs log everything.
    • Running from the command-line logs only CRITICAL by default, but can be overridden with the new optional --log-level argument.
  • Made the documentation a little clearer, and fixed a typo in a code sample.
  • Replaced internal naming references to FRACTIONAL with FLOAT. The word utterly eluded me for v1.0.
  • Fixed some code formatting and Pylint warnings.
  • Ignore coverage HTML reports in source control.

v1.0 - 2018-12-01

  • Initial release.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for wpconfigr, version 1.4
Filename, size File type Python version Upload date Hashes
Filename, size wpconfigr-1.4-py3-none-any.whl (6.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size wpconfigr-1.4.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page