ydb-sqlalchemy 0.1.9__tar.gz → 0.1.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. ydb_sqlalchemy-0.1.11/PKG-INFO +198 -0
  2. ydb_sqlalchemy-0.1.11/README.md +178 -0
  3. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/requirements.txt +1 -1
  4. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/setup.py +1 -1
  5. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/test/test_suite.py +286 -1
  6. ydb_sqlalchemy-0.1.11/ydb_sqlalchemy/_version.py +1 -0
  7. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/__init__.py +5 -0
  8. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/compiler/base.py +23 -2
  9. ydb_sqlalchemy-0.1.11/ydb_sqlalchemy/sqlalchemy/datetime_types.py +74 -0
  10. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/test_sqlalchemy.py +10 -0
  11. ydb_sqlalchemy-0.1.11/ydb_sqlalchemy/sqlalchemy/types.py +141 -0
  12. ydb_sqlalchemy-0.1.11/ydb_sqlalchemy.egg-info/PKG-INFO +198 -0
  13. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy.egg-info/requires.txt +1 -1
  14. ydb_sqlalchemy-0.1.9/PKG-INFO +0 -104
  15. ydb_sqlalchemy-0.1.9/README.md +0 -84
  16. ydb_sqlalchemy-0.1.9/ydb_sqlalchemy/_version.py +0 -1
  17. ydb_sqlalchemy-0.1.9/ydb_sqlalchemy/sqlalchemy/datetime_types.py +0 -28
  18. ydb_sqlalchemy-0.1.9/ydb_sqlalchemy/sqlalchemy/types.py +0 -80
  19. ydb_sqlalchemy-0.1.9/ydb_sqlalchemy.egg-info/PKG-INFO +0 -104
  20. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/LICENSE +0 -0
  21. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/MANIFEST.in +0 -0
  22. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/pyproject.toml +0 -0
  23. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/setup.cfg +0 -0
  24. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/test/__init__.py +0 -0
  25. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/test/conftest.py +0 -0
  26. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/test/test_core.py +0 -0
  27. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/test/test_inspect.py +0 -0
  28. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/test/test_orm.py +0 -0
  29. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/__init__.py +0 -0
  30. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/compiler/__init__.py +0 -0
  31. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/compiler/sa14.py +0 -0
  32. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/compiler/sa20.py +0 -0
  33. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/dbapi_adapter.py +0 -0
  34. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/dml.py +0 -0
  35. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/json.py +0 -0
  36. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy/sqlalchemy/requirements.py +0 -0
  37. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy.egg-info/SOURCES.txt +0 -0
  38. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy.egg-info/dependency_links.txt +0 -0
  39. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy.egg-info/entry_points.txt +0 -0
  40. {ydb_sqlalchemy-0.1.9 → ydb_sqlalchemy-0.1.11}/ydb_sqlalchemy.egg-info/top_level.txt +0 -0
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.1
2
+ Name: ydb-sqlalchemy
3
+ Version: 0.1.11
4
+ Summary: YDB Dialect for SQLAlchemy
5
+ Home-page: http://github.com/ydb-platform/ydb-sqlalchemy
6
+ Author: Yandex LLC
7
+ Author-email: ydb@yandex-team.ru
8
+ License: Apache 2.0
9
+ Keywords: SQLAlchemy YDB YQL
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: sqlalchemy<3.0.0,>=1.4.0
16
+ Requires-Dist: ydb>=3.21.6
17
+ Requires-Dist: ydb-dbapi>=0.1.10
18
+ Provides-Extra: yc
19
+ Requires-Dist: yandexcloud; extra == "yc"
20
+
21
+ # YDB Dialect for SQLAlchemy
22
+ ---
23
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/ydb-platform/ydb-sqlalchemy/blob/main/LICENSE)
24
+ [![PyPI version](https://badge.fury.io/py/ydb-sqlalchemy.svg)](https://badge.fury.io/py/ydb-sqlalchemy)
25
+ [![API Reference](https://img.shields.io/badge/API-Reference-lightgreen.svg)](https://ydb-platform.github.io/ydb-sqlalchemy/api/index.html)
26
+ [![Functional tests](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/tests.yml/badge.svg)](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/tests.yml)
27
+ [![Style checks](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/style.yml/badge.svg)](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/style.yml)
28
+
29
+ This repository contains YQL dialect for SqlAlchemy 2.0.
30
+
31
+ ---
32
+
33
+ **Documentation**: <a href="https://ydb-platform.github.io/ydb-sqlalchemy" target="_blank">https://ydb-platform.github.io/ydb-sqlalchemy</a>
34
+
35
+ ---
36
+
37
+ **Note**: Dialect also works with SqlAlchemy 1.4, but it is not fully tested.
38
+
39
+
40
+ ## Installation
41
+
42
+ ### Via PyPI
43
+ To install ydb-sqlalchemy from PyPI:
44
+
45
+ ```bash
46
+ $ pip install ydb-sqlalchemy
47
+ ```
48
+
49
+ ### Installation from source code
50
+ To work with current ydb-sqlalchemy version clone this repo and run from source root:
51
+
52
+ ```bash
53
+ $ pip install -U .
54
+ ```
55
+
56
+ ## Getting started
57
+
58
+ Connect to local YDB using SqlAlchemy:
59
+
60
+ ```python3
61
+ import sqlalchemy as sa
62
+
63
+
64
+ engine = sa.create_engine("yql+ydb://localhost:2136/local")
65
+
66
+ with engine.connect() as conn:
67
+ rs = conn.execute(sa.text("SELECT 1 AS value"))
68
+ print(rs.fetchone())
69
+
70
+ ```
71
+
72
+ ## Authentication
73
+
74
+ To specify credentials, you should pass `credentials` object to `connect_args` argument of `create_engine` method.
75
+
76
+ ### Static Credentials
77
+
78
+ To use static credentials you should specify `username` and `password` as follows:
79
+
80
+ ```python3
81
+ engine = sa.create_engine(
82
+ "yql+ydb://localhost:2136/local",
83
+ connect_args = {
84
+ "credentials": {
85
+ "username": "...",
86
+ "password": "..."
87
+ }
88
+ }
89
+ )
90
+ ```
91
+
92
+ ### Token Credentials
93
+
94
+ To use access token credentials you should specify `token` as follows:
95
+
96
+ ```python3
97
+ engine = sa.create_engine(
98
+ "yql+ydb://localhost:2136/local",
99
+ connect_args = {
100
+ "credentials": {
101
+ "token": "..."
102
+ }
103
+ }
104
+ )
105
+ ```
106
+
107
+ ### Service Account Credentials
108
+
109
+ To use service account credentials you should specify `service_account_json` as follows:
110
+
111
+ ```python3
112
+ engine = sa.create_engine(
113
+ "yql+ydb://localhost:2136/local",
114
+ connect_args = {
115
+ "credentials": {
116
+ "service_account_json": {
117
+ "id": "...",
118
+ "service_account_id": "...",
119
+ "created_at": "...",
120
+ "key_algorithm": "...",
121
+ "public_key": "...",
122
+ "private_key": "..."
123
+ }
124
+ }
125
+ }
126
+ )
127
+ ```
128
+
129
+ ### Credentials from YDB SDK
130
+
131
+ To use any credentials that comes with `ydb` package, just pass credentials object as follows:
132
+
133
+ ```python3
134
+ import ydb.iam
135
+
136
+ engine = sa.create_engine(
137
+ "yql+ydb://localhost:2136/local",
138
+ connect_args = {
139
+ "credentials": ydb.iam.MetadataUrlCredentials()
140
+ }
141
+ )
142
+
143
+ ```
144
+
145
+
146
+ ## Migrations
147
+
148
+ To setup `alembic` to work with `YDB` please check [this example](https://github.com/ydb-platform/ydb-sqlalchemy/tree/main/examples/alembic).
149
+
150
+ ## Development
151
+
152
+ ### Run Tests:
153
+
154
+ Run the command from the root directory of the repository to start YDB in a local docker container.
155
+ ```bash
156
+ $ docker-compose up
157
+ ```
158
+
159
+ To run all tests execute the command from the root directory of the repository:
160
+ ```bash
161
+ $ tox -e test-all
162
+ ```
163
+
164
+ Run specific test:
165
+ ```bash
166
+ $ tox -e test -- test/test_core.py
167
+ ```
168
+
169
+ Check code style:
170
+ ```bash
171
+ $ tox -e style
172
+ ```
173
+
174
+ Reformat code:
175
+ ```bash
176
+ $ tox -e isort
177
+ $ tox -e black-format
178
+ ```
179
+
180
+ Run example (needs running local YDB):
181
+ ```bash
182
+ $ python -m pip install virtualenv
183
+ $ virtualenv venv
184
+ $ source venv/bin/activate
185
+ $ pip install -r requirements.txt
186
+ $ python examples/example.py
187
+ ```
188
+
189
+ ## Additional Notes
190
+
191
+ ### Pandas
192
+ It is possible to use YDB SA engine with `pandas` fuctions [to_sql()](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html) and [read_sql](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_sql.html). However, there are some limitations:
193
+
194
+ * `to_sql` method can not be used with column tables, since it is impossible to specify `NOT NULL` columns with current `to_sql` arguments. YDB requires column tables to have `NOT NULL` attribute on `PK` columns.
195
+
196
+ * `to_sql` is not fully optimized to load huge datasets. It is recommended to use `method="multi"` and avoid setting a very large `chunksize`.
197
+
198
+ * `read_sql` is not fully optimized to load huge datasets and could lead to significant memory consumptions.
@@ -0,0 +1,178 @@
1
+ # YDB Dialect for SQLAlchemy
2
+ ---
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/ydb-platform/ydb-sqlalchemy/blob/main/LICENSE)
4
+ [![PyPI version](https://badge.fury.io/py/ydb-sqlalchemy.svg)](https://badge.fury.io/py/ydb-sqlalchemy)
5
+ [![API Reference](https://img.shields.io/badge/API-Reference-lightgreen.svg)](https://ydb-platform.github.io/ydb-sqlalchemy/api/index.html)
6
+ [![Functional tests](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/tests.yml/badge.svg)](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/tests.yml)
7
+ [![Style checks](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/style.yml/badge.svg)](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/style.yml)
8
+
9
+ This repository contains YQL dialect for SqlAlchemy 2.0.
10
+
11
+ ---
12
+
13
+ **Documentation**: <a href="https://ydb-platform.github.io/ydb-sqlalchemy" target="_blank">https://ydb-platform.github.io/ydb-sqlalchemy</a>
14
+
15
+ ---
16
+
17
+ **Note**: Dialect also works with SqlAlchemy 1.4, but it is not fully tested.
18
+
19
+
20
+ ## Installation
21
+
22
+ ### Via PyPI
23
+ To install ydb-sqlalchemy from PyPI:
24
+
25
+ ```bash
26
+ $ pip install ydb-sqlalchemy
27
+ ```
28
+
29
+ ### Installation from source code
30
+ To work with current ydb-sqlalchemy version clone this repo and run from source root:
31
+
32
+ ```bash
33
+ $ pip install -U .
34
+ ```
35
+
36
+ ## Getting started
37
+
38
+ Connect to local YDB using SqlAlchemy:
39
+
40
+ ```python3
41
+ import sqlalchemy as sa
42
+
43
+
44
+ engine = sa.create_engine("yql+ydb://localhost:2136/local")
45
+
46
+ with engine.connect() as conn:
47
+ rs = conn.execute(sa.text("SELECT 1 AS value"))
48
+ print(rs.fetchone())
49
+
50
+ ```
51
+
52
+ ## Authentication
53
+
54
+ To specify credentials, you should pass `credentials` object to `connect_args` argument of `create_engine` method.
55
+
56
+ ### Static Credentials
57
+
58
+ To use static credentials you should specify `username` and `password` as follows:
59
+
60
+ ```python3
61
+ engine = sa.create_engine(
62
+ "yql+ydb://localhost:2136/local",
63
+ connect_args = {
64
+ "credentials": {
65
+ "username": "...",
66
+ "password": "..."
67
+ }
68
+ }
69
+ )
70
+ ```
71
+
72
+ ### Token Credentials
73
+
74
+ To use access token credentials you should specify `token` as follows:
75
+
76
+ ```python3
77
+ engine = sa.create_engine(
78
+ "yql+ydb://localhost:2136/local",
79
+ connect_args = {
80
+ "credentials": {
81
+ "token": "..."
82
+ }
83
+ }
84
+ )
85
+ ```
86
+
87
+ ### Service Account Credentials
88
+
89
+ To use service account credentials you should specify `service_account_json` as follows:
90
+
91
+ ```python3
92
+ engine = sa.create_engine(
93
+ "yql+ydb://localhost:2136/local",
94
+ connect_args = {
95
+ "credentials": {
96
+ "service_account_json": {
97
+ "id": "...",
98
+ "service_account_id": "...",
99
+ "created_at": "...",
100
+ "key_algorithm": "...",
101
+ "public_key": "...",
102
+ "private_key": "..."
103
+ }
104
+ }
105
+ }
106
+ )
107
+ ```
108
+
109
+ ### Credentials from YDB SDK
110
+
111
+ To use any credentials that comes with `ydb` package, just pass credentials object as follows:
112
+
113
+ ```python3
114
+ import ydb.iam
115
+
116
+ engine = sa.create_engine(
117
+ "yql+ydb://localhost:2136/local",
118
+ connect_args = {
119
+ "credentials": ydb.iam.MetadataUrlCredentials()
120
+ }
121
+ )
122
+
123
+ ```
124
+
125
+
126
+ ## Migrations
127
+
128
+ To setup `alembic` to work with `YDB` please check [this example](https://github.com/ydb-platform/ydb-sqlalchemy/tree/main/examples/alembic).
129
+
130
+ ## Development
131
+
132
+ ### Run Tests:
133
+
134
+ Run the command from the root directory of the repository to start YDB in a local docker container.
135
+ ```bash
136
+ $ docker-compose up
137
+ ```
138
+
139
+ To run all tests execute the command from the root directory of the repository:
140
+ ```bash
141
+ $ tox -e test-all
142
+ ```
143
+
144
+ Run specific test:
145
+ ```bash
146
+ $ tox -e test -- test/test_core.py
147
+ ```
148
+
149
+ Check code style:
150
+ ```bash
151
+ $ tox -e style
152
+ ```
153
+
154
+ Reformat code:
155
+ ```bash
156
+ $ tox -e isort
157
+ $ tox -e black-format
158
+ ```
159
+
160
+ Run example (needs running local YDB):
161
+ ```bash
162
+ $ python -m pip install virtualenv
163
+ $ virtualenv venv
164
+ $ source venv/bin/activate
165
+ $ pip install -r requirements.txt
166
+ $ python examples/example.py
167
+ ```
168
+
169
+ ## Additional Notes
170
+
171
+ ### Pandas
172
+ It is possible to use YDB SA engine with `pandas` fuctions [to_sql()](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html) and [read_sql](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_sql.html). However, there are some limitations:
173
+
174
+ * `to_sql` method can not be used with column tables, since it is impossible to specify `NOT NULL` columns with current `to_sql` arguments. YDB requires column tables to have `NOT NULL` attribute on `PK` columns.
175
+
176
+ * `to_sql` is not fully optimized to load huge datasets. It is recommended to use `method="multi"` and avoid setting a very large `chunksize`.
177
+
178
+ * `read_sql` is not fully optimized to load huge datasets and could lead to significant memory consumptions.
@@ -1,3 +1,3 @@
1
1
  sqlalchemy >= 1.4.0, < 3.0.0
2
- ydb >= 3.18.8
2
+ ydb >= 3.21.6
3
3
  ydb-dbapi >= 0.1.10
@@ -13,7 +13,7 @@ with open("requirements.txt") as f:
13
13
 
14
14
  setuptools.setup(
15
15
  name="ydb-sqlalchemy",
16
- version="0.1.9", # AUTOVERSION
16
+ version="0.1.11", # AUTOVERSION
17
17
  description="YDB Dialect for SQLAlchemy",
18
18
  author="Yandex LLC",
19
19
  author_email="ydb@yandex-team.ru",