py-pane
pane is a modern data conversion and dataclass library for Python.
There are many existing dataclass libraries for Python. pane gains in composibility,
flexibility, and simplicity because it treats validating a dataclass as a special case
of general type conversion. This base layer is built with robust support for product types,
tagged & untagged unions, and custom predicates.
Features
- Conversion between arbitrary types
- Helpful, detailed error messages
- Conversion to and from dataclasses
- Optional fields
- Field renaming
- Conversion from tuples & dicts
- Dataclass inheritance
- Generic dataclasses
- Condition (field validators)
- First class typing support
- Tagged & untagged unions
- Composable conversion
- Custom converters and hooks for extension
Installation
pane is available from PyPI. To install:
pane deliberately has very few depedencies, and has no binary dependencies.
Supported datatypes
pane aims to support a broad range of standard library and third-party datatypes.
Currently, the following datatypes are supported:
Standard library
Sequence/collection types:
list/typing.Listtuple/typing.Tuple/typing.Sequence/collections.abc.Sequenceset/typing.Set/collections.abc.Setfrozenset/typing.FrozenSet/collections.abc.FrozenSetcollections.deque/typing.Deque
Tuple types:
- Heterogeneous:
tuple[int, str]/t.Tuple[int, str] - Homogeneous:
tuple[int, ...]/t.Tuple[int, ...] - Empty:
tuple[()]/t.Tuple[()]
Mapping types:
dict/typing.Dict/typing.Mapping/typing.MutableMapping/collections.abc.Mapping/collections.abc.MutableMappingcollections.defaultdict/typing.DefaultDictcollections.OrderedDict/typing.OrderedDictcollections.Counter
String/bytes types:
strbytesbytearray
Numeric types:
intfloatcomplexdecimal.Decimalfraction.Fraction
Datetime types:
datetime.datetimedatetime.datedatetime.time
Path-like types:
os.PathLike(currentlystronly, notbytes)pathlib.Path/pathlib.PurePathpathlib.WindowsPath/pathlib.PureWindowsPathpathlib.PosixPath/pathlib.PurePosixPath
Other scalar types:
boolNonere.Pattern/typing.Pattern
Third-party datatypes
numpy.ndarray/NDArray[]
Supported typing constructs
In addition, pane attempts to fully support modern Python type hints. This includes the following:
typing.Uniontyping.Optionaltyping.TypeVartyping.Generictyping.Literaltyping.Anytyping.Annotated
Comparison to other libraries
Coming soon