typed-format-version: Python API Reference
typed_format_version
typed-format-version: load format.version.{major,minor} from a structured file.
This module tries to parse a format.version "section" in some raw data that
may have been loaded from a configuration file, and determines whether that
section contains valid "major" and "minor" integer values. The caller can
then choose the correct schema to validate the loaded data against, e.g. by
using the typedload
library with the correct top-level dataclass definition.
The most commonly used function will probably be get_version()
: it takes
a raw data dictionary and returns a Version
object with a major
and minor
integer attributes, if the data contained a valid "format" dictionary with
a "version" dictionary within it. Optionally the get_version()
function can
remove the top-level "format" member, if a true value is passed for the pop
argument.
VERSION = '0.2.1'
module-attribute
The typed_format_version
library's version.
Format
dataclass
LoadError
Version
dataclass
The format version number.
Source code in typed_format_version/__init__.py
major: int
class-attribute
The major version number.
minor: int
class-attribute
The minor version number.
VersionMatch
dataclass
Matched version number and exactness.
Source code in typed_format_version/__init__.py
failonextra: bool
class-attribute
True if the match was exact, false if the minor version number was higher.
version: Version
class-attribute
The matched version number.
VersionTuple
Bases: NamedTuple
The format version number as a tuple for easier comparison and matching.
Source code in typed_format_version/__init__.py
major: int
class-attribute
The major version number.
minor: int
class-attribute
The minor version number.
determine_version_match(version, schemas)
Figure out which schema to load and whether to allow extra fields.
If there is an exact major.minor version match, return the specified
version and set the failonextra
field to true, so that the data
matches the specification exactly.
If there is no exact match, but there are versions with the same major
number and a minor number that is lower than the specified one, then
return the highest one among them (still lower than the specified one) and
set the failonextra
field to false, so as to allow extra fields ostensibly
defined in a later format version.
Source code in typed_format_version/__init__.py
get_format(data, *, pop=False)
Get the known attributes of the format member (only the version).
Source code in typed_format_version/__init__.py
get_format_and_load(data, dtype, *, pop=False, **kwargs)
Get the format attributes, load and validate the data itself.
Source code in typed_format_version/__init__.py
get_version(data, *, pop=False)
get_version_and_load(data, dtype, *, pop=False, **kwargs)
Get the version attributes, load and validate the data itself.
Source code in typed_format_version/__init__.py
get_version_t(data, *, pop=False)
get_version_t_and_load(data, dtype, *, pop=False, **kwargs)
Get the version attributes, load and validate the data itself.