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
Owner
Yasin Özel
Yasin Özel
A BlackJack simulator in Python to simulate thousands or millions of hands using different strategies.

BlackJack Simulator (in Python) A BlackJack simulator to play any number of hands using different strategies The Rules To keep the code relatively sim

Hamid 4 Jun 24, 2022
This tool lets you perform some quick tasks for CTFs and Pentesting.

This tool lets you convert strings and numbers between number bases (2, 8, 10 and 16) as well as ASCII text. You can use the IP address analyzer to find out details on IPv4 and perform abbreviation a

Ayomide Ayodele-Soyebo 1 Jul 16, 2022
Backman is a random/fixed background image setter for wlroots based compositors

backman Backman is a random/fixed background image setter for wlroots based compositors Dependencies: The program depends on swaybg, python3-toml (or

Hemish 3 Mar 09, 2022
A collection of tools for biomedical research assay analysis in Python.

waltlabtools A collection of tools for biomedical research assay analysis in Python. Key Features Analysis for assays such as digital ELISA, including

Tyler Dougan 1 Apr 18, 2022
These scripts look for non-printable unicode characters in all text files in a source tree

find-unicode-control These scripts look for non-printable unicode characters in all text files in a source tree. find_unicode_control.py should work w

Siddhesh Poyarekar 25 Aug 30, 2022
Aurin - A quick AUR installer for Arch Linux. Install packages from AUR website in a click.

Aurin - A quick AUR installer for Arch Linux. Install packages from AUR website in a click.

Suleman 51 Nov 04, 2022
🚧Useful shortcuts for simple task on windows

Windows Manager A tool containg useful utilities for performing simple shortcut tasks on Windows 10 OS. Features Lit Up - Turns up screen brightness t

Olawale Oyeyipo 0 Mar 24, 2022
A utility that makes it easy to work with Python projects containing lots of packages, of which you only want to develop some.

Mixed development source packages on top of stable constraints using pip mxdev [mɪks dɛv] is a utility that makes it easy to work with Python projects

BlueDynamics Alliance 6 Jun 08, 2022
Small project to interact with python, C, HTML, JavaScript, PHP.

Micro Hidroponic Small project to interact with python, C, HTML, JavaScript, PHP. Table of Contents General Info Technologies Used Screenshots Usage P

Filipe Martins 1 Nov 10, 2021
Create password - Generate Random Password with Passphrase

Generate Random Password with Passphrase This is a python code to generate stron

1 Jan 18, 2022
Audio Steganography is a technique used to transmit hidden information by modifying an audio signal in an imperceptible manner.

Audio Steganography Audio Steganography is a technique used to transmit hidden information by modifying an audio signal in an imperceptible manner. Ab

Karan Yuvraj Singh 1 Oct 17, 2021
It is a tool that looks for a specific username in social networks

It is a tool that looks for a specific username in social networks

MasterBurnt 6 Oct 07, 2022
The Black shade analyser and comparison tool.

diff-shades The Black shade analyser and comparison tool. AKA Richard's personal take at a better black-primer (by stealing ideas from mypy-primer) :p

Richard Si 10 Apr 29, 2022
A Container for the Dependency Injection in Python.

Python Dependency Injection library aiodi is a Container for the Dependency Injection in Python. Installation Use the package manager pip to install a

Denis NA 3 Nov 25, 2022
Cleaning-utils - a collection of small Python functions and classes which make cleaning pipelines shorter and easier

cleaning-utils [] [] [] cleaning-utils is a collection of small Python functions

4 Aug 31, 2022
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.

Victor Benichoux 30 Sep 28, 2022
Manage your exceptions in Python like a PRO

A linter to manage all your python exceptions and try/except blocks (limited only for those who like dinosaurs).

Guilherme Latrova 353 Dec 31, 2022
Python utility for discovering interesting CFPreferences values on iDevices

Description Simple utility to search for interesting preferences in iDevices. Installation python3 -m pip install -U --user cfprefsmon Example In this

12 Aug 19, 2022
Analyze metadata of your Python project.

Analyze metadata of your Python projects Setup: Clone repo py-m venv venv (venv) pip install -r requirements.txt specify the folders which you want to

Pedro Monteiro de Carvalho e Silva Prado 1 Nov 10, 2021
Random Number Generator Analysis With Python

Random-Number-Generator-Analysis Governor's Honors Program Project to determine

Jack Prewitt 2 Jan 23, 2022