Configure uWSGI from your Python code
Project description
https://github.com/idlesign/uwsgiconf
Description
Configure uWSGI from your Python code
If you think you know uWSGI you’re probably wrong. It is always more than you think it is. There are so many subsystems and options (800+) it is difficult to even try to wrap your mind around.
uwsgiconf allowing to define uWSGI configurations in Python tries to improve things the following ways:
It structures options for various subsystems using classes and methods;
It uses docstrings and sane naming to facilitate navigation;
It ships some useful presets to reduce boilerplate code;
It encourages configuration reuse;
It comes with CLI to facilitate configuration;
It features easy to use and documented uwsgi stub Python module;
It offers runtime package, similar to uwsgidecorators, but with more abstractions;
It features integration with Django Framework;
It is able to generate configuration files for Systemd, Upstart.
It can use pyuwsgi.
Consider using IDE with autocompletion and docstings support to be more productive with uwsgiconf.
By that time you already know that uwsgiconf is just another configuration method. Why?
Overview
Static configuration
Let’s make uwsgicfg.py. There we configure uWSGI using nice PythonSection preset to run our web app.
from uwsgiconf.config import configure_uwsgi
from uwsgiconf.presets.nice import PythonSection
def get_configurations():
"""This should return one or more Section or Configuration objects.
In such a way you can configure more than one uWSGI instance in the same place.
Here we'll define just one configuration section, which
will instruct uWSGI to serve WSGI application (from wsgi.py module)
on http://127.0.0.1:8000. We use .bootstrap shortcut method
to construct our configuration section object.
"""
return PythonSection.bootstrap('http://127.0.0.1:8000', wsgi_module='/home/idle/myapp/wsgi.py')
# Almost done. One more thing:
configure_uwsgi(get_configurations)
Now if you want to generate myconf.ini file and use it for uWSGI manually you can do it with:
$ uwsgiconf compile > myconf.ini $ uwsgi myconf.ini
Or use uwsgiconf to automatically spawn uWSGI processes for configurations defined in your module:
$ uwsgiconf run
Note: uwsgiconf CLI requires click package available (can be installed with uwsgiconf).
Runtime configuration
uwsgiconf comes with runtime package which is similar to uwsgidecorators but offers different abstractions to provide useful shortcuts and defaults.
These abstractions will also use a stub uwsgi module when the real one is not available.
A couple of examples:
from uwsgiconf.runtime.locking import lock
from uwsgiconf.runtime.scheduling import register_timer_rb
@register_timer_rb(10, repeat=2)
def repeat_twice():
"""This function will be called twice with 10 seconds interval
using red-black tree based timer.
"""
with lock():
# Code under this context manager will be locked.
do_something()
Allows for runtime access to:
Alarms
Caches
Locks
Logging
Monitoring
Mules
RPC
Scheduling
Signals
Websockets
and more
Third parties support
Django
Run your Django-based project on uWSGI using manage command:
$ ./manage.py uwsgi_run
$ ./manage.py uwsgi_reload --force
Other commands are available.
uWSGI summary and statistics are also available from Admin interface.
System configs
Compile system service config (e.g systemd) to run your uWSGI-powered project:
$ uwsgiconf sysinit systemd
Documentation
More information can be found at http://uwsgiconf.readthedocs.org/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file uwsgiconf-1.0.0.tar.gz
.
File metadata
- Download URL: uwsgiconf-1.0.0.tar.gz
- Upload date:
- Size: 161.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/2.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c09e64b1235b13246f3b491d528b3d3511674ce968f8ee7fa78274ccce568bca |
|
MD5 | a9948bd1a394064e9604d2de0435a2b8 |
|
BLAKE2b-256 | 812f8cef00d933eac4de67291b2ff46d17ce6317d5ba8787b3ec9747bb504c1c |
File details
Details for the file uwsgiconf-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: uwsgiconf-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 161.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/2.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 482df30b9873ff24e1ef6e41b2c36ccb72bac816793d6acfae21940df0294e9d |
|
MD5 | 8f3f7d9fd3539e4dbb0df72770ae357e |
|
BLAKE2b-256 | 0e88f31f8115b2104104bcaabad5c9fe8e6c09fe05b1b77d397a2eeb56a97759 |