Skip to content

Getting started

TileORM connects a Pydantic model to a collection in Tile38. You define the model. TileORM builds the Tile38 commands.

Install TileORM with pip:

Terminal window
pip install tileorm

TileORM needs a running Tile38 server. See the Tile38 documentation for install steps.

Create a Tile38 client. Point it at your server.

from tileorm import Tile38
db = Tile38("redis://localhost:9851")

A model is a Pydantic model with TileORM fields. Every model needs one Identifier field and one location field (PointField, BoundsField, or GeoHashField).

from tileorm import CharField, Group, Identifier, Model, Point, PointField
class Truck(Model):
id: int = Identifier()
group: str = Group()
location: Point = PointField()
field: str = CharField()
class Meta:
database = db

The Meta.database attribute tells the model which Tile38 client to use.

Call Model.create() with a value for each field, plus a location. create() saves the object to Tile38 and returns the model instance.

from tileorm import Point
truck1 = await Truck.create(
id=1,
group="fleet1",
location=Point(lat=52.25, lon=13.37),
field="value",
)

Call Model.get() with the identifier and any group values. get() returns a model instance built from the stored object.

truck = await Truck.get(id=1, group="fleet1")
# Truck(id=1, location=Point(lat=52.25, lon=13.37), group='fleet1', field='value')