utilities

This module contains utility functions for parsing various strings.

Functions

parse_datetime(string: str, default_timezone: tzinfo) → datetime[source]

Parse a timestamp string. If the timestamp does not specify a timezone, default_timezone is used.

Parameters:
  • string (str) – The string to parse.

  • default_timezone (datetime.tzinfo) – The default timezone to set.

Return type:

datetime.datetime

parse_float(string: str, *, int_max_digits: int | None = None) → Decimal[source]

Parse a literal string representing a floating point value.

Changed in version 5.1.1: Added the int_max_digits parameter.

Parameters:
  • string (str) – The string to parse.

  • int_max_digits (int) – The maximum number of digits that a binary, octal or hexadecimal literal can have once converted to a decimal value. See coerce_value() for details.

Return type:

decimal.Decimal

Raises:

ArithmeticError – string is a binary, octal or hexadecimal literal with more digits than allowed by int_max_digits.

parse_timedelta(string: str) → timedelta[source]

Parse a literal string representing a time period in the ISO-8601 duration format.

Parameters:

string (str) – The string to parse.

Return type:

datetime.timedelta