Giter Site home page Giter Site logo

sansio-tld-parser's Introduction

Build Status

A sansio tld parser.

Given a tld rule list and a domain, parse the tld from the domain.

Yes, it's more complicated than domain.split(".") ;)

Why is this sansio? What has io got to do with it?

Parsing TLDs requires actually knowing all of the TLDS. These are maintained in a list online.

For some reason, all of the TLD parsers out that at the moment like to handle lookups to these lists internally, making them awkward to couple with whatever your flavour of application is.

This is a get-the-list-yourself situation.

Installation

pip install tld-parser :)

Use

You'll need access to the public suffix list:

Canonical: https://publicsuffix.org/list/public_suffix_list.dat

Git hosted: https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat

>>> from tld_parser import parse_rule_list, parse_domain
>>>
>>> from some_http_client import get
>>>
>>> suffix_list = get(list_url).content
>>> # The parser expects a Sequence of rules in the same format at the public suffix list.
>>> suffix_list = suffix_list.decode().splitlines()
>>>
>>> tld_rules = parse_rule_list(suffix_list)
>>>
>>> parse_domain(tld_rules, "some_subdomain.domain.co.uk")
Result(registrable_part='some_subdomain.domain', tld='co.uk')

And out pops a Result object :)

Breaking changelog

  • Raise TLDParserError on error parse fail, rather than returning None, lol. Raises NoRegisterablePart when the TLD is valid but the domain given was just a TLD. Raises NoTLDMatch when no TLD could be found.

sansio-tld-parser's People

Contributors

theelous3 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.