Skip to main content

PGSpider Dialect for SQLAlchemy

Project description

sqlalchemy-pgspider

A SQLAlchemy Dialect for PGSpider.

Overview

This is a module that allows you to connect to PGSpider using SQLAlchemy's PostgreSQL Dialect.

SQLAlchemy PostgreSQL Dialect uses the string obtained from pg_catalog.version() to determine whether it is PostgreSQL or not, and Postgres Dialect cannot be used to connect to PGSpider.

sqlalchemy-pgspider inherits PostgreSQL Dialect and overrides the part that checks version information, so that it can connect to PGSpider while retaining PostgreSQL Dialect functionality.

note
Only psycopg2 DBAPI is supported.

Requirements

  • SQLALchemy 1.4.27 or higher
  • psycopg2 (or psycopg2-binary) 2.9 or higher
  • Python 3.7 or higher

Almost all features supported by PostgreSQL's psycopg2 in SQLAlchemy 1.4.28 are available.
Other versions have not been tested.

Installation

Packages can be installed from either PyPI or GitHub.

Install package from PyPI.

pip install sqlalchemy-pgspider

from GitHub.

pip install git+https://github.com/pgspider/sqlalchemy-pgspider

Usage

To connect to PGSpider with SQLAlchemy, the following URL pattern can be used:

pgspider+psycopg2://<username>:<password>@<host>:<port>/<dbname>

Instead of the pgspier+psycopg2:, you can also use pgspider:.
The behaviour is the same whichever you use.

pgspider://<username>:<password>@<host>:<port>/<dbname>

For more detailed usage, see the SQLAlchemy PostgreSQL psycopg2 documentation.
Just change the drivername part of the URL pattern in the documentation from postgresql+psycopg2 to pgspider+psycopg2(or pgspider) to work.

See Also:
SQLAlchemy 1.4 Documentation Dialects PostgreSQL
https://docs.sqlalchemy.org/en/14/dialects/postgresql.html

Sample code

from sqlalchemy import create_engine, text

engine = create_engine("pgspider+psycopg2://pgspider:password@localhost:4813/pgspiderdb")

with engine.connect() as conn:
    conn.execute(text("CREATE TABLE users (id SERIAL NOT NULL PRIMARY KEY, name text)"))
    conn.execute(text("INSERT INTO users (name) VALUES ('Bea'), ('Eddy'), ('Lily')"))

    result = conn.execute(text("SELECT * FROM users WHERE name='Lily'"))
    for row in result:
       print(row)

    conn.execute(text("DROP TABLE users"))

Running this code would output the following string.

(3, 'Lily')

Although not included in the sample code, the SQLAlchemy ORM can also be used.

Testing

Requirements

  • A PGSpider instance up and running
  • pytest >= 7.1.1 installed on the testing machine

Procedure

  1. Clone this repository
  2. Change tests/conftest.py as appropriate
  3. 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

sqlalchemy_pgspider-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

sqlalchemy_pgspider-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_pgspider-0.1.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_pgspider-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.11 Linux/5.15.0-60-generic

File hashes

Hashes for sqlalchemy_pgspider-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c76c79180b0051afe6b08338ab7bb2856922825cf70c673dee6662e5baedf5f8
MD5 3918f836ed4482181f355749d682e4e2
BLAKE2b-256 af3cf454ee4b38aeb859b1401a12544036fdf4e17212af0f5699d24ad107ab7d

See more details on using hashes here.

File details

Details for the file sqlalchemy_pgspider-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_pgspider-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52bc9b93dc7f03bc6094a55afb66321f677659077c12490e106d35f64cc43e1a
MD5 0defbb0885840f62c42dd6ae574d9f76
BLAKE2b-256 d047fafb2bc47974ba72667c501779f99ef30475cd694b3d00697c1fca5b3035

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