Module zut

Reusable Python utilities (top-level API).

Functions

add_command(subparsers, handle, *[, name, ...])

Add the given function or module as a command.

add_package_commands(subparsers, package)

Add all sub modules of the given package as commands.

build_netloc(*[, hostname, port, username, ...])

build_url(*[, scheme, hostname, port, ...])

check_completed_subprocess(cp[, logger, ...])

Improve message in case of subprocess error, to ease debugging.

configure_logging(*[, level, manage_exit])

configure_smb_credentials([user, password, once])

convert(value, to, *[, nullval, if_none])

convert_str_args(func, *args)

convert_to_bool(value, *[, nullval, if_none])

convert_to_date(value, *[, nullval, if_none])

convert_to_datetime(value, *[, nullval, if_none])

convert_to_decimal(value, *[, nullval, if_none])

convert_to_int(value, *[, nullval, if_none])

dump(data, *, dst[, tabular, truncate, ...])

Dump an object (if data is not an iterable) or a an iterable of dicts or iterables (if data is an iterable).

dump_object(data, *[, dst, truncate, ...])

Export any data object, in JSON format, or using pretty print.

duration_iso_string(duration)

erase_live()

Erase text written using write_live().

exec_command(handle[, args, default])

get_bool_variable(name[, fallback])

Read an environment variable as a boolean value.

get_description_text(docstring)

get_exit_code(return_value)

get_help_text(doc)

get_int_variable(name[, fallback])

Read an environment variable as an integer value.

get_lang()

Return current locale lang, for example: fr_FR.

get_list_variable(name[, fallback, sep])

Read an environment variable as a list value.

get_locale_decimal_separator()

get_logging_dict_config(*[, level, manage_exit])

get_secret_variable(name[, fallback])

Read a secret value from an environment variable if given, or from the file indicated by environment variable {name}_FILE if given, or from the file /run/secrets/{name} if the application is running in a Docker container.

get_variable(name[, fallback])

Read an environment variable.

gigi_bytes(value)

Convert from bytes to GigiBytes.

hide_url_password(url)

human_bytes(value, *[, unit, divider, ...])

Get a human-readable representation of a number of bytes.

human_number(value, *[, unit, divider, ...])

Get a human-readable representation of a number.

in_docker_container()

Indicate whether the application is running in a Docker container.

is_aware(value)

is_falsy(value)

is_iterable_of(iterable, element_type)

is_naive(value)

is_tabular_path(path)

is_truthy(value)

kili_bytes(value)

Convert from bytes to KiliBytes.

load_tabular(src, *[, headers, encoding, ...])

make_aware(value[, tz, after1970])

Make a datetime aware in timezone tz (use tz=None or tz='localtime' for the system local timezone).

make_naive(value[, tz, after1970])

Make a datetime naive and expressed in timezone tz (use tz=None or tz='localtime' for the system local timezone).

megi_bytes(value)

Convert from bytes to MegiBytes.

now_aware([tz, ms])

Get the current datetime in the timezone tz (use tz=None or tz='localtime' for the system local timezone).

now_naive_utc(*[, ms])

Get the current datetime in expressed as a naive UTC.

parse_bool(value)

parse_date(value, *[, accept_localized])

parse_datetime(value, *[, accept_localized])

parse_decimal(value[, to, accept_localized])

parse_ipaddress_or_none(address[, version])

Check if the given string is a valid IP address, if yes, return the IPv4Address or IPv6Address object, otherwise return None.

parse_list(value, *[, separator])

parse_tz([tz])

parse_uuid_or_none(uuid[, version])

Check if the given string is a valid UUID, if yes, return the UUID object, otherwise return None.

register_locale([name])

Register a locale for the entire application (system default locale if argument value is None).

resolve_host(host, *[, timeout, ip_version])

Make a DNS resolution with a timeout.

run_command(handle[, args, default])

skip_utf8_bom(fp[, encoding])

Skip UTF8 byte order mark, if any.

slugify(value, *[, separator, keep, ...])

Generate a slug.

slugify_snake(value[, separator, if_none])

CamèlCase => camel_case

tabular_dumper([dst, headers, truncate, ...])

Export tabular data, in CSV format, or using tabulate.

tabular_loader(src, *[, headers, encoding, ...])

today()

topological_sort(source)

Perform a topological sort.

use_locale([name])

Use a locale temporary (in the following thread-local block/context).

write_live(text[, newline])

Write text to stdout, keeping track of what was written, so that it can be erased next time.

Classes

Color()

ColoredFormatter([fmt, datefmt, style, ...])

ColoredRecord(record)

ColumnsProvider()

CsvDumper([dst, headers, truncate, ...])

CsvFormat(*[, encoding, delimiter, ...])

CsvLoader(src, *[, headers, add_columns, ...])

ExitHandler()

A logging handler that counts warnings and errors.

ExtendedConfigParser(*args[, list_separator])

ExtendedJSONEncoder(**kwargs)

Adapted from: django.core.serializers.json.DjangoJSONEncoder

Filter(spec, *[, normalize])

Filters(specs, *[, normalize])

Header([name, key, type, sql_type, ...])

JSONApiClient(*args, **kwargs)

NoopDumper(*args, **kwargs)

Row(provider, values, *[, skip_convert, nullval])

TabDumper([dst, headers, truncate, ...])

TabularDumper(dst, *[, headers, truncate, ...])

Exceptions

ApiClientError(message, *[, code, ...])

NotAvailableError

NotFoundError

ParseError

SeveralFoundError

SimpleError(msg, *args, **kwargs)

An error that should result to only an error message being printed on the console, without a stack trace.