Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add note about using OAuth token #475

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/databricks/sqlalchemy/README.sqlalchemy.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ engine = create_engine(
)
```

### Using OAuth instead of PAT

It is possible to use an OAuth token instead of a PAT token. The token can be obtained from an `oauth_service_principal` like so (M2M using a Service Principal):

```python
from databricks.sdk.core import Config, oauth_service_principal
from sqlalchemy import create_engine

def credential_provider():
config = Config(
host = f"https://{os.environ.get("DATABRICKS_HOSTNAME")}",
client_id = os.environ.get("DATABRICKS_CLIENT_ID"),
client_secret = os.environ.get("DATABRICKS_CLIENT_SECRET")
)
return oauth_service_principal(config)

access_token = credential_provider().oauth_token().access_token
...
```


## Types

The [SQLAlchemy type hierarchy](https://docs.sqlalchemy.org/en/20/core/type_basics.html) contains backend-agnostic type implementations (represented in CamelCase) and backend-specific types (represented in UPPERCASE). The majority of SQLAlchemy's [CamelCase](https://docs.sqlalchemy.org/en/20/core/type_basics.html#the-camelcase-datatypes) types are supported. This means that a SQLAlchemy application using these types should "just work" with Databricks.
Expand Down