Skip to content

ydb-platform/ydb-sqlalchemy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
robot
Dec 19, 2024
484bfc2 · Dec 19, 2024
Nov 28, 2024
Dec 10, 2024
Nov 15, 2024
Dec 19, 2024
Jan 24, 2024
Dec 19, 2024
Mar 31, 2023
Mar 22, 2024
Dec 10, 2024
Nov 5, 2024
Jan 25, 2024
Dec 19, 2024
Jan 25, 2024
Dec 19, 2024
Nov 13, 2024
Dec 10, 2024
Dec 19, 2023

Repository files navigation

YDB Dialect for SQLAlchemy


License Functional tests Style checks

This repository contains YQL dialect for SqlAlchemy 2.0.

Note: Dialect also works with SqlAlchemy 1.4, but it is not fully tested.

Installation

To work with current ydb-sqlalchemy version clone this repo and run from source root:

$ pip install -U .

Getting started

Connect to local YDB using SqlAlchemy:

import sqlalchemy as sa


engine = sa.create_engine("yql+ydb://localhost:2136/local")

with engine.connect() as conn:
  rs = conn.execute(sa.text("SELECT 1 AS value"))
  print(rs.fetchone())

To setup alembic to work with YDB please check this example.

Development

Run Tests:

Run the command from the root directory of the repository to start YDB in a local docker container.

$ docker-compose up

To run all tests execute the command from the root directory of the repository:

$ tox -e test-all

Run specific test:

$ tox -e test -- test/test_core.py

Check code style:

$ tox -e style

Reformat code:

$ tox -e isort
$ tox -e black-format

Run example (needs running local YDB):

$ python -m pip install virtualenv
$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python examples/example.py