Skip to content

Why Typical?🔖

There are many libaries out there that do some or most of what Typical can do. Why should you pick Typical out of the pack? Here’s a short list:

  1. Simplicity.

    • Typical doesn’t require you to learn a new DSL - all you need to know is how to use Python’s standard type-annotations.
  2. No Metaclasses.

    • Typical doesn’t use metaclasses. We don’t infect your inheritance. When you wrap a class with @typic.al, the class you get is the one you defined. That’s it.
  3. Flexibility.

    • Typical works for you and doesn’t enforce arbitrarily strict rules.
    • Because of an emphasis on simplicity and an aversion to inheritance-mangling, you’re free to use this library as it works for your use-case.
  4. Performance.

    • Typical is the fastest pure-Python (no Cython!) library out there. Just check out the histograms below. It achieves this performance with finely-tuned code-generation which allows Typical to localize namespaces and minimize branching logic.
  5. Compliance.

    • Typical is fully-compliant with PEP 563. The entire codebase uses the annotations future, and this is the recommended mode of operation for all consumers of this library, unlike Pydantic.

Benchmarks🔖

The following benchmarks Typical’s three public APIs against on Python 3.9:

As can be seen, Typical’s three APIs are consistently faster than all three libraries, without the need for Cython as a build-dependency, making it far more portable than other libraries on this list.

Validation Only🔖

Typical is 25% faster, on average, than the nearest alternative when validating data, and up to 8X faster when validating invalid data.

Average time (in μs) for validation of invalid data in
a complex, nested
object.

Average time (in μs) for validation of valid data in a
complex, nested object.

Deserialization & Validation🔖

Typical is comparable in performance to the nearest alternative when deserializing valid data into your model, and up to 4x faster when deserializing invalid data.

Average time (in μs) for attempted deserialization of
invalid data in a complex, nested
object.

Average time (in μs) for deserialization of valid data in a
complex, nested object.

Serialization & Validation🔖

Typical is consistently 3-4x faster than the nearest alternative when serializing data to JSON, and requires no additional configuration of your JSON library to dump your models.

It should be noted that at the time of this writing, both Pydantic and Marshmallow will passively allow or ignore invalid data in certain cases by default. This was the case with the test-case used for these benchmarks, which can be found here.

Average time (in μs) for attempted serialization of
invalid data in a complex, nested
object.

Average time (in μs) for serialization of valid data in
a complex, nested object.

Translate to an Arbitrary Class🔖

Typical supports automated translation of one known, custom class to an unknown, unlike other popular libraries.

Average time (in μs) for translation of a known class
to another unknown class a complex, nested
object.

Translate from an Arbitrary Class🔖

Typical also supports translation from an arbitrary class to a known class. Pydantic supports this feature with the from_orm() method.

Average time (in μs) for translation of a known class
to another unknown class a complex, nested
object.