Getting started
TileORM connects a Pydantic model to a collection in Tile38. You define the model. TileORM builds the Tile38 commands.
Install
Section titled “Install”Install TileORM with pip:
pip install tileormTileORM needs a running Tile38 server. See the Tile38 documentation for install steps.
Connect to Tile38
Section titled “Connect to Tile38”Create a Tile38 client. Point it at your server.
from tileorm import Tile38
db = Tile38("redis://localhost:9851")Define a model
Section titled “Define a model”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 = dbThe Meta.database attribute tells the model which Tile38 client to use.
Create an object
Section titled “Create an object”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",)Get an object back
Section titled “Get an object back”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')Next steps
Section titled “Next steps”- Defining models covers every field type.
- Querying covers
get,find, andnearby.