repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
searxng
searx/search/processors/online_url_search.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Processor used for ``online_url_search`` engines.""" import typing as t import re from .online import OnlineProcessor, OnlineParams if t.TYPE_CHECKING: from .abstract import EngineProcessor from searx.search.models import SearchQuery search_syntax = { "ht...
65
1,953
searxng
searx/search/processors/online_currency.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Processor used for ``online_currency`` engines.""" import typing as t import unicodedata import re import flask_babel import babel from searx.data import CURRENCIES from .online import OnlineProcessor, OnlineParams if t.TYPE_CHECKING: from .abstract import Engine...
117
3,608
searxng
searx/search/processors/abstract.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Abstract base classes for all engine processors.""" import typing as t import os import logging import threading from abc import abstractmethod, ABC from timeit import default_timer from searx import get_setting from searx import logger from searx.engines import engine...
309
11,758
searxng
searx/search/processors/online_dictionary.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Processor used for ``online_dictionary`` engines.""" import typing as t import re from searx.sxng_locales import sxng_locales from .online import OnlineProcessor, OnlineParams if t.TYPE_CHECKING: from searx.search.models import SearchQuery search_syntax = re.compi...
103
3,146
searxng
searx/favicons/resolvers.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Implementations of the favicon *resolvers* that are available in the favicon proxy by default. A *resolver* is a function that obtains the favicon from an external source. The *resolver* function receives two arguments (``domain, timeout``) and returns a tuple ``(data, ...
116
4,392
searxng
searx/favicons/__main__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Command line implementation""" import typer from . import cache from . import init init() app = typer.Typer() app.add_typer(cache.app, name="cache", help="commands related to the cache") app()
13
244
searxng
searx/favicons/__init__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Implementations for providing the favicons in SearXNG. There is a command line for developer purposes and for deeper analysis. Here is an example in which the command line is called in the development environment:: $ ./manage pyenv.cmd bash --norc --noprofile (py3)...
45
1,285
searxng
searx/favicons/proxy.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Implementations for a favicon proxy""" from typing import Callable import importlib import base64 import pathlib import urllib.parse import flask from httpx import HTTPError import msgspec from searx import get_setting from searx.webutils import new_hmac, is_hmac_of...
238
8,047
searxng
searx/favicons/config.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import pathlib import msgspec from .cache import FaviconCacheConfig from .proxy import FaviconProxyConfig CONFIG_SCHEMA: int = 1 """Version of the configuration schema.""" TOML_CACHE_CFG: dict[str, "FaviconConfig"] = {} """Cach...
65
2,206
searxng
searx/favicons/cache.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Implementations for caching favicons. :py:obj:`FaviconCacheConfig`: Configuration of the favicon cache :py:obj:`FaviconCache`: Abstract base class for the implementation of a favicon cache. :py:obj:`FaviconCacheSQLite`: Favicon cache that manages the favicon BLOB...
497
17,250
searxng
searx/network/network.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=global-statement # pylint: disable=missing-module-docstring, missing-class-docstring __all__ = ["get_network"] import typing as t from collections.abc import Generator import atexit import asyncio import ipaddress from itertools import cycle import htt...
444
17,764
searxng
searx/network/__init__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring, global-statement __all__ = ["get_network", "initialize", "check_network_configuration", "raise_for_httperror"] import typing as t import asyncio import threading import concurrent.futures from queue import SimpleQueue from types...
277
9,103
searxng
searx/network/raise_for_httperror.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Raise exception for an HTTP response is an error.""" import typing as t from searx.exceptions import ( SearxEngineCaptchaException, SearxEngineTooManyRequestsException, SearxEngineAccessDeniedException, ) from searx import get_setting if t.TYPE_CHECKING: ...
80
3,064
searxng
searx/network/client.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring, global-statement import typing as t from types import TracebackType import asyncio import logging import random from ssl import SSLContext import threading import httpx from httpx_socks import AsyncProxyTransport from python_soc...
241
7,922
searxng
searx/metrics/models.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import typing as t import decimal import threading from searx import logger __all__ = ["Histogram", "HistogramStorage", "CounterStorage"] logger = logger.getChild('searx.metrics') class Histogram: # pylint: disable=missing-...
169
4,742
searxng
searx/metrics/error_recorder.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring, invalid-name import typing as t import inspect from json import JSONDecodeError from urllib.parse import urlparse from httpx import HTTPError, HTTPStatusError from searx.exceptions import ( SearxXPathSyntaxException, Sear...
201
6,737
searxng
searx/metrics/__init__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import math import contextlib from timeit import default_timer from searx.engines import engines from searx.openmetrics import OpenMetricsFamily from .models import HistogramStorage, CounterStorage, VoidHistogram, VoidCounterStora...
295
10,806
searxng
searx/infopage/__init__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Render SearXNG instance documentation. Usage in a Flask app route: .. code:: python from searx import infopage from searx.extended_types import sxng_request _INFO_PAGES = infopage.InfoPageSet(infopage.MistletoePage) @app.route('/info/<pagename>', methods=['GE...
196
6,028
searxng
searx/data/__main__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Command line implementation""" import typer from .core import get_cache app = typer.Typer() @app.command() def state(): """show state of the cache""" cache = get_cache() for table in cache.table_names: for row in cache.DB.execute(f"SELECT count(*)...
21
418
searxng
searx/data/__init__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """This module holds the *data* created by:: make data.all """ # pylint: disable=invalid-name __all__ = ["ahmia_blacklist_loader", "data_dir", "get_cache"] import json import typing as t from .core import log, data_dir, get_cache from .currencies import CurrenciesDB fro...
108
2,764
searxng
searx/data/tracker_patterns.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Simple implementation to store TrackerPatterns data in a SQL database.""" # pylint: disable=too-many-branches import typing as t __all__ = ["TrackerPatternsDB"] import re from collections.abc import Iterator from urllib.parse import urlparse, urlunparse, parse_qsl, url...
183
6,615
searxng
searx/data/currencies.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Simple implementation to store currencies data in a SQL database.""" __all__ = ["CurrenciesDB"] import typing as t import json import pathlib from .core import get_cache, log if t.TYPE_CHECKING: from searx.cache import CacheRowType @t.final class CurrenciesDB: ...
65
2,202
searxng
searx/data/core.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import pathlib from searx import logger from searx.cache import ExpireCacheCfg, ExpireCacheSQLite log = logger.getChild("data") data_dir: pathlib.Path = pathlib.Path(__file__).parent _DATA_CACHE: ExpireCacheSQLite | None = Non...
30
748
searxng
searx/plugins/tor_check.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """A plugin to check if the ip address of the request is a Tor exit-node if the user searches for ``tor-check``. It fetches the tor exit node list from :py:obj:`url_exit_list` and parses all the IPs into a list, then checks if the user's IP address is in it. """ from ipaddr...
79
2,788
searxng
searx/plugins/unit_converter.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """A plugin for converting measured values from one unit to another unit (a unit converter). The plugin looks up the symbols (given in the query term) in a list of converters, each converter is one item in the list (compare :py:obj:`ADDITIONAL_UNITS`). If the symbols are a...
151
4,974
searxng
searx/plugins/self_info.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring, missing-class-docstring import typing import re from ipaddress import ip_address from flask_babel import gettext from searx.result_types import EngineResults from . import Plugin, PluginInfo if typing.TYPE_CHECKING: from s...
60
1,916
searxng
searx/plugins/calculator.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import typing as t from flask_babel import gettext # pyright: ignore[reportUnknownVariableType] from searx.plugins import Plugin, PluginInfo if t.TYPE_CHECKING: from searx.plugins import PluginCfg @t.final class SXNGPlugi...
29
724
searxng
searx/plugins/_core.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=too-few-public-methods,missing-module-docstring __all__ = ["PluginInfo", "Plugin", "PluginCfg", "PluginStorage"] import abc import importlib import inspect import logging import re import typing as t from collections.abc import Generator from dataclasse...
307
10,552
searxng
searx/plugins/time_zone.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import typing as t import datetime from flask_babel import gettext from searx.result_types import EngineResults from searx.weather import DateTime, GeoLocation from . import Plugin, PluginInfo if t.TYPE_CHECKING: from searx...
70
2,396
searxng
searx/plugins/__init__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """.. sidebar:: Further reading .. - :ref:`plugins admin` - :ref:`SearXNG settings <settings plugins>` Plugins can extend or replace functionality of various components of SearXNG. Entry points (hooks) define when a plugin runs. Right now only three hooks are imple...
110
2,957
searxng
searx/plugins/infinite_scroll.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import typing as t from flask_babel import gettext # pyright: ignore[reportUnknownVariableType] from searx.plugins import Plugin, PluginInfo if t.TYPE_CHECKING: from searx.plugins import PluginCfg @t.final class SXNGPlugi...
29
801
searxng
searx/plugins/ahmia_filter.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import typing as t from hashlib import md5 from flask_babel import gettext # pyright: ignore[reportUnknownVariableType] from searx.data import ahmia_blacklist_loader from searx import get_setting from searx.plugins import Plugin...
53
1,822
searxng
searx/plugins/oa_doi_rewrite.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import typing import re from urllib.parse import parse_qsl from flask_babel import gettext from searx import get_setting from searx.plugins import Plugin, PluginInfo from searx.extended_types import sxng_request from ._core impor...
90
2,699
searxng
searx/plugins/hash_plugin.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring, missing-class-docstring import typing import re import hashlib from flask_babel import gettext from searx.plugins import Plugin, PluginInfo from searx.result_types import EngineResults if typing.TYPE_CHECKING: from searx.se...
68
2,151
searxng
searx/plugins/tracker_url_remover.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring, unused-argument import logging import typing as t from flask_babel import gettext # pyright: ignore[reportUnknownVariableType] from searx.data import TRACKER_PATTERNS from . import Plugin, PluginInfo if t.TYPE_CHECKING: i...
59
1,830
searxng
searx/plugins/hostnames.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=too-many-branches, unused-argument """During the initialization phase, the plugin checks whether a ``hostnames:`` configuration exists. If this is not the case, the plugin is not included in the PluginStorage (it is not available for selection). - ``hostna...
201
6,620
searxng
searx/enginelib/traits.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Engine's traits are fetched from the origin engines and stored in a JSON file in the *data folder*. Most often traits are languages and region codes and their mapping from SearXNG's representation to the representation in the origin search engine. For new traits new pro...
255
9,543
searxng
searx/enginelib/__main__.py
.py
"""Implementation of a command line for development purposes. To start a command, switch to the environment and run library module as a script:: $ ./manage pyenv.cmd bash --norc --noprofile (py3) python -m searx.enginelib --help The following commands can be used for maintenance and introspection (development)...
22
613
searxng
searx/enginelib/__init__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Implementations of the framework for the SearXNG engines. - :py:obj:`searx.enginelib.EngineCache` - :py:obj:`searx.enginelib.Engine` - :py:obj:`searx.enginelib.EngineAbout` - :py:obj:`searx.enginelib.traits` There is a command line for developer purposes and for deeper ...
416
14,998
searxng
searx/botdetection/trusted_proxies.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Implementation of a middleware to determine the real IP of an HTTP request (:py:obj:`flask.request.remote_addr`) behind a proxy chain.""" # pylint: disable=too-many-branches import typing as t from collections import abc from ipaddress import IPv4Address, IPv6Address, ...
177
6,709
searxng
searx/botdetection/valkeydb.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Providing a Valkey database for the botdetection methods.""" import valkey __all__ = ["set_valkey_client", "get_valkey_client"] CLIENT: valkey.Valkey | None = None """Global Valkey DB connection (Valkey client object).""" def set_valkey_client(valkey_client: valkey....
22
582
searxng
searx/botdetection/ip_limit.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """.. _botdetection.ip_limit: Method ``ip_limit`` ------------------- The ``ip_limit`` method counts request from an IP in *sliding windows*. If there are to many requests in a sliding window, the request is evaluated as a bot request. This method requires a valkey DB an...
149
5,340
searxng
searx/botdetection/link_token.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """ Method ``link_token`` --------------------- The ``link_token`` method evaluates a request as :py:obj:`suspicious <is_suspicious>` if the URL ``/client<token>.css`` is not requested by the client. By adding a random component (the token) in the URL, a bot can not send a...
157
4,650
searxng
searx/botdetection/http_accept_encoding.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """ Method ``http_accept_encoding`` ------------------------------- The ``http_accept_encoding`` method evaluates a request as the request of a bot if the Accept-Encoding_ header .. - did not contain ``gzip`` AND ``deflate`` (if both values are missed) - did not contain ``...
40
1,050
searxng
searx/botdetection/http_connection.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """ Method ``http_connection`` -------------------------- The ``http_connection`` method evaluates a request as the request of a bot if the Connection_ header is set to ``close``. .. _Connection: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection """ ...
36
811
searxng
searx/botdetection/__init__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """.. _botdetection src: Implementations used for bot detection. """ __all__ = ["init", "dump_request", "get_network", "too_many_requests", "ProxyFix"] import valkey from ._helpers import dump_request from ._helpers import get_network from ._helpers import too_many_re...
26
581
searxng
searx/botdetection/http_accept.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """ Method ``http_accept`` ---------------------- The ``http_accept`` method evaluates a request as the request of a bot if the Accept_ header .. - did not contain ``text/html`` .. _Accept: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept """ from ip...
38
804
searxng
searx/botdetection/ip_lists.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """.. _botdetection.ip_lists: Method ``ip_lists`` ------------------- The ``ip_lists`` method implements :py:obj:`block-list <block_ip>` and :py:obj:`pass-list <pass_ip>`. .. code:: toml [botdetection.ip_lists] pass_ip = [ '167.235.158.251', # IPv4 of check.s...
85
2,687
searxng
searx/botdetection/_helpers.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring, invalid-name import typing as t __all__ = ["log_error_only_once", "dump_request", "get_network", "logger", "too_many_requests"] from ipaddress import ( IPv4Network, IPv6Network, IPv4Address, IPv6Address, ip_n...
87
2,827
searxng
searx/botdetection/http_user_agent.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """ Method ``http_user_agent`` -------------------------- The ``http_user_agent`` method evaluates a request as the request of a bot if the User-Agent_ header is unset or matches the regular expression :py:obj:`USER_AGENT`. .. _User-Agent: https://developer.mozilla.org/...
66
1,939
searxng
searx/botdetection/http_sec_fetch.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """ Method ``http_sec_fetch`` ------------------------- The ``http_sec_fetch`` method protect resources from web attacks with `Fetch Metadata`_. A request is filtered out in case of: - http header Sec-Fetch-Mode_ is invalid - http header Sec-Fetch-Dest_ is invalid .. _Fe...
108
3,083
searxng
searx/botdetection/config.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Configuration class :py:class:`Config` with deep-update, schema validation and deprecated names. The :py:class:`Config` class implements a configuration that is based on structured dictionaries. The configuration schema is defined in a dictionary structure and the confi...
398
13,309
searxng
searx/botdetection/http_accept_language.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """ Method ``http_accept_language`` ------------------------------- The ``http_accept_language`` method evaluates a request as the request of a bot if the Accept-Language_ header is unset. .. _Accept-Language: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Us...
35
830
searxng
searx/answerers/_core.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=too-few-public-methods, missing-module-docstring import abc import importlib import logging import pathlib import warnings from dataclasses import dataclass from searx.utils import load_module from searx.result_types.answer import BaseAnswer _default ...
169
5,230
searxng
searx/answerers/__init__.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """The *answerers* give instant answers related to the search query, they usually provide answers of type :py:obj:`Answer <searx.result_types.Answer>`. Here is an example of a very simple answerer that adds a "Hello" into the answer area: .. code:: from flask_babel imp...
49
1,112
searxng
searx/answerers/random.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring import hashlib import random import string import uuid from flask_babel import gettext from searx.result_types import Answer from searx.result_types.answer import BaseAnswer from . import Answerer, AnswererInfo def random_char...
80
1,817
searxng
searx/answerers/statistics.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later # pylint: disable=missing-module-docstring from functools import reduce from operator import mul import babel import babel.numbers from flask_babel import gettext from searx.extended_types import sxng_request from searx.result_types import Answer from searx.result_types....
66
1,941
searxng
utils/searxng_check.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """Implement some checks in the active installation """ import os import sys import logging import warnings from pathlib import Path repo_root = Path(__file__).resolve().parent.parent LOG_FORMAT_DEBUG = '%(levelname)-7s %(name)-30.30s: %(message)s' logging.basicConfig(lev...
45
1,392
searxng
utils/get_setting.py
.py
# SPDX-License-Identifier: AGPL-3.0-or-later """build environment used by shell scripts """ # set path import sys import importlib.util import re from pathlib import Path repo_root = Path(__file__).resolve().parent.parent def main(setting_name): settings_path = repo_root / "searx" / "settings.yml" with op...
124
3,642
searxng
searxng_extra/update/update_currencies.py
.py
#!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later """Fetch currencies from :origin:`searx/engines/wikidata.py` engine. Output file: :origin:`searx/data/currencies.json` (:origin:`CI Update data ... <.github/workflows/data-update.yml>`). """ # pylint: disable=invalid-name import re import unicodedat...
156
4,971
searxng
searxng_extra/update/update_external_bangs.py
.py
#!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later """Update :origin:`searx/data/external_bangs.json` using the duckduckgo bangs from :py:obj:`BANGS_URL`. - :origin:`CI Update data ... <.github/workflows/data-update.yml>` """ import json from searx.external_bang import LEAF_KEY from searx.data impor...
144
3,940
searxng
searxng_extra/update/update_locales.py
.py
#!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later """Update locale names in :origin:`searx/data/locales.json` used by :ref:`searx.locales` - :py:obj:`searx.locales.RTL_LOCALES` - :py:obj:`searx.locales.LOCALE_NAMES` """ # pylint: disable=invalid-name from typing import Set import json from pathlib im...
102
3,236
searxng
searxng_extra/update/update_osm_keys_tags.py
.py
#!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later """Fetch OSM keys and tags. To get the i18n names, the scripts uses `Wikidata Query Service`_ instead of for example `OSM tags API`_ (side note: the actual change log from map.atownsend.org.uk_ might be useful to normalize OSM tags). Output file: :ori...
215
7,023
searxng
searxng_extra/update/update_ahmia_blacklist.py
.py
#!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later """This script saves `Ahmia's blacklist`_ for onion sites. Output file: :origin:`searx/data/ahmia_blacklist.txt` (:origin:`CI Update data ... <.github/workflows/data-update.yml>`). .. _Ahmia's blacklist: https://ahmia.fi/blacklist/ """ # pylint: dis...
34
1,025
searxng
searxng_extra/update/update_engine_traits.py
.py
#!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later """Update :py:obj:`searx.enginelib.traits.EngineTraitsMap` and :origin:`searx/sxng_locales.py` :py:obj:`searx.enginelib.traits.EngineTraitsMap.ENGINE_TRAITS_FILE`: Persistence of engines traits, fetched from the engines. :origin:`searx/sxng_locales....
230
7,177
searxng
searxng_extra/update/update_engine_descriptions.py
.py
#!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later """Fetch website description from websites and from :origin:`searx/engines/wikidata.py` engine. Output file: :origin:`searx/data/engine_descriptions.json`. """ # pylint: disable=invalid-name, global-statement import json from urllib.parse import url...
402
14,835
searxng
searxng_extra/update/update_wikidata_units.py
.py
#!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later """Fetch units from :origin:`searx/engines/wikidata.py` engine. Output file: :origin:`searx/data/wikidata_units.json` (:origin:`CI Update data ... <.github/workflows/data-update.yml>`). """ import json from searx.engines import wikidata, set_logger...
23
642
searxng
searxng_extra/update/update_firefox_version.py
.py
#!/usr/bin/env python # SPDX-License-Identifier: AGPL-3.0-or-later """Fetch firefox useragent signatures Output file: :origin:`searx/data/useragents.json` (:origin:`CI Update data ... <.github/workflows/data-update.yml>`). """ # pylint: disable=use-dict-literal import json import re from urllib.parse import urlparse...
81
2,359
graphrag
packages/graphrag-common/graphrag_common/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """GraphRAG Common package."""
5
109
graphrag
packages/graphrag-common/graphrag_common/hasher/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """The GraphRAG hasher module.""" from graphrag_common.hasher.hasher import ( Hasher, hash_data, make_yaml_serializable, sha256_hasher, ) __all__ = [ "Hasher", "hash_data", "make_yaml_serializable", "sha256_h...
19
330
graphrag
packages/graphrag-common/graphrag_common/hasher/hasher.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """The GraphRAG hasher module.""" import hashlib from collections.abc import Callable from typing import Any import yaml Hasher = Callable[[str], str] """Type alias for a hasher function (data: str) -> str.""" def sha256_hasher(data: str...
60
1,709
graphrag
packages/graphrag-common/graphrag_common/config/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """The GraphRAG config module.""" from graphrag_common.config.load_config import ConfigParsingError, load_config __all__ = ["ConfigParsingError", "load_config"]
9
241
graphrag
packages/graphrag-common/graphrag_common/config/load_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Load configuration.""" import json import os from collections.abc import Callable from pathlib import Path from string import Template from typing import Any, TypeVar import yaml from dotenv import load_dotenv T = TypeVar("T", covariant...
206
7,361
graphrag
packages/graphrag-common/graphrag_common/factory/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """The GraphRAG factory module.""" from graphrag_common.factory.factory import Factory, ServiceScope __all__ = ["Factory", "ServiceScope"]
9
219
graphrag
packages/graphrag-common/graphrag_common/factory/factory.py
.py
# Copyright (c) 2025 Microsoft Corporation. # Licensed under the MIT License """Factory ABC.""" from abc import ABC from collections.abc import Callable from dataclasses import dataclass from typing import Any, ClassVar, Generic, Literal, TypeVar from graphrag_common.hasher import hash_data T = TypeVar("T", covaria...
114
3,749
graphrag
packages/graphrag-cache/graphrag_cache/cache_key.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Create cache key.""" from typing import Any, Protocol, runtime_checkable from graphrag_common.hasher import hash_data @runtime_checkable class CacheKeyCreator(Protocol): """Create cache key function protocol. Args ---- ...
37
772
graphrag
packages/graphrag-cache/graphrag_cache/json_cache.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'JsonCache' model.""" import json from typing import Any from graphrag_storage import Storage, StorageConfig, create_storage from graphrag_cache.cache import Cache class JsonCache(Cache): """File pipeline cache...
73
2,258
graphrag
packages/graphrag-cache/graphrag_cache/cache_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Cache factory implementation.""" from collections.abc import Callable from graphrag_common.factory import Factory, ServiceScope from graphrag_storage import Storage, create_storage from graphrag_cache.cache import Cache from graphrag_c...
90
2,554
graphrag
packages/graphrag-cache/graphrag_cache/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """The GraphRAG Cache package.""" from graphrag_cache.cache import Cache from graphrag_cache.cache_config import CacheConfig from graphrag_cache.cache_factory import create_cache, register_cache from graphrag_cache.cache_key import CacheKeyC...
21
546
graphrag
packages/graphrag-cache/graphrag_cache/memory_cache.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """MemoryCache implementation.""" from typing import Any from graphrag_cache.cache import Cache class MemoryCache(Cache): """In memory cache class definition.""" _cache: dict[str, Any] _name: str def __init__(self, **kwa...
70
1,777
graphrag
packages/graphrag-cache/graphrag_cache/cache_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Cache configuration model.""" from graphrag_storage import StorageConfig, StorageType from pydantic import BaseModel, ConfigDict, Field from graphrag_cache.cache_type import CacheType class CacheConfig(BaseModel): """The configurat...
27
854
graphrag
packages/graphrag-cache/graphrag_cache/cache_type.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Builtin cache implementation types.""" from enum import StrEnum class CacheType(StrEnum): """Enum for cache types.""" Json = "json" Memory = "memory" Noop = "none"
16
266
graphrag
packages/graphrag-cache/graphrag_cache/cache.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Abstract base class for cache.""" from __future__ import annotations from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_storage import Storage class Cache(ABC): """Provide...
75
1,877
graphrag
packages/graphrag-cache/graphrag_cache/noop_cache.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """NoopCache implementation.""" from typing import Any from graphrag_cache.cache import Cache class NoopCache(Cache): """A no-op implementation of Cache, usually useful for testing.""" def __init__(self, **kwargs: Any) -> None: ...
69
1,711
graphrag
packages/graphrag-chunking/graphrag_chunking/bootstrap_nltk.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Bootstrap definition.""" import warnings # Ignore warnings from numba warnings.filterwarnings("ignore", message=".*The 'nopython' keyword.*") warnings.filterwarnings("ignore", message=".*Use no seed for parallelism.*") initialized_nltk ...
32
890
graphrag
packages/graphrag-chunking/graphrag_chunking/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """System-level chunking package."""
5
115
graphrag
packages/graphrag-chunking/graphrag_chunking/text_chunk.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """The TextChunk dataclass.""" from dataclasses import dataclass @dataclass class TextChunk: """Result of chunking a document.""" original: str """Raw original text chunk before any transformation.""" text: str """The...
30
746
graphrag
packages/graphrag-chunking/graphrag_chunking/chunker.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing the 'Chunker' class.""" from abc import ABC, abstractmethod from collections.abc import Callable from typing import Any from graphrag_chunking.text_chunk import TextChunk class Chunker(ABC): """Abstract base cla...
25
630
graphrag
packages/graphrag-chunking/graphrag_chunking/chunk_strategy_type.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Chunk strategy type enumeration.""" from enum import StrEnum class ChunkerType(StrEnum): """ChunkerType class definition.""" Tokens = "tokens" Sentence = "sentence"
14
262
graphrag
packages/graphrag-chunking/graphrag_chunking/chunking_config.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Parameterization settings for the default configuration.""" from pydantic import BaseModel, ConfigDict, Field from graphrag_chunking.chunk_strategy_type import ChunkerType class ChunkingConfig(BaseModel): """Configuration section f...
37
1,050
graphrag
packages/graphrag-chunking/graphrag_chunking/create_chunk_results.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'create_chunk_results' function.""" from collections.abc import Callable from graphrag_chunking.text_chunk import TextChunk def create_chunk_results( chunks: list[str], transform: Callable[[str], str] | None...
33
1,085
graphrag
packages/graphrag-chunking/graphrag_chunking/token_chunker.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'TokenChunker' class.""" from collections.abc import Callable from typing import Any from graphrag_chunking.chunker import Chunker from graphrag_chunking.create_chunk_results import create_chunk_results from graphrag_...
70
2,112
graphrag
packages/graphrag-chunking/graphrag_chunking/sentence_chunker.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'SentenceChunker' class.""" from collections.abc import Callable from typing import Any import nltk from graphrag_chunking.bootstrap_nltk import bootstrap from graphrag_chunking.chunker import Chunker from graphrag_c...
49
1,753
graphrag
packages/graphrag-chunking/graphrag_chunking/transformers.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A collection of useful built-in transformers you can use for chunking.""" from collections.abc import Callable from typing import Any def add_metadata( metadata: dict[str, Any], delimiter: str = ": ", line_delimiter: str = "...
26
781
graphrag
packages/graphrag-chunking/graphrag_chunking/chunker_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """A module containing 'ChunkerFactory', 'register_chunker', and 'create_chunker'.""" from collections.abc import Callable from graphrag_common.factory.factory import Factory, ServiceScope from graphrag_chunking.chunk_strategy_type import ...
78
2,431
graphrag
packages/graphrag-llm/graphrag_llm/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """GraphRAG LLM Package.""" import nest_asyncio2 nest_asyncio2.apply() # noqa: RUF067
9
167
graphrag
packages/graphrag-llm/graphrag_llm/templating/template_manager.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Abstract base class for template managers.""" from abc import ABC, abstractmethod from typing import Any class TemplateManager(ABC): """Abstract base class for template managers.""" @abstractmethod def __init__(self, **kwar...
66
1,650
graphrag
packages/graphrag-llm/graphrag_llm/templating/__init__.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Templates module.""" from graphrag_llm.templating.template_engine import TemplateEngine from graphrag_llm.templating.template_engine_factory import ( create_template_engine, register_template_engine, ) from graphrag_llm.templating...
25
672
graphrag
packages/graphrag-llm/graphrag_llm/templating/template_engine.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Abstract base class for template engines.""" from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from graphrag_llm.templating.template_manager import TemplateManager class TemplateEngine(ABC)...
54
1,497
graphrag
packages/graphrag-llm/graphrag_llm/templating/template_engine_factory.py
.py
# Copyright (c) 2024 Microsoft Corporation. # Licensed under the MIT License """Template engine factory implementation.""" from collections.abc import Callable from typing import TYPE_CHECKING from graphrag_common.factory import Factory from graphrag_llm.config.template_engine_config import TemplateEngineConfig fro...
96
3,103