gramex
¶
Parses command line / configuration and runs Gramex.
Running gramex
on the command line calls:
- gramex.commandline to parse command line arguments
- gramex.init to parse the configuration and start Gramex
This module also has
- gramex.shutdown to shut down Gramex (e.g. on
Ctrl+C
) - gramex.gramex_update to check if Gramex is out of date
- gramex.log to log messages persistently (e.g. on ElasticSearch)
commandline(args=None)
¶
Run Gramex from the command line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
List[str]
|
Command line arguments. If not provided, uses |
None
|
Gramex can be run in 2 ways, both of which call gramex.commandline:
python -m gramex
, which runs__main__.py
.gramex
, which runsconsole_scripts
insetup.py
gramex -V
and gramex --version
exit after printing the Gramex version.
The positional arguments call different functions:
gramex
runs Gramex and calls gramex.initgramex init
creates a new Gramex project and calls gramex.install.initgramex service
creates a Windows service and calls gramex.install.service- … etc. (Run
gramex help
for more)
Keyword arguments are passed to the function, e.g.
gramex service install --startup=auto
calls
gramex.install.service('install', startup='auto')
.
Keyword arguments with ‘.’ are split into sub-keys, e.g.
gramex --listen.port 80
becomes init(listen={"port": 80})
.
Values are parsed as YAML, e.g. null
becomes None
.
If the keyword arguments include --help
, it prints the usage of that function and exits.
Source code in gramex\__init__.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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 |
|
init(force_reload=False, kwargs)
¶
Load Gramex configurations and start / restart the Gramex instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reload |
bool
|
Reload services even config hasn’t changed |
False
|
**kwargs |
dict
|
Overrides config |
{}
|
gramex.init()
loads configurations from 3 sources, which override each other:
- Gramex’s
gramex.yaml
- Current directory’s
gramex.yaml
- The
kwargs
Then it calls each gramex.services with its configuration.
It can be called multiple times. For efficiency, a services function is called only if its
configuration has changed or force_reload=True
.
If a kwarg value is:
- a string, it’s loaded as-is
- a Path pointing to a file, it’s loaded as a YAML config file
- a Path pointing to a directory, it loads a
gramex.yaml
file from that directory
Source code in gramex\__init__.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
shutdown()
¶
Shut down the running Gramex instance.
Source code in gramex\__init__.py
322 323 324 325 326 327 328 329 330 |
|
gramex_update(url)
¶
Check if a newer version of Gramex is available. If yes, log a warning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
URL to check for new version |
required |
Gramex uses https://gramener.com/gramex-update/ as the URL to check for new versions.
Source code in gramex\__init__.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
log(args, kwargs)
¶
Logs structured information for future reference.
Examples:
>>> gramex.log(level='INFO', x=1, msg='abc')
This logs {level: INFO, x: 1, msg: abc}
into a logging queue.
If a gramexlog
service like ElasticSearch has been configured, it will periodically flush
the logs into the server.
Source code in gramex\__init__.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
console(msg)
¶
Write message to console. An alias for print().
Source code in gramex\__init__.py
416 417 418 |
|