Skip to main content

Configure uWSGI from your Python code.

Project description

uwsgiconf

https://github.com/idlesign/uwsgiconf

PyPI - Version License Coverage Docs

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 docstrings 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)
  1. 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
    
  2. Or use uwsgiconf to automatically spawn uWSGI processes for configurations defined in your module:

    uwsgiconf run
    

!!! tip "Write code" 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.

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.
  • Django cache based on uWSGI cache.
  • and more

System configs

Compile system service config (e.g systemd) to run your uWSGI-powered project:

uwsgiconf sysinit systemd

Development

Use makeapp to streamline the development:

$ uv tool install makeapp
# or
$ uv tool upgrade makeapp

Clone the source code the repository and switch into its directory:

# bootstrap the utilities
$ ma tools
# initialize the environment
$ ma up

Check code style and run tests before your pull request:

$ ma style
$ ma tests

Documentation

More information can be found at https://uwsgiconf.readthedocs.io/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uwsgiconf-2.3.1.tar.gz (131.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uwsgiconf-2.3.1-py3-none-any.whl (180.2 kB view details)

Uploaded Python 3

File details

Details for the file uwsgiconf-2.3.1.tar.gz.

File metadata

  • Download URL: uwsgiconf-2.3.1.tar.gz
  • Upload date:
  • Size: 131.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for uwsgiconf-2.3.1.tar.gz
Algorithm Hash digest
SHA256 2a9b7ccd8a8e8b0ca38506d204f3cad9e9a9cf66d591a59f996cd1c41184b8ef
MD5 0b67ed23b98a6350f7b74cb74917e8d6
BLAKE2b-256 6171ddf239a39c5aa4f7258f5a34d58db2b2d41a22b55a1d9a50eb8034353baf

See more details on using hashes here.

File details

Details for the file uwsgiconf-2.3.1-py3-none-any.whl.

File metadata

  • Download URL: uwsgiconf-2.3.1-py3-none-any.whl
  • Upload date:
  • Size: 180.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for uwsgiconf-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 18ee3a683a854cec618114101d99fbb8827792bd7b379c049d108ee1ae272684
MD5 d1cf9d0a1cb41406d42177178ffda2cf
BLAKE2b-256 3a296525e5662adabd726a2d8c1476aec884d2b466a60a0ddcba0ac6701a3c5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page