.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx Namespace Reference

Namespaces

namespace  answerers
namespace  autocomplete
namespace  babel_extract
namespace  botdetection
namespace  cache
namespace  compat
namespace  data
namespace  enginelib
namespace  engines
 ::1337x
namespace  exceptions
namespace  extended_types
namespace  external_bang
namespace  external_urls
namespace  favicons
namespace  flaskfix
namespace  infopage
namespace  limiter
namespace  locales
namespace  metrics
namespace  network
namespace  openmetrics
namespace  plugins
namespace  preferences
namespace  query
namespace  result_types
namespace  results
namespace  settings_defaults
namespace  settings_loader
namespace  sqlitedb
namespace  sxng_locales
namespace  unixthreadname
namespace  utils
namespace  valkeydb
namespace  valkeylib
namespace  version
namespace  weather
namespace  webadapter
namespace  webapp
namespace  webutils
namespace  wikidata_units

Functions

 init_settings ()
t.Any get_setting (str name, t.Any default=_unset)
 _is_color_terminal ()
 _logging_config_debug ()

Variables

str LOG_FORMAT_DEBUG = '%(levelname)-7s %(name)-30.30s: %(message)s'
str LOG_FORMAT_PROD = '%(asctime)-15s %(levelname)s:%(name)s: %(message)s'
 LOG_LEVEL_PROD = logging.WARNING
str searx_dir = abspath(dirname(__file__))
str searx_parent_dir = abspath(dirname(dirname(__file__)))
dict settings = {}
bool sxng_debug = False
 logger = logging.getLogger('searx')
 _unset = object()

Function Documentation

◆ _is_color_terminal()

searx._is_color_terminal ( )
protected

Definition at line 95 of file __init__.py.

95def _is_color_terminal():
96 if os.getenv('TERM') in ('dumb', 'unknown'):
97 return False
98 return sys.stdout.isatty()
99
100

Referenced by _logging_config_debug().

Here is the caller graph for this function:

◆ _logging_config_debug()

searx._logging_config_debug ( )
protected

Definition at line 101 of file __init__.py.

101def _logging_config_debug():
102 try:
103 import coloredlogs # pylint: disable=import-outside-toplevel
104 except ImportError:
105 coloredlogs = None
106
107 log_level = os.environ.get('SEARXNG_DEBUG_LOG_LEVEL', 'DEBUG')
108 if coloredlogs and _is_color_terminal():
109 level_styles = {
110 'spam': {'color': 'green', 'faint': True},
111 'debug': {},
112 'notice': {'color': 'magenta'},
113 'success': {'bold': True, 'color': 'green'},
114 'info': {'bold': True, 'color': 'cyan'},
115 'warning': {'color': 'yellow'},
116 'error': {'color': 'red'},
117 'critical': {'bold': True, 'color': 'red'},
118 }
119 field_styles = {
120 'asctime': {'color': 'green'},
121 'hostname': {'color': 'magenta'},
122 'levelname': {'color': 8},
123 'name': {'color': 8},
124 'programname': {'color': 'cyan'},
125 'username': {'color': 'yellow'},
126 }
127 coloredlogs.install( # type: ignore
128 level=log_level,
129 level_styles=level_styles,
130 field_styles=field_styles,
131 fmt=LOG_FORMAT_DEBUG,
132 )
133 else:
134 logging.basicConfig(level=getattr(logging, log_level, "ERROR"), format=LOG_FORMAT_DEBUG)
135
136

References _is_color_terminal(), and init_settings().

Referenced by init_settings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_setting()

t.Any searx.get_setting ( str name,
t.Any default = _unset )
Returns the value to which ``name`` point.  If there is no such name in the
settings and the ``default`` is unset, a :py:obj:`KeyError` is raised.

Definition at line 74 of file __init__.py.

74def get_setting(name: str, default: t.Any = _unset) -> t.Any:
75 """Returns the value to which ``name`` point. If there is no such name in the
76 settings and the ``default`` is unset, a :py:obj:`KeyError` is raised.
77
78 """
79 value: dict[str, t.Any] = settings
80 for a in name.split('.'):
81 if isinstance(value, dict):
82 value = value.get(a, _unset)
83 else:
84 value = _unset # type: ignore
85
86 if value is _unset:
87 if default is _unset:
88 raise KeyError(name)
89 value = default # type: ignore
90 break
91
92 return value
93
94

Referenced by searx.favicons.proxy._initial_resolver_map(), searx.webapp.config(), searx.webapp.get_client_settings(), searx.plugins.oa_doi_rewrite.get_doi_resolver(), searx.webutils.get_static_file_list(), searx.webutils.group_engines_in_tab(), searx.plugins.ahmia_filter.SXNGPlugin.init(), searx.webapp.init(), init_settings(), searx.plugins.initialize(), searx.valkeydb.initialize(), searx.favicons.is_active(), searx.webapp.preferences(), searx.network.raise_for_httperror.raise_for_cloudflare_captcha(), searx.network.raise_for_httperror.raise_for_recaptcha(), searx.webapp.render(), searx.webapp.run(), and searx.valkeylib.secret_hash().

Here is the caller graph for this function:

◆ init_settings()

searx.init_settings ( )
Initialize global ``settings`` and ``sxng_debug`` variables and
``logger`` from ``SEARXNG_SETTINGS_PATH``.

Definition at line 32 of file __init__.py.

32def init_settings():
33 """Initialize global ``settings`` and ``sxng_debug`` variables and
34 ``logger`` from ``SEARXNG_SETTINGS_PATH``.
35 """
36
37 # pylint: disable=import-outside-toplevel
38 from searx import settings_loader
39 from searx.settings_defaults import SCHEMA, apply_schema
40
41 global settings, sxng_debug # pylint: disable=global-variable-not-assigned
42
43 cfg, msg = settings_loader.load_settings(load_user_settings=True)
44 cfg = cfg or {}
45 apply_schema(cfg, SCHEMA, [])
46
47 settings.clear()
48 settings.update(cfg)
49
50 sxng_debug = get_setting("general.debug")
51 if sxng_debug:
52 _logging_config_debug()
53 else:
54 logging.basicConfig(level=LOG_LEVEL_PROD, format=LOG_FORMAT_PROD)
55 logging.root.setLevel(level=LOG_LEVEL_PROD)
56 logging.getLogger('werkzeug').setLevel(level=LOG_LEVEL_PROD)
57 logger.info(msg)
58
59 # log max_request_timeout
60 max_request_timeout: int | None = settings['outgoing']['max_request_timeout']
61 if max_request_timeout is None:
62 logger.info('max_request_timeout=%s', repr(max_request_timeout))
63 else:
64 logger.info('max_request_timeout=%i second(s)', max_request_timeout)
65
66 if settings['server']['public_instance']:
67 logger.warning(
68 "Be aware you have activated features intended only for public instances. "
69 "This force the usage of the limiter and link_token / "
70 "see https://docs.searxng.org/admin/searx.limiter.html"
71 )
72
73

References _logging_config_debug(), and get_setting().

Referenced by _logging_config_debug().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _unset

searx._unset = object()
protected

Definition at line 29 of file __init__.py.

◆ LOG_FORMAT_DEBUG

str searx.LOG_FORMAT_DEBUG = '%(levelname)-7s %(name)-30.30s: %(message)s'

Definition at line 15 of file __init__.py.

◆ LOG_FORMAT_PROD

str searx.LOG_FORMAT_PROD = '%(asctime)-15s %(levelname)s:%(name)s: %(message)s'

Definition at line 18 of file __init__.py.

◆ LOG_LEVEL_PROD

searx.LOG_LEVEL_PROD = logging.WARNING

Definition at line 19 of file __init__.py.

◆ logger

searx.logger = logging.getLogger('searx')

Definition at line 27 of file __init__.py.

◆ searx_dir

str searx.searx_dir = abspath(dirname(__file__))

Definition at line 21 of file __init__.py.

◆ searx_parent_dir

str searx.searx_parent_dir = abspath(dirname(dirname(__file__)))

Definition at line 22 of file __init__.py.

◆ settings

dict searx.settings = {}

Definition at line 24 of file __init__.py.

◆ sxng_debug

bool searx.sxng_debug = False

Definition at line 26 of file __init__.py.