Skip to content
MobilityDB extensions for SQLAlchemy
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Update documentation Jan 8, 2020
mobilitydb_sqlalchemy Adapt parameter order to MovingPandas 0.2 Jan 7, 2020
tests Fix MovingPandas test Jan 7, 2020
.gitignore Initial commit Dec 23, 2019
.readthedocs.yml Introduce Dec 25, 2019
LICENSE.txt Create LICENSE.txt Jan 22, 2020
README.rst README.rst - Include contributing instructions Jan 22, 2020
poetry.lock Upgrade dependencies Jan 8, 2020
pyproject.toml Add optional support for using movingpandas when using TGeomPoint Dec 25, 2019 Add badges for license and download stats Jan 22, 2020


Test Status Documentation Status PyPI downloads MIT License

MobilityDB SQLAlchemy

This package provides extensions to SQLAlchemy for interacting with MobilityDB. The data retrieved from the database is directly mapped to time-indexed pandas DataFrame objects. TGeomPoint objects can be optionally mapped to movingpandas' Trajectory data structure.

Thanks to the amazing work by MobilityDB and movingpandas teams, because of which this project exists.


The package is available on PyPI, for Python >= 3.7

pip install mobilitydb-sqlalchemy


from mobilitydb_sqlalchemy import TGeomPoint

from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

class Trips(Base):
    __tablename__ = "test_table_trips_01"
    car_id = Column(Integer, primary_key=True)
    trip_id = Column(Integer, primary_key=True)
    trip = Column(TGeomPoint)

trips = session.query(Trips).all()

# Querying using MobilityDB functions, for example - valueAtTimestamp
        func.valueAtTimestamp(Trips.trip, datetime.datetime(2012, 1, 1, 8, 10, 0))

For more details, read our documentation


Issues and pull requests are welcome.

  • For proposing new features/improvements or reporting bugs, create an issue.
  • Check open issues for viewing existing ideas, verify if it is already proposed/being worked upon.
  • When implementing new features make sure to add relavant tests and documentation before sending pull requests.

Setup environment

First, make sure you have poetry installed Then, get the dependencies by running (in the project home directory):

poetry install

Also make sure you setup git hooks locally, this will ensure code is formatted using black before committing any changes to the repository

pre-commit install

Running Tests

Spin up a mobilitydb instance

docker volume create mobilitydb_data
docker run --name "mobilitydb" -d -p 25432:5432 -v mobilitydb_data:/var/lib/postgresql codewit/mobilitydb

Run the tests

movingpandas is an optional dependency - but to run tests you would need it. So if this is your first time running tests, install it by running:

# Currently installing the optional dependency of movingpandas
# using `poetry install -E movingpandas` doesn't work

# To get movingpandas use pip instead of poetry, run the following (in exact order):
poetry shell
pip install cython
pip install git+ --no-binary cartopy
pip install movingpandas

# This is because of movingpandas dependency cartopy not being PEP 518 compliant
# Refer:

Now, you can actually run the tests using:

poetry run pytest
You can’t perform that action at this time.