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
Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.

Lark - Parsing Library & Toolkit 3.5k Jan 05, 2023
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
✨ Un générateur de mot de passe aléatoire totalement fait en Python par moi, et en français.

Password Generator ❗ Un générateur de mot de passe aléatoire totalement fait en Python par moi, et en français. 🔮 Grâce a une au module random et str

MrGabin 3 Jul 29, 2021
🍰 ConnectMP - An easy and efficient way to share data between Processes in Python.

ConnectMP - Taking Multi-Process Data Sharing to the moon 🚀 Contribute · Community · Documentation 🎫 Introduction : 🍤 ConnectMP is the easiest and

Aiden Ellis 1 Dec 24, 2021
A script to parse and display buy_tag and sell_reason for freqtrade backtesting trades

freqtrade-buyreasons A script to parse and display buy_tag and sell_reason for freqtrade backtesting trades Usage Copy the buy_reasons.py script into

Robert Davey 31 Jan 01, 2023
A python package containing all the basic functions and classes for python. From simple addition to advanced file encryption.

A python package containing all the basic functions and classes for python. From simple addition to advanced file encryption.

PyBash 11 May 22, 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
a demo show how to dump lldb info to ida.

用一个demo来聊聊动态trace 这个仓库能做什么? 帮助理解动态trace的思想。仓库内的demo,可操作,可实践。 动态trace核心思想: 动态记录一个函数内每一条指令的执行中产生的信息,并导入IDA,用来弥补IDA等静态分析工具的不足。 反编译看一下 先clone仓库,把hellolldb

25 Nov 28, 2022
MongoDB utility to inflate the contents of small collection to a new larger collection

MongoDB Data Inflater ("data-inflater") The data-inflater tool is a MongoDB utility to automate the creation of a new large database collection using

Paul Done 3 Nov 28, 2021
More routines for operating on iterables, beyond itertools

More Itertools Python's itertools library is a gem - you can compose elegant solutions for a variety of problems with the functions it provides. In mo

2.9k Jan 06, 2023
Tools to connect to and interact with the Mila cluster

milatools The milatools package provides the mila command, which is meant to help with connecting to and interacting with the Mila cluster. Install Re

Mila 32 Dec 01, 2022
This python program will display all SSID usernames and SSID passwords you once connected to your laptop

Windows-Wifi-password-extractor This python program will display all SSID usernames and SSID passwords you once connected to your laptop How to run th

Bhaskar Pal 3 Apr 26, 2022
Data Utilities e.g. for importing files to onetask

Use this repository to easily convert your source files (csv, txt, excel, json, html) into record-oriented JSON files that can be uploaded into onetask.

onetask.ai 1 Jul 18, 2022
A simple and easy to use Spam Bot made in Python!

This is a simple spam bot made in python. You can use to to spam anyone with anything on any platform.

7 Sep 08, 2022
A Python utility belt containing simple tools, a stdlib like feel, and extra batteries. Hashing, Caching, Timing, Progress, and more made easy!

Ubelt is a small library of robust, tested, documented, and simple functions that extend the Python standard library. It has a flat API that all behav

Jon Crall 638 Dec 13, 2022
iOS Snapchat parser for chats and cached files

ParseSnapchat iOS Snapchat parser for chats and cached files Tested on Windows and Linux install required libraries: pip install -r requirements.txt c

11 Dec 05, 2022
Dependency injection lib for Python 3.8+

PyDI Dependency injection lib for python How to use To define the classes that should be injected and stored as bean use decorator @component @compone

Nikita Antropov 2 Nov 09, 2021
Minimal Windows system information tool written in Python

wfetch wfetch is a Minimal Windows system information tool written in Python (Only works on Windows) Installation First of all have python installed.

zJairO 3 Jan 24, 2022
Tool for generating Memory.scan() compatible instruction search patterns

scanpat Tool for generating Frida Memory.scan() compatible instruction search patterns. Powered by r2. Examples $ ./scanpat.py arm.ks:64 'sub sp, sp,

Ole André Vadla Ravnås 13 Sep 19, 2022
MicroMIUI - Script to optimize miui and not only

MicroMIUI - Script to optimize miui and not only

Groiznyi-Studio 1 Nov 02, 2021