Skip to main content

DataValues

Pypi MIT licensed GitHub Release Date

DataValues is a Python package for handling data sizes (bits/bytes) with full support for both SI (decimal) and IEC (binary) prefixes.

Features

  • Supports bits and bytes
  • Full range of SI (kilo, mega, giga, …) and IEC (kibi, mebi, gibi, …) units
  • Accurate conversions between decimal/binary forms
  • Parsing strings to corresponding units
  • Intuitive comparisons (>, <, ==, >=, <=)
  • Safe arithmetic with unit awareness (+, -, *, /, +=, etc.)
  • Simple API that feels natural in Python

Installation

# PyPi Installation
pip install datavalues
# GitHub Installation
pip install git+'https://github.com/bnassif/datavalues.git' 

Getting Started

Coversion

from datavalues import MegaByte, Byte

# Convert using explicit classes
print(MegaByte(1).convert(Byte))
# 1000000.0 B

# Convert using string parsing
print(MegaByte(1).convert('byte'))
# 1000000.0 B

String Parsing

from datavalues import from_string

from_string('16GiB')
# GibiByte(16)
from_string('1000 megabytes')
# MegaByte(1000)

from datavalues import get_unit

get_unit('tebibytes')
# <class 'datavalues.binary.bytes.TebiByte'>
get_unit('GB')
# <class 'datavalues.metric.bytes.GigaByte'>

Comparisons

from datavalues import *

GigaByte(1) > MegaByte(500)
# True
KibiByte(1024) == MebiByte(1)
# True

Arithmetic

from datavalues import *

GigaByte(1) - MegaByte(175)
# GigaByte(0.825)

KibiByte(1024) + MebiByte(14)
# KibiByte(15360.0)

GibiByte(1) / MebiByte(256)
# 4.0

GibiByte(1) / 4
# GibiByte(0.25)

Byte(250) * 4
# Byte(1000)

Why?

This project originally started as a way to reconcile differences in how NetBox reports and stores data sizes for disks and memory, specifically to align its expectations with the reality reported by hosts.

Soon after, many other applications were found, including:

  • Computing data transfer times
  • Comparing and calculating data & bandwidth units
  • Determining storage requirements for backup retention policies

Thus, datavalues transitioned to a fully-featured library.

Supported Units

Below are tables detailing all available units of measurement for data provided by the datavalues library.

Additional units will be added to this library as they are officially adopted.

SI

SI (metric) units are based on powers of 10 (base-1000). These units use standard metric prefixes such as kilo-, mega-, and giga-, and can be applied to both bits and bytes.

For more details on the SI/metric prefixes, visit the Wikipedia article.

Bits

SI/metric bits are most commonly used in network transport measurements (e.g., Mbps, Gbps).

Unit Symbol Bit Conversion Class
Bit b 1 bit datavalues.base.core.Bit
Kilobit kb 10³ bits datavalues.metric.bits.KiloBit
Megabit Mb 10⁶ bits datavalues.metric.bits.MegaBit
Gigabit Gb 10⁹ bits datavalues.metric.bits.GigaBit
Terabit Tb 10¹² bits datavalues.metric.bits.TeraBit
Petabit Pb 10¹⁵ bits datavalues.metric.bits.PetaBit
Exabit Eb 10¹⁸ bits datavalues.metric.bits.ExaBit
Zettabit Zb 10²¹ bits datavalues.metric.bits.ZettaBit
Yottabit Yb 10²⁴ bits datavalues.metric.bits.YottaBit
Ronnabit Rb 10²⁷ bits datavalues.metric.bits.RonnaBit
Quettabit Qb 10³⁰ bits datavalues.metric.bits.QuettaBit

Bytes

SI/metric bytes (e.g., MB, GB) are widely used in marketing and user-facing representations of storage capacity.

Historically, these units were often used ambiguously to represent binary quantities.
The IEC 60027-2 standard introduced IEC/binary units to remove this ambiguity, though SI units are still commonly used.

Unit Symbol Byte Conversion Class
Byte B 1 byte datavalues.base.core.Byte
Kilobyte kB 10³ bytes datavalues.metric.bytes.KiloByte
Megabyte MB 10⁶ bytes datavalues.metric.bytes.MegaByte
Gigabyte GB 10⁹ bytes datavalues.metric.bytes.GigaByte
Terabyte TB 10¹² bytes datavalues.metric.bytes.TeraByte
Petabyte PB 10¹⁵ bytes datavalues.metric.bytes.PetaByte
Exabyte EB 10¹⁸ bytes datavalues.metric.bytes.ExaByte
Zettabyte ZB 10²¹ bytes datavalues.metric.bytes.ZettaByte
Yottabyte YB 10²⁴ bytes datavalues.metric.bytes.YottaByte
Ronnabyte RB 10²⁷ bytes datavalues.metric.bytes.RonnaByte
Quettabyte QB 10³⁰ bytes datavalues.metric.bytes.QuettaByte

IEC

IEC (binary) units are based on powers of 2 (base-1024). These units use binary prefixes such as kibi-, mebi-, and gibi-, and are most commonly applied to bytes in computing contexts.

For more details on the IEC/binary prefixes, visit the Wikipedia article.

Bits

IEC/binary bits (e.g., Kib, Mib) are defined for consistency with binary prefixes, but are rarely used in practice compared to their byte counterparts.

Unit Symbol Bit Conversion Class
Bit b 1 bit datavalues.base.core.Bit
Kibibit Kib 2¹⁰ bits datavalues.binary.bits.KibiBit
Mebibit Mib 2²⁰ bits datavalues.binary.bits.MebiBit
Gibibit Gib 2³⁰ bits datavalues.binary.bits.GibiBit
Tebibit Tib 2⁴⁰ bits datavalues.binary.bits.TebiBit
Pebibit Pib 2⁵⁰ bits datavalues.binary.bits.PebiBit
Exbibit Eib 2⁶⁰ bits datavalues.binary.bits.ExbiBit
Zebibit Zib 2⁷⁰ bits datavalues.binary.bits.ZebiBit
Yobibit Yib 2⁸⁰ bits datavalues.binary.bits.YobiBit
Robibit Rib 2⁹⁰ bits datavalues.binary.bits.RobiBit
Quebibit Qib 2¹⁰⁰ bits datavalues.binary.bits.QuebiBit

Bytes

IEC/binary bytes (e.g., KiB, MiB, GiB) are most commonly used in operating systems and technical contexts to represent storage and memory.

These units were standardized by IEC 60027-2 to clearly distinguish binary-based values from SI/metric units.

Unit Symbol Byte Conversion Class
Byte B 1 byte datavalues.base.core.Byte
Kibibyte KiB 2¹⁰ bytes datavalues.binary.bytes.KibiByte
Mebibyte MiB 2²⁰ bytes datavalues.binary.bytes.MebiByte
Gibibyte GiB 2³⁰ bytes datavalues.binary.bytes.GibiByte
Tebibyte TiB 2⁴⁰ bytes datavalues.binary.bytes.TebiByte
Pebibyte PiB 2⁵⁰ bytes datavalues.binary.bytes.PebiByte
Exbibyte EiB 2⁶⁰ bytes datavalues.binary.bytes.ExbiByte
Zebibyte ZiB 2⁷⁰ bytes datavalues.binary.bytes.ZebiByte
Yobibyte YiB 2⁸⁰ bytes datavalues.binary.bytes.YobiByte
Robibyte RiB 2⁹⁰ bytes datavalues.binary.bytes.RobiByte
Quebibyte QiB 2¹⁰⁰ bytes datavalues.binary.bytes.QuebiByte

License

MIT - Feel free to use, extend, and contribute.

Metadata

Release files for datavalues 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datavalues 1.1.0
File Size Uploaded Provenance Actions
datavalues-1.1.0.tar.gz 12.3 kB With provenance Details for datavalues-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datavalues 1.1.0
File Interpreter ABI Platform Actions
datavalues-1.1.0-py3-none-any.whl Python 3 none any Details for datavalues-1.1.0-py3-none-any.whl

Total release size: 22.9 kB

Release files / datavalues-1.1.0.tar.gz

Download URL datavalues-1.1.0.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
62b45fba3cb046f87fc3d28a3d424f1d230db8c2973f4ca44c914d1f84d0b129
BLAKE2b-256 checksum
How to use checksums
28912053021cc555742bce013c14e6562c987e3c5aaab8b32ee42ded638909cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 7, 2026.

Transparency log

Release files / datavalues-1.1.0-py3-none-any.whl

Download URL datavalues-1.1.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa548a082379d772bce3144ce88c3e9bd6d36ddeae47ef96e2e18284be80c501
BLAKE2b-256 checksum
How to use checksums
132ca8975843e37398f9c4b88424c6ba7697d8984de80e50d41709c975b3c748
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 7, 2026.

Transparency log

Security for datavalues 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for datavalues-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page