config¶
>>> from ncal.config import load_settings
>>> configuration = load_settings(
... notion_api_token="secret_123456",
... database_id="1234567",
... url_root="https://www.notion.so/exampleuser/afeeec3434177a5aefde223455?v=1462bb2343466546ae54e&p=",
... )
>>> type(configuration)
<class 'ncal.config.Settings'>
>>> configuration.default_calendar_name
'Notion Events'
Functions and classes to manage configuration are in this file.
Configuration can operate through toml, .env, environment variables, or the command line.
Settings
¶
Bases: pydantic.BaseModel
Class for storing settings.
Attributes:
Name | Type | Description |
---|---|---|
notion_api_token |
str
|
API token for Notion integration |
credentials_location |
Path
|
file containing GCal User Credentials |
database_id |
str
|
ID of the Notion database |
Source code in ncal/config.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
env_var_names_dict(prefix)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix |
str
|
string to add to the start of each environment variable name |
required |
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dict[str, str]: A dictionary in the form of |
>>> env_var_names_dict("PREFIX_")
{'notion_api_token': 'prefix_notion_api_token', 'database_id': 'prefix_database_id', 'url_root': 'prefix_url_root', 'credentials_location': 'prefix_credentials_location', 'client_secret_location': 'prefix_client_secret_location', 'default_event_length': 'prefix_default_event_length', 'timezone': 'prefix_timezone', 'default_event_start': 'prefix_default_event_start', 'all_day_event_option': 'prefix_all_day_event_option', 'default_calendar_id': 'prefix_default_calendar_id', 'default_calendar_name': 'prefix_default_calendar_name', 'delete_option': 'prefix_delete_option', 'task_notion_name': 'prefix_task_notion_name', 'date_notion_name': 'prefix_date_notion_name', 'initiative_notion_name': 'prefix_initiative_notion_name', 'initiative_notion_type': 'prefix_initiative_notion_type', 'extrainfo_notion_name': 'prefix_extrainfo_notion_name', 'on_gcal_notion_name': 'prefix_on_gcal_notion_name', 'need_gcal_update_notion_name': 'prefix_need_gcal_update_notion_name', 'gcal_event_id_notion_name': 'prefix_gcal_event_id_notion_name', 'lastupdatedtime_notion_name': 'prefix_lastupdatedtime_notion_name', 'calendar_notion_name': 'prefix_calendar_notion_name', 'current_calendar_id_notion_name': 'prefix_current_calendar_id_notion_name', 'delete_notion_name': 'prefix_delete_notion_name', 'calendar_dictionary': 'prefix_calendar_dictionary'}
Source code in ncal/config.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
get_env_vars_case_insensitive(env_var_names)
¶
Get environment variables matching the given dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env_var_names |
Dict[str, str]
|
{desired label: environment variable label} |
required |
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Dictionary of environment variables |
Source code in ncal/config.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
load_config_file(path_to_file)
¶
Load a toml config file into a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_to_file |
Path
|
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Settings (unfiltered) |
Source code in ncal/config.py
101 102 103 104 105 106 107 108 109 110 111 |
|
load_settings(config_file_path=None, *, use_env_vars=True, use_toml_file=True, **kwargs)
¶
Load settings from multiple sources.
This function falls back to defaults, so only a few settings are required. Priority (high-low): cli, env, config_file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_file_path |
Optional[Path]
|
Path to a .toml config file |
None
|
use_env_vars |
bool
|
True
|
|
use_toml_file |
bool
|
True
|
|
**kwargs |
Any
|
Other settings to provide to the Settings object |
{}
|
Returns:
Type | Description |
---|---|
Settings
|
A ncal.config.Settings object |
Source code in ncal/config.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|