Skip to content

Python

Classes

Python

Python(*args, **kwargs)

OptionsGroup

Python plugin options.

Note

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.


name

.name: str = ''

Name to represent the group.


eval_wsgi_entrypoint

.eval_wsgi_entrypoint(code: str)

Evaluates Python code as WSGI entry point.


import_module

1
2
3
4
5
.import_module(
    modules: Strint, 
    shared: bool = False,  # (1)!
    into_spooler: bool = False,  # (2)!
)
  1. If shared import is done once in master process. Otherwise, import a python module in all the processes. This is done after fork but before request processing.

  2. Import a python module in the spooler. http://uwsgi-docs.readthedocs.io/en/latest/Spooler.html

Imports a python module.


register_module_alias

1
2
3
4
5
.register_module_alias(
    alias: str, 
    module_path: str, 
    after_init: bool = False,  # (1)!
)
  1. add a python module alias after uwsgi module initialization

Adds an alias for a module.

http://uwsgi-docs.readthedocs.io/en/latest/PythonModuleAlias.html


run_module

.run_module(module: str)

Runs a Python script in the uWSGI environment.


set_app_args

.set_app_args(*args)

Sets sys.argv for python apps.

Examples: * pyargv="one two three" will set sys.argv to ('one', 'two', 'three').


set_autoreload_params

1
2
3
4
.set_autoreload_params(
    scan_interval: int | None = None,  # (1)!
    ignore_modules: Strlist = None,  # (2)!
)
  1. Seconds. Monitor Python modules' modification times to trigger reload.

    1
    .. warning:: Use only in development.
    
  2. Ignore the specified module during auto-reload scan.

Sets autoreload related parameters.


set_basic_params

.set_basic_params(
    version: Strint = AUTO,  # (1)!
    python_home: str | None = None,  # (2)!
    enable_threads: bool | None = None,  # (3)!
    search_path: str | None = None,  # (4)!
    python_binary: str | None = None,  # (5)!
    tracebacker_path: str | None = None,  # (6)!
    plugin_dir: str | None = None,  # (7)!
    os_env_reload: bool | None = None,  # (8)!
    optimization_level: int | None = None,  # (9)!
)
  1. Python version plugin supports.

    1
    2
    3
    4
    Example:
        * 3 - version 3
        * <empty> - version 2
        * <default> - version deduced by uwsgiconf
    
  2. Set python executable directory - PYTHONHOME/virtualenv.

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

    Warning

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

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

    1
    .. note:: This can be specified up to 64 times.
    
  5. Set python program name.

  6. Enable the uWSGI Python tracebacker. http://uwsgi-docs.readthedocs.io/en/latest/Tracebacker.html

  7. Directory to search for plugin.

  8. Force os.environ reloading for every request. Used to allow setting of UWSGI_SETENV for Python applications.

  9. Python optimization level (see -O argument). !!! warning This may be dangerous for some apps.


set_wsgi_params

1
2
3
4
5
.set_wsgi_params(
    module: Strpath = None,  # (1)!
    callable_name: str | None = None,  # (2)!
    env_strategy: str | None = None,  # (3)!
)
    • load .wsgi file as the Python application
    • load a WSGI module as the application.

    Note

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

    Examples: * mypackage.my_wsgi_module -- read from application attr of mypackage/my_wsgi_module.py * mypackage.my_wsgi_module:my_app -- read from my_app attr of mypackage/my_wsgi_module.py

  1. Set WSGI callable name. Default: application.

  2. 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

Set wsgi related parameters.