class uwsgiconf.options.python.Python(*args, **kwargs)

Python plugin options.


By default the plugin does not initialize the GIL. This means your app-generated threads will not run. If you need threads, remember to enable them with enable_threads.

set_basic_params(*, version: Union[str, int] = -1, python_home: str = None, enable_threads: bool = None, search_path: str = None, python_binary: str = None, tracebacker_path: str = None, plugin_dir: str = None, os_env_reload: bool = None, optimization_level: int = None)
  • version

    Python version plugin supports.

    • 3 - version 3
    • <empty> - version 2
    • <default> - version deduced by uwsgiconf
  • python_home – Set python executable directory - PYTHONHOME/virtualenv.
  • enable_threads (bool) –

    Enable threads in the embedded languages. This will allow to spawn threads in your app.


    Threads will simply not work if this option is not enabled. There will likely be no error, just no execution of your thread code.

  • search_path

    Add directory (or an .egg or a glob) to the Python search path.


    This can be specified up to 64 times.

  • python_binary – Set python program name.
  • tracebacker_path – Enable the uWSGI Python tracebacker.
  • plugin_dir – Directory to search for plugin.
  • os_env_reload – Force os.environ reloading for every request. Used to allow setting of UWSGI_SETENV for Python applications.
  • optimization_level – Python optimization level (see -O argument). .. warning:: This may be dangerous for some apps.

Sets sys.argv for python apps.

  • pyargv=”one two three” will set sys.argv to ('one', 'two', 'three').
set_wsgi_params(*, module: Union[str, pathlib.Path] = None, callable_name: str = None, env_strategy: str = None)

Set wsgi related parameters.

  • module
    • load .wsgi file as the Python application
    • load a WSGI module as the application.


    The module (sans .py) must be importable, ie. be in PYTHONPATH.

    • mypackage.my_wsgi_module – read from application attr of mypackage/
    • mypackage.my_wsgi_module:my_app – read from my_app attr of mypackage/
  • callable_name – Set WSGI callable name. Default: application.
  • env_strategy

    Strategy for allocating/deallocating the WSGI env, can be:

    • cheat - preallocates the env dictionary on uWSGI startup and clears it
      after each request. Default behaviour for uWSGI <= 2.0.x
    • holy - creates and destroys the environ dictionary at each request.
      Default behaviour for uWSGI >= 2.1
eval_wsgi_entrypoint(code: str)

Evaluates Python code as WSGI entry point.

set_autoreload_params(*, scan_interval: int = None, ignore_modules: Union[str, List[str]] = None)

Sets autoreload related parameters.

  • scan_interval

    Seconds. Monitor Python modules’ modification times to trigger reload.


    Use only in development.

  • ignore_modules – Ignore the specified module during auto-reload scan.
register_module_alias(alias: str, module_path: str, *, after_init: bool = False)

Adds an alias for a module.

  • alias
  • module_path
  • after_init – add a python module alias after uwsgi module initialization
import_module(modules: Union[str, int], *, shared: bool = False, into_spooler: bool = False)

Imports a python module.

  • modules
  • shared – If shared import is done once in master process. Otherwise import a python module in all of the processes. This is done after fork but before request processing.
  • into_spooler – Import a python module in the spooler.
run_module(module: str)

Runs a Python script in the uWSGI environment.