# API Reference

## Module `url_matcher`

class Patterns(include: 'list[str]', exclude: 'list[str] | None' = None, priority: 'int' = 500)
  __init__(include: list[str], exclude: list[str] | None = None, priority: int = 500)
  all_includes_have_domain() → bool

    Return true if all the include patterns have a domain

  exclude: tuple[str, ...]
  get_domains() → list[str]
  get_includes_for(domain: str) → list[str]
  get_includes_without_domain() → list[str]
  include: tuple[str, ...]
  is_universal_pattern() → bool

    Return true if there are no include patterns or they are empty. A universal pattern matches any domain

  priority: int

class URLMatcher(data: Mapping[Any, Patterns] | Iterable[tuple[Any, Patterns]] | None = None)
  __init__(data: Mapping[Any, Patterns] | Iterable[tuple[Any, Patterns]] | None = None)

    A class that matches URLs against a list of patterns, returning the identifier of the rule that matched the URL.

    Example usage:

        matcher = URLMatcher()
        matcher.add_or_update(1, Patterns(include=["example.com/product"]))
        matcher.add_or_update(2, Patterns(include=["other.com"]))

        assert matcher.match("http://example.com/product/a_product.html") == 1
        assert matcher.match("http://other.com/a_different_page") == 2

    Parameters:

      data – A map or a list of tuples with identifier, patterns pairs to initialize the object from

  add_or_update(identifier: Any, patterns: Patterns) → None
  get(identifier: Any) → Patterns | None
  match(url: str, *, include_universal: bool = True) → Any | None
  match_all(url: str, *, include_universal: bool = True) → Iterator[Any]
  match_universal() → Iterator[Any]
  matchers_by_domain: dict[str, list[PatternsMatcher]]
  matchers_universal: list[PatternsMatcher]
  patterns: dict[Any, Patterns]
  remove(identifier: Any) → None