-
Notifications
You must be signed in to change notification settings - Fork 0
Environments
This Wiki page is used to describe our best practices for setting up environments for our scripts to run against.
- We follow the Twelve Factor App guidelines, specifically the Config section for environment management
-
Use virtual environments where possible. See Python Virtual Environments: A Primer for a good introduction on how to set up a virtual environment using your IDE of choice.
-
Use python-dotenv to create 3 .env files: .env.dev, .env.test, and .env.prod. In each, the following should be included:
- as_un=archivesspace_username
- as_pw=archivesspace_password
- as_uri=url_to_archivesspace_production_api_8089 OR ASPACE_API=url_to_archivesspace_test_api_8089 OR ASPACE_API=url_to_archivesspace_dev_api_4567
-
Previously, we used a secrets.py file to keep track login credentials and test/production URLs for connecting to the ArchivesSpace API. The following are typically included in secrets.py:
- as_un = "archivesspace_username"
- as_pw = "archivesspace_pw"
- as_api_prod = "url_to_archivesspace_production_api_8089"
- as_api_stag = "url_to_archivesspace_test_api_8089"
-
Additional credentials you can include in the .env files to connect to the ArchivesSpace database include:
- db_un = "archivesspace_test_database_username"
- db_pw = "archivesspace_test_database_pw"
- db_host = "archivesspace_test_database_hostname"
- db_name = "archivesspace_test_database_name"
- db_port = "archivesspace_test_database_port_number"
- venv
- python-dotenv (preferred)
To import and set a default environment variable, use the following:
from dotenv import find_dotenv, load_dotenv
# Find and load environment-specific .env file
env_file = find_dotenv(f'.env.{os.getenv("ENV", "dev")}')
load_dotenv(env_file)
archivesspace_instance = ArchivesSpace(os.getenv('as_api'), os.getenv('as_un'), os.getenv('as_pw'))