Skip to content

Commit 9706933

Browse files
authored
Merge pull request #89 from ydb-platform/update_readme
Update README to describe auth
2 parents 8729c2e + ec32151 commit 9706933

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,82 @@ with engine.connect() as conn:
4242

4343
```
4444

45+
## Authentication
46+
47+
To specify credentials, you should pass `credentials` object to `connect_args` argument of `create_engine` method.
48+
49+
### Static Credentials
50+
51+
To use static credentials you should specify `username` and `password` as follows:
52+
53+
```python3
54+
engine = sa.create_engine(
55+
"yql+ydb://localhost:2136/local",
56+
connect_args = {
57+
"credentials": {
58+
"username": "...",
59+
"password": "..."
60+
}
61+
}
62+
)
63+
```
64+
65+
### Token Credentials
66+
67+
To use access token credentials you should specify `token` as follows:
68+
69+
```python3
70+
engine = sa.create_engine(
71+
"yql+ydb://localhost:2136/local",
72+
connect_args = {
73+
"credentials": {
74+
"token": "..."
75+
}
76+
}
77+
)
78+
```
79+
80+
### Service Account Credentials
81+
82+
To use service account credentials you should specify `service_account_json` as follows:
83+
84+
```python3
85+
engine = sa.create_engine(
86+
"yql+ydb://localhost:2136/local",
87+
connect_args = {
88+
"credentials": {
89+
"service_account_json": {
90+
"id": "...",
91+
"service_account_id": "...",
92+
"created_at": "...",
93+
"key_algorithm": "...",
94+
"public_key": "...",
95+
"private_key": "..."
96+
}
97+
}
98+
}
99+
)
100+
```
101+
102+
### Credentials from YDB SDK
103+
104+
To use any credentials that comes with `ydb` package, just pass credentials object as follows:
105+
106+
```python3
107+
import ydb.iam
108+
109+
engine = sa.create_engine(
110+
"yql+ydb://localhost:2136/local",
111+
connect_args = {
112+
"credentials": ydb.iam.MetadataUrlCredentials()
113+
}
114+
)
115+
116+
```
117+
118+
119+
## Migrations
120+
45121
To setup `alembic` to work with `YDB` please check [this example](https://github.com/ydb-platform/ydb-sqlalchemy/tree/main/examples/alembic).
46122

47123
## Development
@@ -82,3 +158,14 @@ $ source venv/bin/activate
82158
$ pip install -r requirements.txt
83159
$ python examples/example.py
84160
```
161+
162+
## Additional Notes
163+
164+
### Pandas
165+
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:
166+
167+
* `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.
168+
169+
* `to_sql` is not fully optimized to load huge datasets. It is recommended to use `method="multi"` and avoid setting a very large `chunksize`.
170+
171+
* `read_sql` is not fully optimized to load huge datasets and could lead to significant memory consumptions.

0 commit comments

Comments
 (0)