The one and only library to make your network code handsome
Project description
Netsome
A Python library for working with common networking types and conversions, including IPv4/IPv6 addresses/networks, MAC addresses, BGP ASNs, VLANs and network interfaces.
Installation
pip install netsome
Features
- IPv4 & IPv6 address and network manipulation (addresses, networks, interfaces)
- IPv6 Support: Full IPv6 address handling with compression, special address types, and IPv4-mapped addresses
- MAC address handling (MAC-48/EUI-48)
- BGP AS number conversions (asplain, asdot, asdotplus formats)
- VLAN ID validation and management
- Network interface name parsing and standardization
- Robust validation for all data types
- Type-safe implementation with proper error handling
Basic Usage
from netsome.types import (
IPv4Address,
IPv4Network,
IPv4Interface,
IPv6Address,
IPv6Network,
IPv6Interface,
MacAddress,
ASN,
VID,
Community,
Interface,
)
# IPv4 address and network manipulation
ipv4_addr = IPv4Address("192.168.1.1")
print(ipv4_addr.address) # "192.168.1.1"
print(ipv4_addr.cidr) # "192.168.1.1/32"
ipv4_net = IPv4Network("192.168.1.0/24")
print(ipv4_net.prefixlen) # 24
print(ipv4_net.netaddress) # "192.168.1.0"
ipv4_interface = IPv4Interface("192.168.1.1/24")
print(ipv4_interface.address) # "192.168.1.1"
print(ipv4_interface.network) # "192.168.1.0/24"
# IPv6 address and network manipulation
ipv6_addr = IPv6Address("2001:db8::1")
print(ipv6_addr.address) # "2001:db8::1"
print(ipv6_addr.expanded) # "2001:0db8:0000:0000:0000:0000:0000:0001"
print(ipv6_addr.is_global) # True
ipv6_net = IPv6Network("2001:db8::/32")
print(ipv6_net.prefixlen) # 32
print(len(list(ipv6_net.subnets(prefixlen=64)))) # 4294967296
ipv6_interface = IPv6Interface("2001:db8::1/64")
print(ipv6_interface.address) # "2001:db8::1"
print(ipv6_interface.network) # "2001:db8::/64"
# IPv6 special address detection
link_local = IPv6Address("fe80::1")
print(link_local.is_link_local) # True
multicast = IPv6Address("ff02::1")
print(multicast.is_multicast) # True
# Work with MAC addresses
mac = MacAddress("001122334455")
print(mac.is_unicast()) # True
print(mac.oui) # "001122"
# Handle BGP AS numbers
asn = ASN.from_asdot("64512.1")
print(asn.to_asplain()) # "4244897793"
# Work with BGP Communities
community = Community.from_str("65000:100")
print(str(community)) # "65000:100"
print(int(community)) # 4259840100
# Manage VLAN IDs
vid = VID(100)
print(vid.is_reserved()) # False
# Parse and work with network interface names
iface = Interface("eth0")
print(iface.type) # IFACE_TYPES.ETHERNET
print(iface.value) # "0"
print(iface.canonical_name) # "Ethernet0"
print(iface.abbreviated_name) # "Eth0"
Authors
- Dmitriy Kudryavtsev - author - kuderr
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
netsome-0.4.4.tar.gz
(17.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
netsome-0.4.4-py3-none-any.whl
(26.0 kB
view details)
File details
Details for the file netsome-0.4.4.tar.gz.
File metadata
- Download URL: netsome-0.4.4.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/22.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98f39ce6aeab788a55175ce2d33b8cb120cfc108a7a5dbab33e1eb806289618d
|
|
| MD5 |
a2896c422897f1b3039c66b841eb852d
|
|
| BLAKE2b-256 |
180b88dd7a46d3d39ce88062bed1653be870b477ca5ec75cbf19c9bb364fe219
|
File details
Details for the file netsome-0.4.4-py3-none-any.whl.
File metadata
- Download URL: netsome-0.4.4-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/22.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f529442d9d4eb000eb1ca022225a8059fa251569e5c9bdccfd65e6ea0f392460
|
|
| MD5 |
8965cd03dd37ec9ab6134d58c223aa10
|
|
| BLAKE2b-256 |
5be2cddb974e94f5d637b4bbc3ecde554e94b43a0aa92a0b54d5f6679734ae47
|