Skip to main content

IEEE 802 MAC-48, EUI-48, EUI-64, or a 20-octet IP over InfiniBand link-layer addresses

Project description

hardware-address

IEEE 802 MAC-48, EUI-48, EUI-64, and InfiniBand hardware addresses for Python.

PyPI version License Python versions

A fast, memory-safe library for working with hardware addresses, powered by Rust.

Installation

pip install hardware_address

Features

  • 🚀 Fast: Native Rust implementation with Python bindings
  • 🔒 Memory Safe: Written in Rust for guaranteed memory safety
  • 🎯 Type Safe: Full type hints and IDE autocomplete support
  • 📦 Zero Dependencies: No external dependencies
  • 🔄 Multiple Formats: Parse and format addresses in colon, hyphen, or dot-separated formats

Quick Start

from hardware_address import MacAddr

# Parse from string
addr = MacAddr.parse("00:00:5e:00:53:01")

# Create from bytes
addr = MacAddr.from_bytes(b"\x00\x00\x5e\x00\x53\x01")

# String representation
print(str(addr))   # "00:00:5e:00:53:01"
print(repr(addr))  # MacAddr("00:00:5e:00:53:01")

# Get bytes
data = bytes(addr)

# Comparison and hashing
if addr1 == addr2:
    print("Addresses match!")

# Use as dictionary key
devices = {addr: "Server 1"}

Supported Address Types

MacAddr (6 bytes)

IEEE 802 MAC-48/EUI-48 addresses:

from hardware_address import MacAddr

addr = MacAddr.parse("00:00:5e:00:53:01")
print(addr)  # 00:00:5e:00:53:01

Eui64Addr (8 bytes)

EUI-64 addresses used in IPv6 and other protocols:

from hardware_address import Eui64Addr

addr = Eui64Addr.parse("02:00:5e:10:00:00:00:01")
print(addr)  # 02:00:5e:10:00:00:00:01

InfiniBandAddr (20 bytes)

IP over InfiniBand link-layer addresses:

from hardware_address import InfiniBandAddr

addr = InfiniBandAddr.parse(
    "00:00:00:00:fe:80:00:00:00:00:00:00:02:00:5e:10:00:00:00:01"
)

Parsing Formats

All address types support three parsing formats:

from hardware_address import MacAddr

# Colon-separated (standard)
addr1 = MacAddr.parse("00:00:5e:00:53:01")

# Hyphen-separated (Windows style)
addr2 = MacAddr.parse("00-00-5e-00-53-01")

# Dot-separated (Cisco style)
addr3 = MacAddr.parse("0000.5e00.5301")

# All produce the same address
assert addr1 == addr2 == addr3

API Reference

Creating Addresses

# From string
addr = MacAddr.parse("00:00:5e:00:53:01")

# From bytes
addr = MacAddr.from_bytes(b"\x00\x00\x5e\x00\x53\x01")

Converting Addresses

# To string (default format)
s = str(addr)  # "00:00:5e:00:53:01"

# To bytes
data = bytes(addr)  # b'\x00\x00\x5e\x00\x53\x01'

# Representation for debugging
r = repr(addr)  # MacAddr("00:00:5e:00:53:01")

Comparison Operations

# Equality
if addr1 == addr2:
    print("Equal")

# Ordering
if addr1 < addr2:
    print("addr1 is less than addr2")

# Hashing (use as dict key)
devices = {addr: "Device 1"}

Error Handling

from hardware_address import MacAddr

try:
    addr = MacAddr.parse("invalid")
except ValueError as e:
    print(f"Parse error: {e}")

try:
    addr = MacAddr.from_bytes(b"\x00\x00")  # Wrong length
except ValueError as e:
    print(f"Invalid length: {e}")

Performance

This library is implemented in Rust and compiled to native code, providing:

  • Parsing: ~10-50x faster than pure Python implementations
  • Memory: Zero-copy operations where possible
  • Safety: No buffer overflows or memory leaks

Type Hints

Full type hints are included for IDE support:

from hardware_address import MacAddr
from typing import Dict

def process_address(addr: MacAddr) -> bytes:
    return bytes(addr)

devices: Dict[MacAddr, str] = {}
devices[MacAddr.parse("00:00:5e:00:53:01")] = "Server"

Platform Support

Pre-built wheels are available for:

  • Linux: x86_64, i686, aarch64, armv7
  • macOS: x86_64 (Intel), aarch64 (Apple Silicon)
  • Windows: x64, x86
  • Python: 3.8, 3.9, 3.10, 3.11, 3.12

License

Licensed under either of:

at your option.

Links

Contributing

Contributions are welcome! See the repository for details.

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

hardware_address-0.2.0.tar.gz (33.2 kB view details)

Uploaded Source

Built Distributions

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

hardware_address-0.2.0-cp37-abi3-win_amd64.whl (144.4 kB view details)

Uploaded CPython 3.7+Windows x86-64

hardware_address-0.2.0-cp37-abi3-win32.whl (138.0 kB view details)

Uploaded CPython 3.7+Windows x86

hardware_address-0.2.0-cp37-abi3-musllinux_1_2_x86_64.whl (414.0 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ x86-64

hardware_address-0.2.0-cp37-abi3-musllinux_1_2_i686.whl (444.3 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ i686

hardware_address-0.2.0-cp37-abi3-musllinux_1_2_armv7l.whl (501.7 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ ARMv7l

hardware_address-0.2.0-cp37-abi3-musllinux_1_2_aarch64.whl (412.0 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ ARM64

hardware_address-0.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (245.4 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

hardware_address-0.2.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (270.4 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ s390x

hardware_address-0.2.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (366.8 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ppc64le

hardware_address-0.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (236.9 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARMv7l

hardware_address-0.2.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (230.8 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

hardware_address-0.2.0-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl (264.7 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.5+ i686

hardware_address-0.2.0-cp37-abi3-macosx_11_0_arm64.whl (212.7 kB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

hardware_address-0.2.0-cp37-abi3-macosx_10_12_x86_64.whl (224.2 kB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file hardware_address-0.2.0.tar.gz.

File metadata

  • Download URL: hardware_address-0.2.0.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.6

File hashes

Hashes for hardware_address-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c5356786b33bf45d5c0b81bf7473b24bf8e859c058067b9d28fffd7bd0e28cb0
MD5 9c0348472321278ae802808c3df94fa1
BLAKE2b-256 9eb82c82020f52d58fec364618777e44d8201d00934082b19b3cc59b7ec16b02

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c11f901ec8b33968713176d124d724f38855553776cace18ed4abf71a4633bef
MD5 339a41f9b9c049eca8355806048c9421
BLAKE2b-256 4c914caf993a369826492034a5d8db01ec0d164644941b545f8f6632d86b680a

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-win32.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 303d2413a4609cb5321802dab443796617d1b32e5c0b61b3cfae308658ef714b
MD5 ba04f6448443875060c13204b12e8762
BLAKE2b-256 53c2df65745fd9f76cfcc27a90e90035439ac95b2fcd3bb5509a2862bb4ae06e

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c211c145aab1f4a352f9158c465de68c4bbf657ba6b8f2b22834512853cf6a42
MD5 d59b092b7b9050e1bfa7ad4d18a70557
BLAKE2b-256 80dbf298e949194d837349c5fad1783d997edf65f9e484a1b788278c6e35ca27

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 218f4d0cd9dfc2d0e198439106b2b73904ed7656916f4108b8aa5d3bff028a34
MD5 bf13471379cdf3bbdbb62a3f8466c6e2
BLAKE2b-256 74e1a0ec5949df849f678dc1a777b1119fe9cf995b4d0a8498180ef0bf8db860

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 f6b51448840ae6498a597f17ab48234d35934b9939b75acce9e5102944a09c6a
MD5 6b62ee87ab6db53d857467b2ee87aef2
BLAKE2b-256 50a3fd7e27f44d795dc9c38b3e7cac52fc24c196d9c08fadc5e38cb6444856e1

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f08d6d228d121bd56a883f4dfb436eb46a8ba369057b922645f72c4ab4b2536f
MD5 4db357e1bbf299803e0b64706e429525
BLAKE2b-256 6019723bb66732b030bc166d471248641dbcd816b732ac99752a8c80cc1a8901

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3342cfcd13a274d8dbf6110caa65604a552fc67370c2984429354fef40893dca
MD5 bc08947a1c6b5f0bd979cf30adc23a66
BLAKE2b-256 18e2d4e3ec6a73b7d25f364f63c891af2a162d36855f3e99c8b604322003a394

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 f7c0863e2817c6610d4a2efaa789438663a222d838ac8c37702f4ac082af0ece
MD5 0d430e6a603023a297feb4d3db19d0a4
BLAKE2b-256 63b7bd4098a4358e627cccce27e9d4512a6be5d6f9312fb2dc5232c2792258ca

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 1dfeadf3100e706b1762f000212f8a4b0423de2e96edc057e5a7a3f3134db067
MD5 fd96aac20b44187167a7782465362961
BLAKE2b-256 d473a04a77068c680ae53e546287ca5e23ed3b3c9c73922bbe00ded31015388d

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 3719ea66aecd920e2c5da781a9b87a7d4b12a57272c4b3257f6e7e18d987133f
MD5 c9eb8665e1ab07c970219bfe88cadefe
BLAKE2b-256 530f2e2044f66e72380963c028c7f979adeac980afdb90a1596dc90efd5c6f0b

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 be3834aa38068568c9403a7149fcb2145e9bcf8acbd162b90d407c82a61a2da5
MD5 6ec482bfbb764257f912b4402859a784
BLAKE2b-256 bc47b61bd591887a0c88501c52339d68968ba5a46972d95324a3deb3625dcc97

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 4b0a2db47f892f9f67a4cbe9d427958b80e9660f7d8677181c9cd13ea6d90416
MD5 0ca297e82813f5859f12ea7dfd675fce
BLAKE2b-256 1200a61c4b73f622c27a7c8a3307e6deebfbb7bdeb23568dd0b81d8a76efbb51

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 93a874a1cc1ef650e6318e6c0ec100d44d96048aa041f8aec40bf8f309070394
MD5 fcdc8918004d722f97975b18fb2cdad6
BLAKE2b-256 090748d050d256213721f5087d8d37e791f4c4d5a42679a329c20f91150c6115

See more details on using hashes here.

File details

Details for the file hardware_address-0.2.0-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for hardware_address-0.2.0-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4576b99a8a157c6565ef3d49cc8db0d9cef84b326445f9c6b728c6f400497866
MD5 8c0fee355f72ed7167be15a19a32fe85
BLAKE2b-256 e7a58ba6da0197b216d62795a3843657d3265df2edec65fb0adbf7617fa86ea7

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