The tool to convert domains to the famous IDNA format.

https://travis-ci.com/PyFunceble/domain2idna.svg?branch=master https://coveralls.io/repos/github/PyFunceble/domain2idna/badge.svg?branch=master https://api.codacy.com/project/badge/Grade/7fc14987068e409e9ddb70195f2485ab https://img.shields.io/github/license/PyFunceble/domain2idna.svg https://img.shields.io/github/release/PyFunceble/domain2idna.svg https://img.shields.io/badge/code%20style-black-000000.svg

Requirements

Here is the list of requirements:

  • Python 3.6.2+ && Python < 4
  • colorama

Python 3.6.8+ && Python < 4

The specification 3.6.8+ is because we test domain2idna (daily) in all version from 3.6.8. Otherwise, more semantically, domain2idna is written for all Python 3.6+ version.

colorama

As we want to add some coloration, we choose colorama for the job as it offers a portable awesome solution.

Get and install domain2idna

Using pip

Choose your repository, install and enjoy domain2idna!

From PyPi

$ pip3 install --user domain2idna

Note

We recommend the --user flag which installs the required dependencies at the user level. More information about it can be found on pip documentation.

Warning

We do not recommend the --user flag when using domain2idna into containers like - for example - Travis CI.

From GitHub

$ pip3 install --user git+https://github.com/PyFunceble/domain2idna.git@master#egg=domain2idna

Note

We recommend the --user flag which installs the required dependencies at the user level. More information about it can be found on pip documentation.

Warning

We do not recommend the --user flag when using domain2idna into containers like - for example - Travis CI.

Using conda

$ conda install -c pyfunceble domain2idna

Pure Python method

Execute the following and enjoy domain2idna!

We clone the repository.

$ git clone https://github.com/PyFunceble/domain2idna.git

We move to the cloned directory.

$ cd domain2idna

We test the package before installating.

$ python3 setup.py test

We install domain2idna.

$ python3 setup.py install --user

Note

We recommend the --user flag which installs the required dependencies at the user level. More information about it can be found on pip documentation.

Warning

We do not recommend the --user flag when using domain2idna into containers like - for example - Travis CI.

First steps

Make sure that you can run the following without any issue and enjoy domain2idna!!

$ domain2idna --version

Usage

As a Python module

Here’s an example which show us how domain2idna can be used a python module.

#!/usr/bin/env python3

"""
This module uses domains2idna to convert a given domain.

Author:
    Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom

Contributors:
    Let's contribute to this example!!

Repository:
    https://github.com/PyFunceble/domain2idna
"""
from domain2idna import domain2idna

DOMAINS = [
    "bittréẋ.com", "bịllogram.com", "coinbȧse.com", "cryptopiạ.com", "cṙyptopia.com"
]

# The following return the result of the whole list.
print("UTF-8 domains: %s" % DOMAINS)
print("Converted domains: %s" % domain2idna(DOMAINS))

# The following return the result of only one element.
print("UTF-8 domain: %s" % DOMAINS[0])
print( "Converted domain: %s" % domain2idna(DOMAINS[0]))

From a terminal

Here is the list of available command when calling domain2idna from a terminal.

usage: domain2idna [-h] [-s SUBJECT [SUBJECT ...]] [-e ENCODING] [-f FILE] [-o OUTPUT] [-v]

domain2idna - The tool to convert a domain or a file with a list of domain to the famous IDNA format.

optional arguments:
    -h, --help            show this help message and exit
    -s SUBJECT [SUBJECT ...], --subject SUBJECT [SUBJECT ...]
                            Sets the subjects to convert.
    -e ENCODING, --encoding ENCODING
                            Sets the encoding to use.
    -f FILE, --file FILE  Sets the file to read to get the domain(s) to convert.
    -o OUTPUT, --output OUTPUT
                            Sets the file where we write the converted domain(s).
    -v, --version         show program's version number and exit

Crafted with ♥ by Nissar Chababy (Funilrys)

Code documentation

domain2idna - The tool to convert a domain or a file with a list of domain to the famous IDNA format.

Author:
Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom
Contributors:
Let’s contribute to domains2idna!!
Project link:
https://github.com/PyFunceble/domain2idna
Project documentation:
http://domain2idna.readthedocs.io

License:

MIT License

Copyright (c) 2019, 2020, 2021, 2022 PyFunceble
Copyright (c) 2018, 2019, 2020, 2021, 2022 Nissar Chababy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
domain2idna.domain2idna(subject, encoding='utf-8')[source]

Process the conversion of the given subject.

Parameters:
  • subject (str, list) – The subject to convert.
  • encoding (str) – The encoding to provide.
Return type:

list, str

domain2idna.get(domain_to_convert)[source]

This function is a passerelle between the front and the backend of this module.

Parameters:domain_to_convert (str) – The domain to convert.
Returns:
str:
if a string is given.
list:
if a list is given.
Return type:str, list

Deprecated since version 1.10.0: Use domain2idna() instead.

Helpers

Problematic

How can we write, read and delete a file without having to write everytime the same thing?

Code documentation

File()
class domain2idna.helpers.File(filename)[source]

File treatment/manipulations.

Parameters:filename (str) – A path to the file to manipulate.
delete()[source]

Deletes a given file path.

Warning

We handle the case that the file does not exist.

read(encoding=None)[source]

Reads a given file path and return its content.

Parameters:encoding (str) – The encoding to use when opening the file.
Return type:str
write(data_to_write)[source]

Writes or appends data into the given file path.

Parameters:data_to_write (str) – The data to write.

Converter

Code documentation

class domain2idna.converter.Converter(subject, original_encoding='utf-8')[source]

Provides a base for every core logic we add.

Parameters:
  • subject (str, list) – The subject to convert.
  • original_encoding (str) – The encoding to provide as output.
convert_to_idna(subject, original_encoding='utf-8')[source]

Converts the given subject to IDNA.

Parameters:subject (str) – The subject to convert.
Return type:str
get_converted()[source]

Provides the converted data.

Issues

Have or found an issue with domain2idna? Please follow one of the following.

  • Fill a new issue.
  • Send a email to contactTATATAfunilrysTODTOTODcom.

Indices and tables