Skip to content

Commit 994ec5c

Browse files
authored
Merge branch 'main' into ex_basic-example_p2
2 parents 099e4ed + 11a7d87 commit 994ec5c

File tree

7 files changed

+74
-11
lines changed

7 files changed

+74
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.9.0 ##
2+
3+
* fixed minor issue in SDK imports for Python 2.
4+
15
## 2.7.0 ##
26

37
* fixes in TxContext in ydb.aio module.

examples/basic_example_v1/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Running this sample with the managed YDB instance in Yandex Cloud
2+
---
3+
4+
(0) Install the required Python dependencies
5+
6+
python3 -m pip install iso8601
7+
python3 -m pip install 'ydb[yc]'
8+
9+
(1) Install the yc command line tool
10+
11+
https://cloud.yandex.ru/docs/cli/operations/install-cli
12+
13+
(2) Create the service account using the YC Web Console, and assign it the ydb.editor role.
14+
15+
Alternatively use the following shell snippet:
16+
17+
```bash
18+
# Specify the Yandex Cloud folder and service account name
19+
export YC_FOLDER=mzinal
20+
export SA_NAME=ydb-sa-0
21+
# Create the service account
22+
yc iam service-account create $SA_NAME
23+
# Obtain the service account id
24+
export SA_ID=`yc iam service-account get --name $SA_NAME | sed -n 's/^id: \(.*\)$/\1/p'`
25+
# Assign the ydb.editor role for the specified YC folder to the service account just created
26+
yc resource-manager folder add-access-binding $YC_FOLDER --role ydb.editor --subject serviceAccount:$SA_ID
27+
```
28+
29+
(3) Generate the service account key to be used for authentication.
30+
31+
Note: unfortunately, right now YC Web Console does not offer a way to generate the SA key
32+
with its Web interface.
33+
34+
```bash
35+
yc iam key create --service-account-name $SA_NAME --output $HOME/key-ydb-sa-0.json
36+
```
37+
38+
(4) Obtain the endpoint and database path from the Web Console.
39+
40+
Alternatively, use the following command to grab the required data in the shell:
41+
42+
```bash
43+
yc ydb db get --name ydb1
44+
```
45+
46+
`ydb1` value in the command above is the logical name of the YDB managed database.
47+
48+
(5) Run the sample:
49+
50+
```bash
51+
# Set the path to the service account key file
52+
export YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS=$HOME/key-ydb-sa-0.json
53+
# Set the database path and its endpoint
54+
export YDB_ENDPOINT=grpcs://ydb.serverless.yandexcloud.net:2135
55+
export YDB_DATABASE=/ru-central1/b1gfvslmokutuvt2g019/etnvbffeqegu1ub2rg2o
56+
# Run the script
57+
python3 __main__.py -e $YDB_ENDPOINT -d $YDB_DATABASE
58+
```

examples/basic_example_v1/basic_example.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
import os
3-
2+
import posixpath
43
import ydb
54
import basic_example_data
65

@@ -269,7 +268,7 @@ def callee(session):
269268

270269
def describe_table(pool, path, name):
271270
def callee(session):
272-
result = session.describe_table(os.path.join(path, name))
271+
result = session.describe_table(posixpath.join(path, name))
273272
print("\n> describe table: series")
274273
for column in result.columns:
275274
print("column, name:", column.name, ",", str(column.type.item).strip())
@@ -288,7 +287,7 @@ def bulk_upsert(table_client, path):
288287
.add_column("air_date", ydb.OptionalType(ydb.PrimitiveType.Uint64))
289288
)
290289
rows = basic_example_data.get_episodes_data_for_bulk_upsert()
291-
table_client.bulk_upsert(os.path.join(path, "episodes"), rows, column_types)
290+
table_client.bulk_upsert(posixpath.join(path, "episodes"), rows, column_types)
292291

293292

294293
def is_directory_exists(driver, path):
@@ -302,11 +301,11 @@ def ensure_path_exists(driver, database, path):
302301
paths_to_create = list()
303302
path = path.rstrip("/")
304303
while path not in ("", database):
305-
full_path = os.path.join(database, path)
304+
full_path = posixpath.join(database, path)
306305
if is_directory_exists(driver, full_path):
307306
break
308307
paths_to_create.append(full_path)
309-
path = os.path.dirname(path).rstrip("/")
308+
path = posixpath.dirname(path).rstrip("/")
310309

311310
while len(paths_to_create) > 0:
312311
full_path = paths_to_create.pop(-1)
@@ -323,7 +322,7 @@ def run(endpoint, database, path):
323322

324323
# absolute path - prefix to the table's names,
325324
# including the database location
326-
full_path = os.path.join(database, path)
325+
full_path = posixpath.join(database, path)
327326

328327
create_tables(pool, full_path)
329328

examples/service-account-credentials/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ def main():
2626
# specify YDB_DATABASE environment variable.
2727
database=os.getenv("YDB_DATABASE"),
2828
# construct the service account credentials instance
29+
# service account key should be in the local file,
30+
# and SA_KEY_FILE environment variable should point to it
2931
credentials=ydb.iam.ServiceAccountCredentials.from_file(
30-
"~/.ydb/sa.json",
32+
os.getenv("SA_KEY_FILE"),
3133
),
3234
)
3335

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setuptools.setup(
88
name="ydb",
9-
version="2.8.0",
9+
version="2.9.0",
1010
description="YDB Python SDK",
1111
author="Yandex LLC",
1212
author_email="[email protected]",

ydb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717

1818
try:
1919
import ydb.aio as aio # noqa
20-
except ImportError:
20+
except Exception:
2121
pass

ydb/ydb_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "2.8.0"
1+
VERSION = "2.9.0"

0 commit comments

Comments
 (0)