Add .env Support to Manage Script and WSGI Application Module #3460

Closed
opened 2025-12-29 18:29:19 +01:00 by adam · 3 comments
Owner

Originally created by @dstarner on GitHub (Mar 11, 2020).

Environment

  • Python version: 3.7
  • NetBox version: 2.7.10

Proposed Functionality

Add automatic support for reading from a .env file, if present in the root directory of the project. Most likely using the python-dotenv module.

Use Case

This would make it much easier to develop and test locally as it provides a simple, top-level interface that manages all the available configuration. .env files are easier to add quick overrides than in the nested netbox/configuration.py file and I prefer using it over going into the django settings so that I can have one consistent configuration.py file that just reads from the environment, instead of needing different versions for different connection variations.

Database Changes

None!

External Dependencies

https://github.com/theskumar/python-dotenv would be added to assist in loading the environment.

Originally created by @dstarner on GitHub (Mar 11, 2020). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for proposing specific new features or enhancements. If you have a general idea or question, please post to our mailing list instead of opening an issue: https://groups.google.com/forum/#!forum/netbox-discuss NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.7 * NetBox version: 2.7.10 <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality Add automatic support for reading from a `.env` file, if present in the root directory of the project. Most likely using the [`python-dotenv`](https://github.com/theskumar/python-dotenv) module. <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case This would make it much easier to develop and test locally as it provides a simple, top-level interface that manages all the available configuration. `.env` files are easier to add quick overrides than in the nested `netbox/configuration.py` file and I prefer using it over going into the django settings so that I can have one consistent `configuration.py` file that just reads from the environment, instead of needing different versions for different connection variations. <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes None! <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies https://github.com/theskumar/python-dotenv would be added to assist in loading the environment.
adam closed this issue 2025-12-29 18:29:19 +01:00
Author
Owner

@jeremystretch commented on GitHub (Mar 11, 2020):

Why not just modify your configuration.py to read environment variables?

@jeremystretch commented on GitHub (Mar 11, 2020): Why not just modify your `configuration.py` to read environment variables?
Author
Owner

@dstarner commented on GitHub (Mar 11, 2020):

We do that already, and thats one of the use cases for implementing this. Then a user could define values in .env and read them via os.getenv calls in the configuration.py file. Without reading .env you need to prefix each manage.py call or container with the list of environment variables desired.

@dstarner commented on GitHub (Mar 11, 2020): We do that already, and thats one of the use cases for implementing this. Then a user could define values in `.env` and read them via `os.getenv` calls in the `configuration.py` file. Without reading `.env` you need to prefix each `manage.py` call or container with the list of environment variables desired.
Author
Owner

@jeremystretch commented on GitHub (Mar 13, 2020):

But you could just direct your configuration.py to read from a specific file.

The system we have in place for configuration is well-established and IMO plenty flexible. I'd rather not commit resources to implementing, documenting, and testing an abstraction layer around it, particularly if it is of little value to regular users.

@jeremystretch commented on GitHub (Mar 13, 2020): But you could just direct your `configuration.py` to read from a specific file. The system we have in place for configuration is well-established and IMO plenty flexible. I'd rather not commit resources to implementing, documenting, and testing an abstraction layer around it, particularly if it is of little value to regular users.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3460