Skip to main content
https://secure.travis-ci.org/mulkieran/justbytes.png?branch=master

Justbytes

Justbytes is a module for handling computation with address ranges expressed in bytes. Its principle feature is a Range class from which can be constructed Range objects which represent a precise and finite address range in bytes. Various arithmetic operations are defined for Range objects.

Its sole purpose is the representation of real address ranges on real machines. For that reason, it does not allow powers of ranges, imprecise ranges, or non-finite ranges. In order that the usual laws of arithmetic can be maintained, it does allow fractional ranges.

Practical Computing with Address Ranges

When computing with address ranges, the numeric value can be viewed as a logical, rather than a physical, quantity. That is, unlike, e.g., mass or length, which are quantities which must be measured with a measuring instrument which has some built-in imprecision, an address range is a quantity that is not measured, but is known precisely. This precision arises because the number represents not as much an amount of memory as a number of addressable, byte-size, locations in memory.

Consequently, computations such as addition of two Ranges, and conversion between different magnitudes of bytes, i.e., from MiB to GiB, must be done precisely. The underlying implementation must therefore use a precise representation of the number of bytes. Floating point numbers, which are frequently the preferred type for the representation of physical quantities, are disallowed by this requirement.

Operations

This module does not accommodate multi-dimensionality of address ranges. Consequently, multiplying one Range object by another Range object will cause an error to be raised, since bytes^2 is not representable by the module. For most uses any operation which would yield a multi-dimensional quantity is not useful. There are no plans to adapt this package so that it can accommodate multi-dimensionality of address ranges.

Numerous computations with address ranges are nonsensical. For example, 2 raised to a power which is some address range, is a meaningless computation. All such operations cause an error to be raised.

Some computations with precise, finite, values may yield irrational results. For example, while 2 is rational, its square root is an irrational number. There is no allowed operation on Range objects which can result in an irrational Range value. It turns out that all such operations are either nonsensical or would result in a value with an unrepresentable type.

The result type of operations is a Range, where appropriate, or a subtype of Rational, where a numeric value is appropriate.

Floating Point Numbers

It is not possible to use floating point numbers or Decimal in computations with Ranges. Where a fractional quantity is desired, use Fraction objects. Thus, Range(0) * 1.2 and Range(0) * Decimal(“1.2”) raise an exception, but Range(0) * Fraction(“1.2”) is acceptable.

Computing the Representation of a Range

The representation of a Range is computed according to a specified configuration. In the default configuration, the representation uses IEC rather than SI units.

The representation of a Range is not a string, but a structured representation of the precise value, as well as the relationship of the representation to the actual value.

This representation is exposed to clients of the library, which may use it in any way.

Displaying Ranges

The Range class also has standard methods for the representation of Range objects as str objects.

The str representation can also be configured. The manipulation of the representation to form a str object is abstracted from the rest of the source to emphasize that clients of the package may choose to represent address ranges in any manner they choose.

Representing Units

The size module supplies a set of named prefixes for both SI and binary units, for all non-fractional prefixes. Fractional prefixes are not defined.

Constructing Ranges Programmatically

New Range objects can be constructed from Range objects, numeric values, e.g., int or Fraction, or strings which represent such numeric values. strings may be used to represent fractional quantities, e.g., “1.2”, but floats and Decimals are disallowed.

The constructor takes an optional units specifier, which defaults to bytes for all numeric values, and to None for Range objects. The type of the unit specifier is a named prefix supplied by the size module or a Range object.

Errors

All errors raised by justbytes operations are subtypes of the RangeError class.

Memory Consumption and Bandwidth vs. Address Ranges

Memory consumption, e.g., by a process during execution on a specified workload, is a quantity, that like address ranges, is specified in bytes. However, memory consumption is simply a measurement of the amount of a physical quantity consumed. When bytes are used only to represent memory consumption, computations do not generally require the special handling supplied by this library. Generally, measurement of memory consumption can be treated like any other physical quantity. The same reasoning applies to bandwidth. For a physical analogy, one can imagine memory consumption to be analogous to volume, e.g., litres, and bandwidth to be analogous to flow, e.g., litres per minute.

User Input

This package does not handle arbitrary user input. It is expected that the client will transform any input, from whatever source, into a number and an optional unit specification which can be passed directly to the Range constructor.

Alternative Packages

If you are interested in computing in Python with physical, rather than logical, quantities, you should consult the pint package: http://pint.readthedocs.org.

Packaging

Downstream packagers, if incorporating testing into their packaging, are encouraged to use only the tests in the test_deterministic module, to avoid testing failures that may arise due to the non-deterministic behavior of Hypothesis tests.

Metadata

Release files for justbytes 0.15.3

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

Source distribution (sdist)

Source distribution for justbytes 0.15.3
File Size Uploaded
justbytes-0.15.3.tar.gz 24.6 kB Details

Built distribution (wheel)

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

Total release size: 51.7 kB

Release files / justbytes-0.15.3.tar.gz

Download URL justbytes-0.15.3.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
815dba096750c0e0158bbc872ee1b7e2bde4551b5792e9b256e85213c690de58
BLAKE2b-256 checksum
How to use checksums
09a489fda55360d1f76d4075d645ee2ba06f7c8b3917b5896281355d2d4aab32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.7

Release files / justbytes-0.15.3-py3-none-any.whl

Download URL justbytes-0.15.3-py3-none-any.whl
Size 27.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8edafefb052691cdb11f2468825cb989cb5352e3715fed9bb97e340ae0b7ef33
BLAKE2b-256 checksum
How to use checksums
e3e738b85457eeb8d99de968b752400c564da1b0a8e8a182dd93d81dc99e1aac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.15.3 This release

2 release files

0.15.2

2 release files

0.15.1

2 release files

0.15

2 release files

0.14

1 release file

0.12

1 release file

0.11

1 release file

0.10

1 release file

0.9

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

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