All Projects → dungdm93 → sqlalchemy-trino

dungdm93 / sqlalchemy-trino

Licence: Apache-2.0 License
Trino (f.k.a PrestoSQL) dialect for SQLAlchemy.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to sqlalchemy-trino

dvhb-hybrid
A package to mix django and asyncio in one application
Stars: ✭ 45 (+125%)
Mutual labels:  sqlalchemy
fastapi-boilerplate
FastAPI boilerplate for real world production
Stars: ✭ 145 (+625%)
Mutual labels:  sqlalchemy
sqlalchemy jsonfield
SQLALchemy JSONField implementation for storing dicts at SQL independently from JSON type support
Stars: ✭ 19 (-5%)
Mutual labels:  sqlalchemy
PythonTwitchBotFramework
asynchronous twitchbot framework made in pure python
Stars: ✭ 78 (+290%)
Mutual labels:  sqlalchemy
stream2segment
A Python project to download, process and visualize medium-to-massive amount of seismic waveforms and metadata
Stars: ✭ 18 (-10%)
Mutual labels:  sqlalchemy
framequery
SQL on dataframes - pandas and dask
Stars: ✭ 63 (+215%)
Mutual labels:  sqlalchemy
fastrates
💵 Free & open source API service for current and historical foreign exchange rates.
Stars: ✭ 26 (+30%)
Mutual labels:  sqlalchemy
flask-whooshee
Customizable Flask - SQLAlchemy - Whoosh integration
Stars: ✭ 68 (+240%)
Mutual labels:  sqlalchemy
reactant
Generate code for "models, views, and urls" based on Python type annotations. Supports Django REST, SQLAlchemy, Peewee.
Stars: ✭ 14 (-30%)
Mutual labels:  sqlalchemy
Resume-Generator
A Resume builder which allows users to build their own custom resumes with details like experience,projects , skills ,education etc. Users can also have the feature to download their resumes . To contribute send PR at development branch from where it will be merged in master once checked.
Stars: ✭ 28 (+40%)
Mutual labels:  sqlalchemy
carry
Python ETL(Extract-Transform-Load) tool / Data migration tool
Stars: ✭ 115 (+475%)
Mutual labels:  sqlalchemy
telethon-session-sqlalchemy
SQLAlchemy backend for Telethon session storage
Stars: ✭ 34 (+70%)
Mutual labels:  sqlalchemy
hotpotato
Hotpotato is a space for chefs to display their creations. Follow your favorite chef. Like your favorite recipes. And find the latest gluten-free, vegetarian, and multi-culinary recipes.
Stars: ✭ 13 (-35%)
Mutual labels:  sqlalchemy
nebulo
Instant GraphQL API for PostgreSQL and SQLAlchemy
Stars: ✭ 74 (+270%)
Mutual labels:  sqlalchemy
fastapi-sqlalchemy-1.4-async
https://rogulski.it/blog/sqlalchemy-14-async-orm-with-fastapi/
Stars: ✭ 17 (-15%)
Mutual labels:  sqlalchemy
flaskbooks
A very light social network & RESTful API for sharing books using flask!
Stars: ✭ 19 (-5%)
Mutual labels:  sqlalchemy
Addax
Addax is an open source universal ETL tool that supports most of those RDBMS and NoSQLs on the planet, helping you transfer data from any one place to another.
Stars: ✭ 615 (+2975%)
Mutual labels:  trino
alchemical
SQLAlchemy 1.4+ wrapper that simplifies its use in Python applications. Can be used with Flask, FastAPI or other web frameworks.
Stars: ✭ 44 (+120%)
Mutual labels:  sqlalchemy
python-web-boilerplate
Python web template for modern web backend applications
Stars: ✭ 20 (+0%)
Mutual labels:  sqlalchemy
opentracing-utils
Convenient utilities for adding OpenTracing support in your python projects
Stars: ✭ 20 (+0%)
Mutual labels:  sqlalchemy

sqlalchemy-trino

Trino (f.k.a PrestoSQL) dialect for SQLAlchemy.

The primary purpose of this is provide a dialect for Trino that can be used with Apache Superset. But other use-cases should works as well.

Supported Trino version

Trino version 352 and higher

Installation

The driver can either be installed through PyPi or from the source code.

Through Python Package Index

pip install sqlalchemy-trino

Latest from Source Code

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

Usage

To connect from SQLAlchemy to Trino, use connection string (URL) following this pattern:

trino://<username>:<password>@<host>:<port>/catalog/[schema]

JWT authentication

You can pass the JWT token via either connect_args or the query string parameter accessToken:

from sqlalchemy.engine import create_engine
from trino.auth import JWTAuthentication

# pass access token via connect_args
engine = create_engine(
  'trino://<username>@<host>:<port>/',
  connect_args={'auth': JWTAuthentication('a-jwt-token')},
)

# pass access token via the query string param accessToken
engine = create_engine(
  'trino://<username>@<host>:<port>/?accessToken=a-jwt-token',
)

Notice: When using username and password, it will connect to Trino over TLS connection automatically.

User impersonation

It supports user impersonation with username and password based authentication only.

You can pass the session user (a.k.a., the user that will be impersonated) via either connect_args or the query string parameter sessionUser:

from sqlalchemy.engine import create_engine

# pass session user via connect_args
engine = create_engine(
  'trino://<username>:<password>@<host>:<port>/',
  connect_args={'user': 'user-to-be-impersonated'},
)

# pass session user via a query string parameter
engine = create_engine(
  'trino://<username>:<password>@<host>:<port>/?sessionUser=user-to-be-impersonated',
)

Pandas support

import pandas as pd
from pandas import DataFrame
import sqlalchemy_trino
from sqlalchemy.engine import Engine, Connection

def trino_pandas_write(engine: Engine):
    df: DataFrame = pd.read_csv("tests/data/population.csv")
    df.to_sql(con=engine, schema="default", name="abcxyz", method="multi", index=False)

    print(df)


def trino_pandas_read(engine: Engine):
    connection: Connection = engine.connect()
    df = pd.read_sql("SELECT * FROM public.foobar", connection)

    print(df)

Note: in df.to_sql following params is required:

  • index=False because index is not supported in Trino.
  • method="multi": currently method=None (default) is not working because Trino dbapi is not support executemany yet
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].