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
In the end, we hope this helps to contribute to a bigger ENS community and wider ENS adoption !
The NameHash Python Implementation of ENS Normalize is now available here:
You can also try it in a Google Colab Notebook.
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 !
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:
- Advocated for inclusion of all characters regularly used in languages such as Polish which we think is valuable for future ENS adoption.
- Identified various bugs and provided suggested solutions.
- 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:
- A carefully crafted glossary for some of the technical ideas related to ENS names.
- Optimized modeling of normalization errors, including detailed error information.
- Implemented “ens_cure” - an algorithm that can “cure” many normalization errors that would fail ens_normalize.
- Python documentation with real-world examples.
- 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).
- 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.
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.
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.
- ENSIP-15 Github Directory
- Python Implementation of ENS Normalize
- ENS DAO Governance Forum: ENS Name Normalization Part 1
- ENS DAO Governance Forum: ENS Name Normalization Part 2
- ENS Forum Proposal for replacing the ENSIP-1 Name Syntax with ENSIP-15
- ENS Townhall Q3 Recording
- Python ENS Documentation
- Python Interface for Ethereum
- Web3.py: 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.