API Documentation

This is a simple library to help you serialize Python type names and call them up again when you need them.

pytypewriter.errors

Sometimes things go wrong.

exception pytypewriter.errors.PyTypewriterException(message: str, inner: Exception = None)[source]

Bases: Exception

This is the base exception for other exceptions defined in this library.

property inner

Get the exception that caused this exception.

property message

Get the exception message.

pytypewriter.exchange

Document exchange… data exchange… it all starts here!

class pytypewriter.exchange.Exportable[source]

Bases: abc.ABC

Objects that can be exported as and loaded from simple data types should extend Exportable to make their intentions clear and their methods consistent.

abstract export() → Mapping[str, Any][source]

Export the instance as a mapping of simple types.

Returns

the mapping

abstract classmethod load(data: Mapping[str, Any]) → Any[source]

Create an instance from a mapping.

Parameters

data – the data

Returns

the instance

pytypewriter.exchange.export(exportable: pytypewriter.exchange.Exportable) → Mapping[str, Any][source]

Export an Exportable including meta-data.

Parameters

exportable – the exportable

Returns

the mapping

Note

This function will add a __type__ key containing the fully-qualified type name.

See also

pytypewriter.exchange.load(data: Mapping[str, Any]) → Any[source]
Parameters

data – a mapping that represents the type

Returns

the type instance

Note

The mapping must contain a __type__ key that contains the fully-qualified type name.

See also

pytypewriter.types

If you’re dealing with Python types, deal here.

exception pytypewriter.types.InvalidTypeException(message: str, inner: Exception = None)[source]

Bases: pytypewriter.errors.PyTypewriterException

Raised when an attempt is made to retrieve an non-existent type from a fully-qualified name.

See also

pycls

pytypewriter.types.pycls(fqn: str) → TypeVar[source]

Get the class to which a fully-qualified name (FQN) refers.

Parameters

fqn – the fully-qualified name of the class

Returns

the class described by the fully-qualified name (FQN)

pytypewriter.types.pyfqn(obj) → str[source]

Get the fully-qualified name (FQN) of an object’s type.

Parameters

obj – the object

Returns

the fully-qualified type name