How to separate development and production in python

Viewed 338

I am developing a Python application to automate my tasks, I would like to have two separate environments, development and production, and in the future maybe a Web app environment or a CLI tool environment.

The development phase for example has modules for unit testing and API keys that I don't want to be shipped to production. Is it possible to have a package.json equivalent that can help me?

I also want to define the entry file that has to be executed first, which is main.py for my project, can this be achieved?

1 Answers

For package.json equivalents: You can define different requirements.txt files for development and production. For example, requirements.prod.txt and requirements.dev.txt. Inside the dev requirements, you can actually define the prod requirements by placing -r requirements.prod.txt inside the requirements.dev.txt. This way, development requirements will include all the production packages, plus something else for e.g. testing purposes.

For API keys: I would create a .ini file for production and development and take care of only shipping the production version to production. In the code, you can primarily read the development .ini file, and only use the production one if development version does not exist. This way it is easier for the prod.ini and dev.ini config files to coexist in the project folder. When there is no dev.ini in production, prod.ini will be used.

You can define the entry point in your script by running python main.py, please elaborate what you meant with this.

If you need more info, please comment so I can modify my answer.

Related