Application
The Application class is the core of every Grace bot. It manages configuration, the database engine and session, model discovery, extension discovery, and logging. Every generated project instantiates exactly one Application in bot/__init__.py, alongside the Bot that wraps it.
from grace.application import Application
app = Application()
app.load() # sets the environment and wires up logging, models, and the database
grace.application.Application
Application()
This class is the core of the application In other words, this class that manage the database, the application environment and loads the configurations.
Source code in grace/application.py
32 33 34 35 36 37 38 | |
environment
instance-attribute
environment = 'development'
command_sync
instance-attribute
command_sync = True
watch
instance-attribute
watch = False
metadata
property
metadata
token
property
token
session
property
session
Instantiate the session for querying the database.
config
property
config
client
property
client
extension_modules
property
extension_modules
Generate the extensions modules
has_database
property
has_database
database_infos
property
database_infos
database_exists
property
database_exists
get_extension_module
get_extension_module(extension_name)
Return the extension from the given extension name
Source code in grace/application.py
102 103 104 105 106 107 108 | |
load
load(env=None)
Sets the environment and loads all the component of the application
Source code in grace/application.py
110 111 112 113 114 115 116 117 118 119 | |
load_models
load_models()
Import all models in the bot/models package.
Source code in grace/application.py
121 122 123 124 125 126 | |
load_logs
load_logs()
Source code in grace/application.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
load_database
load_database()
Loads and connects to the database using the loaded config
Source code in grace/application.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
unload_database
unload_database()
Unloads the current database
Source code in grace/application.py
171 172 173 174 175 | |
reload_database
reload_database()
Reload the database. This function can be used in case there's a dynamic environment change.
Source code in grace/application.py
177 178 179 180 181 182 183 184 | |
create_database
create_database()
Creates the database for the current loaded config
Source code in grace/application.py
186 187 188 189 190 191 | |
drop_database
drop_database()
Drops the database for the current loaded config
Source code in grace/application.py
193 194 195 196 197 198 | |
create_tables
create_tables()
Creates all the tables for the current loaded database
Source code in grace/application.py
200 201 202 203 204 205 206 207 208 209 | |
drop_tables
drop_tables()
Drops all the tables for the current loaded database
Source code in grace/application.py
211 212 213 214 215 216 217 218 219 220 | |