Skip to main content

A Python package to easily use uints/ints in Python.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uintlib-2.0.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uintlib-2.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file uintlib-2.0.0.tar.gz.

File metadata

  • Download URL: uintlib-2.0.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for uintlib-2.0.0.tar.gz
Algorithm Hash digest
SHA256 0496c664f6d8f7db27eea95de0b39481e675dd6a04fe7c28f47dc79e6362b8ec
MD5 8d1f26a9a0a706b4f62d91c922eafd30
BLAKE2b-256 eaf26016508ba191acd7c8de30bb25eee8ddb023dcf97ff3a275ef18d9c58dbb

See more details on using hashes here.

File details

Details for the file uintlib-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: uintlib-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for uintlib-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b06c2b5cb3dde2c316d744991120ff7ae132f10052f30421d55c7a04cc742d84
MD5 e8c2bdbc37cfa9939527b9337f9abaf1
BLAKE2b-256 359b6b2d7a033c1f88ae8b8a00afe1ceb20d2fa1e91017b2e7bf01a0c98cb367

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page