toil.lib.conversions

Conversion utilities for mapping memory, disk, core declarations from strings to numbers and vice versa. Also contains general conversion functions

Attributes

KIB

MIB

GIB

TIB

PIB

EIB

KB

MB

GB

TB

PB

EB

BINARY_PREFIXES

DECIMAL_PREFIXES

VALID_PREFIXES

Functions

bytes_in_unit([unit])

convert_units(num, src_unit[, dst_unit])

Returns a float representing the converted input in dst_units.

parse_memory_string(string)

Given a string representation of some memory (i.e. '1024 Mib'), return the

human2bytes(string)

Given a string representation of some memory (i.e. '1024 Mib'), return the

bytes2human(n)

Return a binary value as a human readable string with units.

b_to_mib(n)

Convert a number from bytes to mibibytes.

mib_to_b(n)

Convert a number from mibibytes to bytes.

hms_duration_to_seconds(hms)

Parses a given time string in hours:minutes:seconds,

strtobool(val)

Make a human-readable string into a bool.

opt_strtobool(b)

Convert an optional string representation of bool to None or bool

modify_url(url, remove)

Given a valid URL string, split out the params, remove any offending

Module Contents

toil.lib.conversions.KIB = 1024
toil.lib.conversions.MIB = 1048576
toil.lib.conversions.GIB = 1073741824
toil.lib.conversions.TIB = 1099511627776
toil.lib.conversions.PIB = 1125899906842624
toil.lib.conversions.EIB = 1152921504606846976
toil.lib.conversions.KB = 1000
toil.lib.conversions.MB = 1000000
toil.lib.conversions.GB = 1000000000
toil.lib.conversions.TB = 1000000000000
toil.lib.conversions.PB = 1000000000000000
toil.lib.conversions.EB = 1000000000000000000
toil.lib.conversions.BINARY_PREFIXES = ['ki', 'mi', 'gi', 'ti', 'pi', 'ei', 'kib', 'mib', 'gib', 'tib', 'pib', 'eib']
toil.lib.conversions.DECIMAL_PREFIXES = ['b', 'k', 'm', 'g', 't', 'p', 'e', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb']
toil.lib.conversions.VALID_PREFIXES = ['ki', 'mi', 'gi', 'ti', 'pi', 'ei', 'kib', 'mib', 'gib', 'tib', 'pib', 'eib', 'b', 'k', 'm',...
toil.lib.conversions.bytes_in_unit(unit='B')[source]
Parameters:

unit (str)

Return type:

int

toil.lib.conversions.convert_units(num, src_unit, dst_unit='B')[source]

Returns a float representing the converted input in dst_units.

Parameters:
Return type:

float

toil.lib.conversions.parse_memory_string(string)[source]

Given a string representation of some memory (i.e. ‘1024 Mib’), return the number and unit.

Parameters:

string (str)

Return type:

tuple[float, str]

toil.lib.conversions.human2bytes(string)[source]

Given a string representation of some memory (i.e. ‘1024 Mib’), return the integer number of bytes.

Parameters:

string (str)

Return type:

int

toil.lib.conversions.bytes2human(n)[source]

Return a binary value as a human readable string with units.

Parameters:

n (SupportsInt)

Return type:

str

toil.lib.conversions.b_to_mib(n)[source]

Convert a number from bytes to mibibytes.

Parameters:

n (int | float)

Return type:

float

toil.lib.conversions.mib_to_b(n)[source]

Convert a number from mibibytes to bytes.

Parameters:

n (int | float)

Return type:

float

toil.lib.conversions.hms_duration_to_seconds(hms)[source]

Parses a given time string in hours:minutes:seconds, returns an equivalent total seconds value

Parameters:

hms (str)

Return type:

float

toil.lib.conversions.strtobool(val)[source]

Make a human-readable string into a bool.

Convert a string along the lines of “y”, “1”, “ON”, “TrUe”, or “Yes” to True, and the corresponding false-ish values to False.

Parameters:

val (str)

Return type:

bool

toil.lib.conversions.opt_strtobool(b)[source]

Convert an optional string representation of bool to None or bool

Parameters:

b (str | None)

Return type:

bool | None

toil.lib.conversions.modify_url(url, remove)[source]

Given a valid URL string, split out the params, remove any offending params in ‘remove’, and return the cleaned URL.

Parameters:
Return type:

str