⚠️ This repository is archived and no longer maintained.Use PyMEOS instead.
PyMEOS is the actively maintained Python binding for the MEOS C library underneath MobilityDB. It supersedes this driver — it covers the same psycopg2-based PostgreSQL workflow (via
pymeos.db.psycopg2.MobilityDB) and additionally provides the full MEOS API in idiomatic Python, suitable for use with MobilityDB, MobilityDuck, or standalone MEOS.This repository is preserved in archived form for historical reference and to keep existing links / citations resolvable. The deprecation notice has been in place since 2023.
MobilityDB-python is a database adapter to access MobilityDB from Python. It supports both the psycopg2 and the asyncpg adapters for PostgreSQL and uses the postgis adapter for PostGIS.
This package is no longer up-to-date with the recent and incoming changes of MobilityDB, and will no longer by maintained.
We recommend using the PyMEOS package,
which provides a Python interface to the MEOS C library, the underlying library of MobilityDB.
pip install python-mobilitydb- Python >= 3.0
- MobilityDB
Using the psycopg2 adapter for PostgreSQL
importpsycopg2frommobilitydb.psycopgimportregisterconnection=Nonetry:
# Set the connection parameters to PostgreSQLconnection=psycopg2.connect(host='localhost', database='test', user='user', password='pw')
connection.autocommit=True# Register MobilityDB data typesregister(connection)
# Open a cursor to perform database operationscursor=connection.cursor()
# Query the database and obtain data as Python objectsselect_query="SELECT * FROM tbl_tfloatseq ORDER BY k LIMIT 10"cursor.execute(select_query)
rows=cursor.fetchall()
# Print the obtained rows and call a method on the instancesforrowinrows:
print("key =", row[0])
print("tfloatseq =", row[1])
ifnotrow[1]:
print("")
else:
print("startTimestamp =", row[1].startTimestamp.isoformat(), "\n")
except (Exception, psycopg2.Error) aserror:
print("Error while connecting to PostgreSQL", error)
finally:
# Close the connectionifconnection:
connection.close()Using the asyncg adapter for PostgreSQL
importasyncioimportasyncpgfrommobilitydb.asyncpgimportregisterasyncdefrun():
# Connect to an existing databaseconnection=awaitasyncpg.connect(host='localhost', database='test', user='user', password='pw')
try:
# Register MobilityDB data typesawaitregister(connection)
# Query the database and obtain data as Python objectsselect_query="SELECT * FROM tbl_tgeompointseq ORDER BY k LIMIT 10"rows=awaitconnection.fetch(select_query)
# Print the obtained rows and call a method on the instancesforrowinrows:
print("key =", row[0])
print("tgeompointseq =", row[1])
ifnotrow[1]:
print("")
else:
print("startTimestamp =", row[1].startTimestamp.isoformat(), "\n")
finally:
# Close the connectionawaitconnection.close()
# Launch the processloop=asyncio.get_event_loop()
loop.run_until_complete(run())HTML: https://docs.mobilitydb.com/MobilityDB-python/master/
PDF: https://docs.mobilitydb.com/MobilityDB-python/master/python-mobilitydb.pdf
EPUB: https://docs.mobilitydb.com/MobilityDB-python/master/python-mobilitydb.epub
Issues and Pull Requests are welcome.
MobilityDB SQLAlchemy is another package that provides extensions to SQLAlchemy for interacting with MobilityDB.