Python

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

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.

set_basic_params(version=(1, ), python_home=None, enable_threads=None, search_path=None, python_binary=None, tracebacker_path=None, plugin_dir=None, os_env_reload=None, optimization_level=None)
Parameters:
  • version (str|unicode|int) –

    Python version plugin supports.

    Example:
    • 3 - version 3
    • <empty> - version 2
    • <default> - version deduced by uwsgiconf
  • python_home (str|unicode) – Set python executable directory - PYTHONHOME/virtualenv.
  • search_path (str|unicode) –

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

    Note

    This can be specified up to 64 times.

  • python_binary (str|unicode) – Set python program name.
  • tracebacker_path (str|unicode) – Enable the uWSGI Python tracebacker. http://uwsgi-docs.readthedocs.io/en/latest/Tracebacker.html
  • plugin_dir (str|unicode) – Directory to search for plugin.
  • enable_threads (bool) –

    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.

  • os_env_reload (bool) – Force os.environ reloading for every request. Used to allow setting of UWSGI_SETENV for Python applications.
  • optimization_level (int) – Python optimization level (see -O argument). .. warning:: This may be dangerous for some apps.
set_app_args(*args)

Sets sys.argv for python apps.

Examples:
  • pyargv=”one two three” will set sys.argv to ('one', 'two', 'three').
Parameters:args
set_wsgi_params(module=None, callable_name=None, env_strategy=None)

Set wsgi related parameters.

Parameters:
  • module (str|unicode) –
    • load .wsgi file as the Python application
    • load a WSGI module as the application.

    Note

    The module (sans .py) must be importable, ie. 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
  • callable_name (str|unicode) – Set WSGI callable name. Default: application.
  • env_strategy (str|unicode) –

    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)

Evaluates Python code as WSGI entry point.

Parameters:code (str|unicode) –
set_autoreload_params(scan_interval=None, ignore_modules=None)

Sets autoreload related parameters.

Parameters:
  • scan_interval (int) –

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

    Warning

    Use only in development.

  • ignore_modules (list|st|unicode) – Ignore the specified module during auto-reload scan.
register_module_alias(alias, module_path, after_init=False)

Adds an alias for a module.

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

Parameters:
  • alias (str|unicode) –
  • module_path (str|unicode) –
  • after_init (bool) – add a python module alias after uwsgi module initialization
import_module(modules, shared=False, into_spooler=False)

Imports a python module.

Parameters:
  • modules (list|str|unicode) –
  • shared (bool) – 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 (bool) – Import a python module in the spooler. http://uwsgi-docs.readthedocs.io/en/latest/Spooler.html
run_module(module)

Runs a Python script in the uWSGI environment.

Parameters:module (str|unicode) –