Python Implementation of ENS Normalize

Python ENS Normalize

What We Built

NameHash has built and open sourced a Python implementation of ENS Normalize.

This work is based on the (proposed) new ENS Normalize Standard and becomes the second implementation of this new standard, joining the existing reference implementation in Javascript.

What this impacts

This library means Python developers can now normalize ENS names!

With many Ethereum tools and libraries written in Python, the Python implementation of the ENS Normalize library makes it easier to integrate ENS into new and existing Python applications.

This means ENS just became even more accessible for developers around the world to incorporate into their applications :rocket:

In the end, we hope this helps to contribute to a bigger ENS community and wider ENS adoption !

Give it a try

The NameHash Python Implementation of ENS Normalize is now available here:

You can also try it in a Google Colab Notebook.

Why We Built It

NameHash is building a platform with fun new ways to discover and register ENS names. Some of these features required a Python implementation of the new ENS Normalize. None existed yet. So our team put a special effort into creating one. We’ve open sourced our results to help empower builders from all parts of the ENS and Web3 community. We’re excited to see what others will create with it !

NameHash contributions to the new ENS Normalize Standard

The journey to build a new ENS Normalization Standard has been a long one ! There’s been a large effort, led by raffy.eth, and involving many contributors, to advance this new standard. Our team has been closely following each step in this effort. For more than a year, each time there’s been updates to raffy.eth’s Javascript implementation, our team would implement parallel updates to this Python implementation.

In general we’ve been followers behind raffy.eth here. But we’ve also made an effort to positively influence the standard in a few ways. This includes:

  1. Advocated for inclusion of all characters regularly used in languages such as Polish which we think is valuable for future ENS adoption.
  2. Identified various bugs and provided suggested solutions.
  3. Proposed the need for ens_normalize_fragment which is important for substring searches of normalized names.

The Python library we’re open sourcing also includes a few new features that go beyond a minimal implementation of the standard:

  1. A carefully crafted glossary for some of the technical ideas related to ENS names.
  2. Optimized modeling of normalization errors, including detailed error information.
  3. Implemented “ens_cure” - an algorithm that can “cure” many normalization errors that would fail ens_normalize.
  4. Python documentation with real-world examples.
  5. A developer guide for improving and updating the Python library.

This library includes an exhaustive testing and validation effort to ensure compatibility with the standard:

  • Passes 100% of the official validation tests (validated automatically with pytest).
  • Passes an additional suite of further tests for compatibility with the official Javascript reference implementation.
  • Provides 100% code testing coverage.
  • Passes all of these tests across Linux, MacOS, and Windows.

The Python ENS Normalize library demonstrates there can be multiple mature implementations of the new ENS Normalization standard. We hope this library and the careful testing that went into its creation increases confidence for the ENS DAO to approve the new ENS Normalize.

New Feature: ens_cure

This algorithm can “cure” many normalization errors that would fail ens_normalize. ens_cure is NOT a part of the ENS Normalization Standard, but might be a useful utility for some situations. For example, if a user input fails ens_normalize, a user could be prompted with a more helpful error message such as: “Did you mean curedname.eth?”. Here’s a Venn diagram (not to scale) that summarizes how ens_cure expands the set of input values that can be normalized.

New Feature: Optimized modeling of normalization errors

Users just looking to normalize names in Python are free to ignore these new features and simply catch Python Exception objects with user-friendly messages.

As a quick summary: we’ve created a “hierarchy” for handling normalizations, cures, and errors:

  • A “normalizable sequence” which represents a change that must be made to the input name to confirm with the normalization standard, e.g. uppercase to lowercase conversion.
  • A “curable sequence” which represents an issue with the input name that is not normalizable through ens_normalize, but that might be resolved through a specific change suggestion in the input name, e.g. removing a space.
  • A “disallowed sequence” which represents an issue that cannot be cured through ens_cure automatically because it is challenging to describe the specific substring transformation that might be needed.

Full details on the optimized modeling of normalization errors can be in the GitHub repo.

This error hierarchy enabled our implementation of ens_cure:

  • ens_normalize automatically applies “normalizations”.
  • ens_cure automatically applies “normalizations” and “cures”.
  • “disallowed sequences” continue to be thrown from both ens_normalize and ens_cure.

Additional Resources Related to Python ENS Normalize

Other Popular Python libraries for web3

  • A Python library for interacting with the Ethereum blockchain, which provides functionality for sending transactions, querying data, and interacting with smart contracts.
  • Brownie: A Python-based development framework for building smart contracts and dApps on the Ethereum blockchain. It includes a built-in testing framework, an interactive console, and other tools for developing and deploying smart contracts.
  • eth-utils: A Python library that provides utility functions for working with Ethereum data types, such as addresses, hashes, and private keys.
  • eth-abi: A Python library that provides functions for encoding and decoding Ethereum contract ABI (Application Binary Interface) data.
  • py-solc-x: A Python library for compiling Solidity smart contracts into bytecode for deployment on the Ethereum blockchain.

Outstanding work! Will you reach out to web3py to integrate your work?

I hope you’ll apply for a retroactive bounty from the Ecosystem WG.


We agree @lightwalker.eth – please fill this out: DeForm


Thanks @nick.eth and @slobo.eth ! We’ve submitted the form you’ve linked :+1:

And we definitely want to see web3py updated to support the latest ENS normalize. We’ve begun some initial outreach to the web3py community to discuss integrating our work.


@nick.eth We have created an issue in web3py repository: Update ENS normalization to new standard · Issue #2967 · ethereum/ · GitHub
We can prepare Pull Request if web3py is interested.

1 Like

Outstanding. I can’t speak for the team, but I imagine anything that lowers the barrier to getting it implemented would be welcome.