Etherium unit conversation and arithmetic library

Overview

etherunit

Etherium unit conversation and arithmetic library

Install

pip install -u etherunit

Usage

>>> from etherunit import Ether, Gwei, Wei, E

Create a new quantity with units

You can create a new quatity like this

>> Gwei(".05") 0.05 gwei >>> Wei("5") 5 wei ">
>>> Ether(".05")
0.05 ether
>>> Gwei(".05")
0.05 gwei
>>> Wei("5")
5 wei

Or you can use the helper function E() to create a new quantity

>> E(".05 gwei") 0.05 gwei >>> E("5 wei") 5 wei ">
>>> E(".05 eth")
0.05 ether
>>> E(".05 gwei")
0.05 gwei
>>> E("5 wei")
5 wei

Arithmetic operations

Different quatities can be added together without any problems

>>> E(".05 eth") + E("2 gwei") == E("0.050000002 eth")
True

This also applies for subtraction

>>> E(".05 eth") - E("2 gwei") == E("0.049999998 eth")
True

You can also multiply quanities with other integers

>>> E(".05 eth") * 2
0.1 ether

... but not with other quatities

>>> E(".05 eth") * E("2 gwei")  # type: ignore
AssertionError: 2 gwei is not an integer

You also can't multiply quatities with other integers, like floats. Why? Because it can result with fractional wei, which is not allowed

>>> E(".05 eth") * 1.5
AssertionError: 1.5 is not an integer

You can divide quatities with other integers, the result is always a quatity

>>> E(".05 eth") / 2
0.025 ether

And you can divide quatities with other quatities, the result is always an integer

>>> E("10 eth") / E("3 eth")
3

You can find the remainder of a division with mod operator (%)

>>> E("10 eth") % E("3 eth")
1 ether

You can also use divmod() to get both the quotient and the remainder

>>> divmod(E("10 eth"), E("3 eth"))
(3, 1 ether)

Conversion

You can convert a quatity to another quatity, though it's not necessary for arithmetic operations

>> E("10 eth").wei 10000000000000000000 wei >>> (E("10 eth") % E("3 eth")).wei 1000000000000000000 wei >>> E("10 eth").wei.eth.eth.eth.eth.gwei.wei.wei.wei # :D 10000000000000000000 wei ">
>>> E("10 eth").gwei
10000000000 gwei
>>> E("10 eth").wei
10000000000000000000 wei
>>> (E("10 eth") % E("3 eth")).wei
1000000000000000000 wei
>>> E("10 eth").wei.eth.eth.eth.eth.gwei.wei.wei.wei  # :D
10000000000000000000 wei
You might also like...
Retrying is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just about anything.

Retrying Retrying is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just

About Library for extract infomation from thai personal identity card.
About Library for extract infomation from thai personal identity card.

ThaiPersonalCardExtract Library for extract infomation from thai personal identity card. imprement from easyocr and tesseract New Feature v1.3.2 🎁 In

ecowater-softner is a Python library for collecting information from Ecowater water softeners.

Ecowater Softner ecowater-softner is a Python library for collecting information from Ecowater water softeners. Installation Use the package manager p

A color library based on pokemons colors!
A color library based on pokemons colors!

pokepalette A simple pokemon color chooser " This repo is based on CDWimmer/PokePalette and was originated from this tweet. If you don't remember your

A tiny Python library for generating public IDs from integers

pids Create short public identifiers based on integer IDs. Installation pip install pids Usage from pids import pid public_id = pid.from_int(1234) #

Helpful functions for use alongside the rich Python library.

🔧 Rich Tools A python package with helpful functions for use alongside with the rich python library. 󠀠󠀠 The current features are: Convert a Pandas

ticktock is a minimalist library to view Python time performance of Python code.

ticktock is a minimalist library to view Python time performance of Python code.

A small python library that helps you to generate localization strings for your mobile projects.

LocalizationUtiltiy A small python library that helps you to generate localization strings for your mobile projects. This small script aims to help yo

The git for the Python Story Utility Package library.

SUP The git for the Python Story Utility Package library. Installation: Install SUP by simply running pip install psup in your terminal. Check out our

Owner
Yasin Özel
Yasin Özel
isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections and by type.

isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections and by type. It provides a command line utility, Python library and plugins for various editors to quickly sort all your imports.

Python Code Quality Authority 5.5k Jan 8, 2023
A library for interacting with Path of Exile game and economy data, and a unique loot filter generation framework.

wraeblast A library for interfacing with Path of Exile game and economy data, and a set of item filters geared towards trade league players. Filter Ge

David Gidwani 29 Aug 28, 2022
A Python library for reading, writing and visualizing the OMEGA Format

A Python library for reading, writing and visualizing the OMEGA Format, targeted towards storing reference and perception data in the automotive context on an object list basis with a focus on an urban use case.

Institut für Kraftfahrzeuge, RWTH Aachen, ika 12 Sep 1, 2022
RapidFuzz is a fast string matching library for Python and C++

RapidFuzz is a fast string matching library for Python and C++, which is using the string similarity calculations from FuzzyWuzzy

Max Bachmann 1.7k Jan 4, 2023
pydsinternals - A Python native library containing necessary classes, functions and structures to interact with Windows Active Directory.

pydsinternals - Directory Services Internals Library A Python native library containing necessary classes, functions and structures to interact with W

Podalirius 36 Dec 14, 2022
Library for processing molecules and reactions in python way

Chython [ˈkʌɪθ(ə)n] Library for processing molecules and reactions in python way. Features: Read/write/convert formats: MDL .RDF (.RXN) and .SDF (.MOL

null 16 Dec 1, 2022
A simple gpsd client and python library.

gpsdclient A small and simple gpsd client and library Installation Needs Python 3 (no other dependencies). If you want to use the library, use pip: pi

Thomas Feldmann 33 Nov 24, 2022
Python library to decorate and beautify strings

outputformat Python library to decorate and beautify your standard output ?? Ins

Felipe Delestro Matos 259 Dec 13, 2022
A functional standard library for Python.

Toolz A set of utility functions for iterators, functions, and dictionaries. See the PyToolz documentation at https://toolz.readthedocs.io LICENSE New

null 4.1k Dec 30, 2022
Retrying library for Python

Tenacity Tenacity is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just

Julien Danjou 4.3k Jan 5, 2023