Skip to main content

MobilityDB extensions to SQLAlchemy

Project description

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 and TGeogPoint 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.

This project is built using PyMEOS

A demo webapp built using this library is now available online:

Live Demo: https://mobilitydb-sqlalchemy-demo.adonmo.com

Source Code: https://github.com/adonmo/mobilitydb-sqlalchemy-demo

Installation

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

pip install mobilitydb-sqlalchemy

Usage

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
session.query(
    Trips.car_id,
    func.asText(
        func.valueAtTimestamp(Trips.trip, datetime.datetime(2012, 1, 1, 8, 10, 0))
    ),
).all()

There is also a tutorial published on Anita Graser’s blog.

For more details, read our documentation (specifically, the quickstart).

Contributing

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:

poetry install -E movingpandas

Now, you can actually run the tests using:

poetry run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mobilitydb-sqlalchemy-0.3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mobilitydb_sqlalchemy-0.3-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file mobilitydb-sqlalchemy-0.3.tar.gz.

File metadata

  • Download URL: mobilitydb-sqlalchemy-0.3.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.5 Linux/5.7.12-arch1-1

File hashes

Hashes for mobilitydb-sqlalchemy-0.3.tar.gz
Algorithm Hash digest
SHA256 262e5b6e6017e1593b8edd63c4a30829bae78a9b5049a9c6b240ec92f4a10ae3
MD5 6dff972709be3791bd0f6b55f6c36a56
BLAKE2b-256 531fc0a3dd85b4f7c68c56d76b18bcca3196c7bdc3957441a34f25300898c752

See more details on using hashes here.

File details

Details for the file mobilitydb_sqlalchemy-0.3-py3-none-any.whl.

File metadata

  • Download URL: mobilitydb_sqlalchemy-0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.5 Linux/5.7.12-arch1-1

File hashes

Hashes for mobilitydb_sqlalchemy-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cee50cb52edc6c66046ea8b724f5743cc9433a474ea4a7938328490c83c75aee
MD5 12951e2e6a40e3388e883b609fbcdb5b
BLAKE2b-256 15fa40f2a2837aa4d983c91b6f39141fd7ed7cb227528ef6a395fc3c99781c93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page