Authentication
There are several ways to authenticate through YDB Python SDK.
Anonymous Credentials
Full executable example here.
driver = ydb.Driver(
endpoint=os.getenv("YDB_ENDPOINT"),
database=os.getenv("YDB_DATABASE"),
credentials=ydb.AnonymousCredentials(),
)
Access Token Credentials
Full executable example here.
driver = ydb.Driver(
endpoint=os.getenv("YDB_ENDPOINT"),
database=os.getenv("YDB_DATABASE"),
credentials=ydb.AccessTokenCredentials(os.getenv("YDB_ACCESS_TOKEN_CREDENTIALS")),
)
Static Credentials
Full executable example here.
driver_config = ydb.DriverConfig(
endpoint=endpoint,
database=database,
credentials=ydb.StaticCredentials.from_user_password(user, password),
)
driver = ydb.Driver(driver_config=driver_config)
Service Account Credentials
Full executable example here.
driver = ydb.Driver(
endpoint=os.getenv("YDB_ENDPOINT"),
database=os.getenv("YDB_DATABASE"),
credentials=ydb.iam.ServiceAccountCredentials.from_file(
os.getenv("SA_KEY_FILE"),
),
)
OAuth 2.0 Token Exchange Credentials
Full executable example here.
driver = ydb.Driver(
endpoint=args.endpoint,
database=args.database,
root_certificates=ydb.load_ydb_root_certificate(),
credentials=ydb.oauth2_token_exchange.Oauth2TokenExchangeCredentials(
token_endpoint=args.token_endpoint,
audience=args.audience,
subject_token_source=ydb.oauth2_token_exchange.JwtTokenSource(
signing_method="RS256",
private_key_file=args.private_key_file,
key_id=args.key_id,
issuer=args.issuer,
subject=args.subject,
audience=args.audience,
),
),
)
Metadata Credentials
Full executable example here.
driver = ydb.Driver(
endpoint=os.getenv("YDB_ENDPOINT"),
database=os.getenv("YDB_DATABASE"),
credentials=ydb.iam.MetadataUrlCredentials(),
)