Configuration
Config ¶
This is a generic config class that can be extended by other classes. Map environment variables to class fields according to these rules:
- Field won't be parsed unless it has a type annotation
- Field will be skipped if not in all caps
- Class field and environment variable name are the same
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env
|
Mapping[str, Any]
|
A mapping of environment variables. |
required |
Raises:
Type | Description |
---|---|
AppConfigError
|
Required fields are not provided |
AppConfigError
|
Provided value for field does not match with the specified data type |
Source code in JPS_BASE_LIB/python_wrapper/twa/conf/agent_conf.py
AgentConfig ¶
Bases: Config
Configuration class for the DerivationAgent. This class is a subclass of Config and provides custom configurations for developed agents. It includes various fields to configure the agent's behavior and connectivity.
Attributes:
Name | Type | Description |
---|---|---|
DERIVATION_PERIODIC_TIMESCALE |
int
|
The time scale of the periodic job that monitors asynchronous derivations. |
DERIVATION_INSTANCE_BASE_URL |
str
|
The base URL of the derivation instances that to be created by this agent. |
SPARQL_QUERY_ENDPOINT |
str
|
The SPARQL endpoint to be used for querying the knowledge graph. |
SPARQL_UPDATE_ENDPOINT |
str
|
The SPARQL endpoint to be used for updating the knowledge graph. |
KG_USERNAME |
str
|
The username to access the SPARQL endpoint. |
KG_PASSWORD |
str
|
The password to access the SPARQL endpoint. |
FILE_SERVER_ENDPOINT |
str
|
The endpoint of the file server. |
FILE_SERVER_USERNAME |
str
|
The username to access the file server. |
FILE_SERVER_PASSWORD |
str
|
The password to access the file server. |
ONTOAGENT_OPERATION_HTTP_BASE_URL |
str
|
The URL of the OntoAgent:Operation HTTP endpoint. |
REGISTER_AGENT |
bool
|
Whether to register the OntoAgent instance of the configured agent to knowledge graph. |
MAX_THREAD_MONITOR_ASYNC_DERIVATIONS |
int
|
The maximum number of thread can be invoked to monitor async derivations at the same time, the default value is 1. |
EMAIL_RECIPIENT |
str
|
The list of recipients of email notifications during agent operation, multiple email address should be seperated by semicolon, e.g. foo.1@bar.com;foo.2@bar.com. |
EMAIL_SUBJECT_PREFIX |
str
|
The subject prefix for email notifications, "[] " is automatically added, e.g. the prefix will be "[YourAgent] " if "YourAgent" is specified. |
EMAIL_USERNAME |
str
|
The username of the email sender, note that a gmail account is required. |
EMAIL_AUTH_JSON_PATH |
str
|
The json file path to the OAuth2 file of the gmail account defined by EMAIL_USERNAME. |
EMAIL_START_END_ASYNC_DERIVATIONS |
bool
|
The boolean flag to choose whether to send email notification at the start and end of process an async derivation, the default value is False. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env
|
Mapping[str, Any]
|
A mapping of environment variables. |
required |
Raises:
Type | Description |
---|---|
AppConfigError
|
Required fields are not provided |
AppConfigError
|
Provided value for field does not match with the specified data type |
Source code in JPS_BASE_LIB/python_wrapper/twa/conf/agent_conf.py
config_generic ¶
Load and return the configuration for the specified configuration class from either environment variables or a specified environment file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf_cls
|
Type[Config]
|
The configuration class to instantiate. |
required |
env_file
|
str
|
The path to a dotenv (.env) file containing environment variables. If not provided, environment variables will be loaded from the system environment. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Config |
Config
|
An instance of the provided configuration class, populated with environment variables. |
Raises:
Type | Description |
---|---|
AppConfigError
|
If required configuration fields are missing or cannot be cast to the specified types. |
Examples:
# Load configuration from a .env file
config = config_generic(MyConfigClass, env_file=".env")
# Load configuration from system environment variables
config = config_generic(MyConfigClass)
Note
The function prioritizes loading environment variables from the provided env_file if specified. Otherwise, it defaults to using the system environment variables.
Source code in JPS_BASE_LIB/python_wrapper/twa/conf/agent_conf.py
config_derivation_agent ¶
config_derivation_agent(env_file: str = None) -> AgentConfig
Load and return the configuration for the DerivationAgent from either environment variables or a specified environment file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env_file
|
str
|
The path to a dotenv file containing environment variables. If not provided, environment variables will be loaded from the system environment. |
None
|
Returns:
Name | Type | Description |
---|---|---|
AgentConfig |
AgentConfig
|
An instance of the AgentConfig class, populated with environment variables. |
Raises:
Type | Description |
---|---|
AppConfigError
|
If required configuration fields are missing or cannot be cast to the specified types. |
Examples:
# Load configuration from a .env file
config = config_derivation_agent(env_file=".env")
# Load configuration from system environment variables
config = config_derivation_agent()
Note
The function prioritizes loading environment variables from the provided env_file if specified. Otherwise, it defaults to using the system environment variables.