Skip to main content

uintlib

A simple, lightweight Python library providing fixed-size unsigned and signed integer types
(UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64) with correct wrapping behavior
and easy arithmetic operations. Perfect for network programming, binary protocols, emulation, and low-level data manipulation.


Why?

Python's built-in integers are unbounded and do not overflow, which is convenient but not suitable for all use cases, especially when working with:

  • Binary protocols requiring precise bit widths
  • Network packet parsing and construction
  • Emulators or hardware interfacing code
  • Embedded systems data serialization/deserialization
  • Situations where overflow behavior must match C, Rust, Go, or other languages

This library provides integer classes that behave like fixed-size integers in low-level languages, including overflow wrapping and bit masking.


Features

  • Fixed bit widths: 8, 16, 32, and 64 bits
  • Both unsigned (UInt*) and signed (Int*) types
  • Proper overflow wrapping on arithmetic operations (+, -)
  • Supports comparison operators (==, !=, <, >, etc.)
  • Intuitive constructor with automatic bit masking
  • Supports integer conversion via int()
  • Easy to extend or customize
  • Lightweight, no external dependencies

Installation

You can install from PyPI (once published) using:

pip install uintlib

Usage

from uintlib.uint import UInt8, Int16, UInt32, Int64

a = UInt8(250)
b = UInt8(10)

print(a + b)          # UInt8(4) — wraps around at 255 (250 + 10 = 260 → 4)
print(int(a + b))     # 4 as Python int

x = Int16(-20000)
y = Int16(10000)

print(x + y)          # Int16(-10000) — correct 16-bit signed overflow
print(int(x + y))     # -10000

# Comparisons work as expected
print(a == UInt8(4))  # True
print(x < y)          # True

Metadata

Release files for uintlib 2.0.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 uintlib 2.0.0
File Size Uploaded
uintlib-2.0.0.tar.gz 5.4 kB Details

Built distribution (wheel)

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

Total release size: 11.0 kB

Release files / uintlib-2.0.0.tar.gz

Download URL uintlib-2.0.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0496c664f6d8f7db27eea95de0b39481e675dd6a04fe7c28f47dc79e6362b8ec
BLAKE2b-256 checksum
How to use checksums
eaf26016508ba191acd7c8de30bb25eee8ddb023dcf97ff3a275ef18d9c58dbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / uintlib-2.0.0-py3-none-any.whl

Download URL uintlib-2.0.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b06c2b5cb3dde2c316d744991120ff7ae132f10052f30421d55c7a04cc742d84
BLAKE2b-256 checksum
How to use checksums
359b6b2d7a033c1f88ae8b8a00afe1ceb20d2fa1e91017b2e7bf01a0c98cb367
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

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