Overview
CoroNet uses environment variables to manage sensitive configuration data and customize application behavior. All environment variables should be stored in a.env file in the project root directory.
Required Environment Variables
OPENAI_API_KEY
The OpenAI API key is required for the primary OCR functionality using GPT-4o-mini vision model..env
The application will fail to start if this variable is not set. See the OpenAI Setup guide for instructions on obtaining an API key.
app.py:15
app.py
Optional Environment Variables
Flask Configuration
While not currently exposed as environment variables in the code, you can add these common Flask settings:.env
File Storage Paths
The application automatically creates these directories if they don’t exist:- DATA_PATH:
data/registros.csv- CSV file storing license plate records - UPLOADS_DIR:
uploads/- Directory for uploaded vehicle images
app.py:17-22
app.py
Creating the .env File
Create the file
In your project root directory (where
app.py is located), create a new file named .env:Verify .gitignore
Confirm that You should see
.env is listed in your .gitignore file to prevent accidental commits:*.env in the output.Environment Variable Loading
CoroNet uses thepython-dotenv package to load environment variables from the .env file:
load_dotenv() function:
- Searches for a
.envfile in the current directory and parent directories - Loads all variables into the environment
- Does not override existing environment variables
- Silently fails if no
.envfile is found
Example .env File
Here’s a complete example.env file for CoroNet:
.env
Verifying Configuration
To verify your environment variables are loaded correctly:Security Best Practices
- Never commit
.envfiles - Always keep them in.gitignore - Use strong secret keys - Generate random keys for
SECRET_KEY - Rotate API keys regularly - Update your OpenAI API key periodically
- Limit API key permissions - Use keys with minimal required permissions
- Use different keys per environment - Separate keys for development, staging, and production
- Monitor API usage - Check your OpenAI dashboard for unexpected usage
Troubleshooting
Application won’t start
If you see an error related to the OpenAI client, ensure your.env file:
- Exists in the project root directory (same location as
app.py) - Contains a valid
OPENAI_API_KEYvariable - Has no extra spaces around the
=sign - Has no quotes around the API key value
Environment variables not loading
If variables aren’t being read:- Verify
python-dotenvis installed:pip list | grep dotenv - Check the
.envfile location (should be in project root) - Ensure
load_dotenv()is called before accessing variables - Try specifying the path explicitly:
load_dotenv('.env')
Next Steps
OpenAI Setup
Get your OpenAI API key and configure the model
Tesseract Setup
Install Tesseract OCR for fallback text extraction
