Configuration
The SDK and CLI read settings from environment variables. They can be set in the
shell or stored in a .env file that the CLI loads automatically via
dotenv.load_dotenv().
Environment Variables
Variable |
Description |
Default |
|---|---|---|
IMEDNET_API_KEY |
API key used for authentication. |
None |
IMEDNET_SECURITY_KEY |
Security key used for authentication. |
None |
IMEDNET_BASE_URL |
Optional base URL for private deployments. |
None |
IMEDNET_STUDY_KEY |
Study identifier used by examples and some tests. |
None |
IMEDNET_RUN_E2E |
Set to |
None |
IMEDNET_BATCH_ID |
Batch identifier used by job polling tests. Created automatically if unset. |
None |
IMEDNET_FORM_KEY |
Form key for record-creation tests. If unset, the first form is used. |
None |
IMEDNET_ALLOW_MUTATION |
Set to |
None |
Using a .env File
You can create a .env file in the project root to store these variables.
A template is provided in .env.example:
cp .env.example .env
Edit the file to add your keys:
IMEDNET_API_KEY=your_api_key
IMEDNET_SECURITY_KEY=your_security_key
IMEDNET_BASE_URL=https://edc.prod.imednetapi.com
The CLI loads this file automatically. Other scripts can call
dotenv.load_dotenv() to mimic this behaviour.
Parsing Values
When reading environment variables or other untyped values, use helpers from
imednet.utils.validators such as
imednet.utils.validators.parse_bool(),
imednet.utils.validators.parse_datetime(),
imednet.utils.validators.parse_int_or_default(),
imednet.utils.validators.parse_str_or_default(),
imednet.utils.validators.parse_list_or_default(), and
imednet.utils.validators.parse_dict_or_default().
>>> from imednet.utils.validators import (
... parse_bool,
... parse_datetime,
... parse_int_or_default,
... parse_str_or_default,
... parse_list_or_default,
... parse_dict_or_default,
... )
>>> parse_bool("yes")
True
>>> parse_datetime("2020-01-01T00:00:00Z").year
2020
>>> parse_int_or_default("bad", default=5)
5
>>> parse_str_or_default(1.23)
'1.23'
>>> parse_list_or_default("x")
['x']
>>> parse_dict_or_default(None)
{}
Troubleshooting
Missing required environment variable(s)
If you see an error like Error: IMEDNET_API_KEY and IMEDNET_SECURITY_KEY environment variables must be set. (CLI) or API key and security key are required (SDK), or an “Unauthorized” API error, ensure you have set these variables in your shell or in a .env file in the directory where you run the script. See Using a .env File for details.