Reference
- class vessel.Tool(...)
Bases:
NamedTupleHolds utilities for handling incoming data.
-
create:
Callable[[list[TypeVar(_RootV)],TypeVar(_DataV)],TypeVar(_RootV)] Used for converting the incoming data to the “root” form kept in cache.
-
create:
- vessel.resolve(unit)
Get the root data for a unit.
- class vessel.Unit(data: _DataV, /, *, unique=False)
Bases:
Generic[_DataV]For subclassing only.
class User(vessel.Unit, tool = ...): ... user = User(data)
- vessel.update(unit, data, **kwargs)
Update the unit’s root with new data.
- class vessel.GetField(...)
Bases:
NamedTupleHolds information for fetching data specific to an attribute.
- class vessel.SetField(...)
Bases:
NamedTupleHolds information for handling incoming data specific to a key.
- vessel.unsafe(cls)
Context managers for raising
AttributeErrorinstead of returning :var:`.missing`.
- class vessel.Object(data: _DataV, /, *, unique=False)
Bases:
Unit[_DataV]For subclassing only.
fields = { 'id': vessel.SetField( create = lambda path, data: str(data), unique = True ), 'name': vessel.SetField( create = lambda path, data: str(data) ) } def identify(path, data): return str(data['id']) class User(vessel.Unit, fields = fields, identify = identify): id: str = vessel.GetField( select = lambda root: root['id'] ) name: str = vessel.GetField( select = lambda root: root['name'] ) data0 = {'id': 0, 'name': 'Zero'} user0 = User(data0) # <User(id=0, name='Zero')> data1 = {'id': 0, 'name': 'One'} user1 = User(data1) # <User(id=0, name='One')> user0 is user1 # True (identify matches)
- vessel.keyify(cls, data)
Get the collection key of the incoming data for an Object class.
- class vessel.List(data: _DataV, /, *, unique=False)
Bases:
Unit[_DataV]For subclassing only.
def create(path, data): return User(data) class UserStore(List, create = create): pass data = [{'id': 2, 'name': 'Two'}, {'id': 3, 'name': 'Three'}] users = UserStore(data) # [<User(id=2, name='Two')>, <User(id=2, name='Three')>]
- class vessel.Dict(data: _DataV, /, *, unique=False)
Bases:
Unit[_DataV]For subclassing only.
def create(path, data): return User(data) def keyify(path, data): reutrn str(data['id']) class UserStore(Dict, create = create, keyify = keyify): pass data = [{'id': 4, 'name': 'Four'}, {'id': 5, 'name': 'Five'}] users = UserStore(data) # {'4': <User(id=2, name='Two')>, '5': <User(id=2, name='Three')>}
- vessel.pop(unit, key)
Remove and return using the key.
- vessel.collect(cls, data, *, keyify=None, name=<function <lambda>>)
Creates a collection of
Object`s based on whether keyification has been provided (either by setting :paramref:.SetField.unique` toTrueor usingkeyify).- Parameters:
cls (
TypeVar(_ObjectV)) – Used to create thecreatefunction.data (
TypeVar(_DataV)) – Used for filling the collection with instances ofcls.keyify (
Callable[[list[list[TypeVar(_RootV)]],TypeVar(_DataV)],Hashable]) – Determines whether to useListorDictas the collection base.name (
Callable[[List|Dict],str]) – Used for fetching the name of the new collection.
- Return type:
Sequence[TypeVar(_ObjectV)] |Mapping[Hashable,TypeVar(_ObjectV)]
- class vessel.Collection(Object: _ObjectV, *args, **kwargs)
Bases:
Collection[_ObjectV]Same as
collect(), except can also be used as a typehint.
- vessel.strip(unit)
Get the fully nested raw underlying data.