Bandwidth¶
netutils.bandwidth
¶
Functions for performing bandwidth calculations.
bits_to_name(speed, nbr_decimal=0)
¶
Method to convert an int value for speed int bits to the name value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
speed |
int
|
Speed in bits to be converted. |
required |
nbr_decimal |
Optional[int]
|
Precision of end result, ie number of decimal points to round to. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
str
|
Name value for speed in bits |
Examples:
>>> from netutils.bandwidth import bits_to_name
>>> bits_to_name(125000)
'125Kbps'
>>> bits_to_name(1000000000)
'1Gbps'
Source code in netutils/bandwidth.py
bytes_to_name(speed, nbr_decimal=0)
¶
Method to convert an int value for speed in bytes to the name value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
speed |
float
|
Speed in bytes to be converted. |
required |
nbr_decimal |
int
|
Precision of end result, ie number of decimal points to round to. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
str
|
Name value for speed in bytes |
Examples:
>>> from netutils.bandwidth import bytes_to_name
>>> bytes_to_name(10000.0)
'10.0KBps'
>>> bytes_to_name(10000000.0)
'10.0MBps'
Source code in netutils/bandwidth.py
name_to_bits(speed)
¶
Method to convert a short bandwidth name to int value in bps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
speed |
str
|
Bandwidth to be converted like |
required |
Returns:
Type | Description |
---|---|
int
|
value of bandwidth to be converted to bps |
Examples:
>>> from netutils.bandwidth import name_to_bits
>>> name_to_bits("10Gbps")
10000000000
>>> name_to_bits("33.6Kbps")
33600
>>> name_to_bits("2.5Gbps")
2500000000
>>> name_to_bits('100 MB')
800000000
Source code in netutils/bandwidth.py
name_to_bytes(speed)
¶
Method to convert a short bandwidth name to float value in Bps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
speed |
str
|
Bandwidth to be converted like |
required |
Returns:
Type | Description |
---|---|
float
|
value of bandwidth to be converted to Bps |
Examples:
>>> from netutils.bandwidth import name_to_bytes
>>> name_to_bytes("10Gbps")
1250000000.0
>>> name_to_bytes("100Mbps")
12500000.0
>>> name_to_bytes("100GBps")
100000000000.0
>>> name_to_bytes('100 GB')
100000000000.0
Source code in netutils/bandwidth.py
name_to_name(speed, speed_type, nbr_decimal=0)
¶
Method to convert a short bandwidth name to another bandwdth name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
speed |
str
|
Bandwidth to be converted like |
required |
speed_type |
str
|
Name to convert the bandwdth to like |
required |
nbr_decimal |
int
|
Precision of end result, ie number of decimal points to round to. Defaults to 0. |
0
|
Returns:
Type | Description |
---|---|
str
|
The named value which user wishes to return to. |
Examples:
>>> from netutils.bandwidth import name_to_name
>>> name_to_name("10Gbps", "Kbps")
'10000000.0Kbps'
>>> name_to_name("10GBps", "Kbps")
'80000000.0Kbps'
>>> name_to_name("10KBps", "Gbps", 4)
'0.0001Gbps'