Search code examples
pythonpypi

Best way to include a user-editable config file in a pypi package?


I have a command-line python script that uses a configuration file. I'm planning to put this on pypi soon.

What is the best general approach for including a default version of the configuration file in the package, so that it is obvious to the end-user where to find it?

One example of a pypi project which includes user-editable config files is Django. In Django, the user has to run a script to initialize a new project. This generates a directory with a bunch of stuff, including the project configuration file. However, this seems like a heavy approach for a simple command line utility like mine.

Another option is requiring the user to specify the location of the config file as a command line arg. I guess this is okay, but it puts the onus on the user to go to the documentation and create the entire config file from scratch.

Is there any better option? Is there any standard practice for this?

Thanks!

-Travis


Solution

  • You could include the defaults as part of your script and then allow the user to change the defaults with either command line arguments or a config file in the user's home directory.

    I don't think the Django approach would work unless you have the concept of a project.

    If this is on Unix I would either put the config file in /etc if the script will be run by more than one user or in the user's home folder as a dotfile. This way the user does not have to specify the config file each time, though you could also have a command line argument that lets the user specify a different config file to use.