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 addresses/networks, MAC addresses, BGP ASNs, VLANs and network interfaces.
Installation
pip install netsome
Features
- IPv4 address and network manipulation (addresses, networks, interfaces)
- 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,
MacAddress,
ASN,
VID,
Community,
Interface,
)
# Create and manipulate IPv4 addresses
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"
# 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.3.25.tar.gz
(12.5 kB
view details)
Built Distribution
netsome-0.3.25-py3-none-any.whl
(16.8 kB
view details)
File details
Details for the file netsome-0.3.25.tar.gz
.
File metadata
- Download URL: netsome-0.3.25.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5684a1756a30d3672626dd2d2567bbb52ec691456b7f58abeb4bc90ca30e8f9d |
|
MD5 | 44c9fef3a5e037b0b9ba2b694d6dfc8d |
|
BLAKE2b-256 | eebe14474a91b5cc9ede3b8d46c9771dd16183d931c7f66ad661f623d92cc118 |
File details
Details for the file netsome-0.3.25-py3-none-any.whl
.
File metadata
- Download URL: netsome-0.3.25-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5df8de95012ff72350dcf980efc430e66f93b58e99d5be7f39f4f0c1071af76c |
|
MD5 | 344d03389603e09254cdf199124e3fff |
|
BLAKE2b-256 | c17fa4aa6aedc4542b45b409b58060d2b5aed7289c31a466c7b16cab24a0b2e7 |