searxng_extra/standalone_searx.py

Script to run SearXNG from terminal.

DON’T USE THIS SCRIPT!!

Danger

Be warned, using the standalone_searx.py won’t give you privacy!

On the contrary, this script behaves like a SearXNG server: your IP is exposed and tracked by all active engines (google, bing, qwant, … ), with every query!

Note

This is an old and grumpy hack / SearXNG is a Flask application with client/server structure, which can’t be turned into a command line tool the way it was done here.

Getting categories without initiate the engine will only return [‘general’]

>>> import searx.engines
... list(searx.engines.categories.keys())
['general']
>>> import searx.search
... searx.search.initialize()
... list(searx.engines.categories.keys())
['general', 'it', 'science', 'images', 'news', 'videos', 'music', 'files', 'social media', 'map']

Example to use this script:

$ python3 searxng_extra/standalone_searx.py rain
searxng_extra.standalone_searx.get_search_query(args: Namespace, engine_categories: List[str] | None = None) SearchQuery[source]

Get search results for the query

searxng_extra.standalone_searx.json_serial(obj: Any) Any[source]

JSON serializer for objects not serializable by default json code.

Raises:

TypeError – raised when obj is not serializable

searxng_extra.standalone_searx.no_parsed_url(results: List[Dict[str, Any]]) List[Dict[str, Any]][source]

Remove parsed url from dict.

searxng_extra.standalone_searx.parse_argument(args: List[str] | None = None, category_choices: List[str] | None = None) Namespace[source]

Parse command line.

Raises:

SystemExit – Query argument required on args

Examples:

>>> import importlib
... # load module
... spec = importlib.util.spec_from_file_location(
...     'utils.standalone_searx', 'utils/standalone_searx.py')
... sas = importlib.util.module_from_spec(spec)
... spec.loader.exec_module(sas)
... sas.parse_argument()
usage: ptipython [-h] [--category [{general}]] [--lang [LANG]] [--pageno [PAGENO]] [--safesearch [{0,1,2}]] [--timerange [{day,week,month,year}]]
                 query
SystemExit: 2
>>> sas.parse_argument(['rain'])
Namespace(category='general', lang='all', pageno=1, query='rain', safesearch='0', timerange=None)
searxng_extra.standalone_searx.to_dict(search_query: SearchQuery) Dict[str, Any][source]

Get result from parsed arguments.