Skip to main content

A common library for netloc rule use case.

Project description


Build Status codecov PyPI - Python Version PyPI

A library for matching netloc.

Netloc is a concept to describe the location of a URL, it can be treated as 3-tuple (host, port, scheme)

Netloc match is a very common and useful operation on processing URL. For example, netloc blacklist is a series rules of netloc with ALLOWED or DISALLOWED:|80|http ALLOWED|| DISALLOWED

You can skip processing becase it match|| DISALLOWED.


pip install os-netloc-rule


  • load netloc and rule

    from os_netloc_rule import Matcher
    netloc_rules = [
        ('||', 1),
        ('||', 2),
        ('|8080|', 3),
    matcher = Matcher()
    for netloc_string, rule in rules:
        matcher.load_from_string(netloc_string, rule)
  • match netloc

    matcher.match('', '8080', 'http')
  • if there are same netloc with different rule, the latter covers the former by default. But you can custom your own cmp function when loading rules

    def cmp(former, latter):
        return -1 if former > latter else 1
    matcher.load(host, port, scheme, rule, cmp=cmp)
  • iter netloc

    for netloc, rule in matcher.iter():

Unit Tests



MIT licensed.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for os-netloc-rule, version 0.3
Filename, size File type Python version Upload date Hashes
Filename, size os-netloc-rule-0.3.tar.gz (5.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page