Skip to main content

A database adapter to access MobilityDB from Python

Project description

MobilityDB-python

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.

Deprecation Notice :warning:

This package is no longer maintained. Instead, we recommend using the PyMEOS package, which provides a Python interface to the MEOS C library, which is the underlying library of MobilityDB.

Install

pip install python-mobilitydb

Requirements

  • Python >= 3.0
  • MobilityDB

Basic Usage

Using the psycopg2 adapter for PostgreSQL

import psycopg2
from mobilitydb.psycopg import register

connection = None

try:
    # Set the connection parameters to PostgreSQL
    connection = psycopg2.connect(host='localhost', database='test', user='user', password='pw')
    connection.autocommit = True

    # Register MobilityDB data types
    register(connection)

    # Open a cursor to perform database operations
    cursor = connection.cursor()

    # Query the database and obtain data as Python objects
    select_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 instances
    for row in rows:
        print("key =", row[0])
        print("tfloatseq =", row[1])
        if not row[1]:
            print("")
        else:
            print("startTimestamp =", row[1].startTimestamp.isoformat(), "\n")

except (Exception, psycopg2.Error) as error:
    print("Error while connecting to PostgreSQL", error)

finally:
    # Close the connection
    if connection:
        connection.close()

Using the asyncg adapter for PostgreSQL

import asyncio
import asyncpg
from mobilitydb.asyncpg import register


async def run():
    # Connect to an existing database
    connection = await asyncpg.connect(host='localhost', database='test', user='user', password='pw')

    try:
        # Register MobilityDB data types
        await register(connection)

        # Query the database and obtain data as Python objects
        select_query = "SELECT * FROM tbl_tgeompointseq ORDER BY k LIMIT 10"
        rows = await connection.fetch(select_query)

        # Print the obtained rows and call a method on the instances
        for row in rows:
            print("key =", row[0])
            print("tgeompointseq =", row[1])
            if not row[1]:
                print("")
            else:
                print("startTimestamp =", row[1].startTimestamp.isoformat(), "\n")
    finally:
        # Close the connection
        await connection.close()

# Launch the process
loop = asyncio.get_event_loop()
loop.run_until_complete(run())

Manual

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

Contributing

Issues and Pull Requests are welcome.

Related Project

MobilityDB SQLAlchemy is another package that provides extensions to SQLAlchemy for interacting with MobilityDB.

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

python-mobilitydb-0.1.3.tar.gz (53.2 kB view details)

Uploaded Source

Built Distribution

python_mobilitydb-0.1.3-py3-none-any.whl (133.3 kB view details)

Uploaded Python 3

File details

Details for the file python-mobilitydb-0.1.3.tar.gz.

File metadata

  • Download URL: python-mobilitydb-0.1.3.tar.gz
  • Upload date:
  • Size: 53.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for python-mobilitydb-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c161f1e0c15929115da1f6a9f42589350bb3d8835bd4e8ea3c4d5cd437385313
MD5 ff081e78a49418513384d6458e25ea14
BLAKE2b-256 1975be4a37c859a6ef7258f0fe3d0c49fdab891a0edbd93239bdc5e1c4bee613

See more details on using hashes here.

File details

Details for the file python_mobilitydb-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for python_mobilitydb-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5c3f60b9e79bf4cacec566dafc8afe11a9ffc918689e221bd9594fb7623f2438
MD5 8bd8c2e1f2862f5e4e989a008abfe930
BLAKE2b-256 fe53328d2cf993905f5e524389f8cd2ab90b546ffe5f088c4344894b7c78ee49

See more details on using hashes here.

Supported by

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