First-class SQLAlchemy support for Oso Cloud
Project description
SQLAlchemy 🤝 Oso Cloud
The Oso Cloud extension for SQLAlchemy enables you to filter database queries based on your application's authorization logic.
- With Local Authorization, you don’t need all your data in one place. Let your other services own things like user roles and entitlements. We’ll stitch anything relevant into queries over your SQLAlchemy data, with no need to sync.
- Pair with other extensions like
pgvectorto build powerful, secure RAG search over private data. - First-class SQLAlchemy support for unparalleled ergonomics.
Install
pip install sqlalchemy-oso-cloud
Use
Step 1: Map SQLAlchemy Data
With the utilities in [sqlalchemy_oso_cloud.orm], bind data in your SQLAlchemy models to the Oso facts you'll use in your authorization policy.
import sqlalchemy_oso_cloud as oso
class Document(Base, oso.Resource):
...
# TODO(iris): decide on this API
organization: relation(remote="Organization")
# maps facts like `has_state(Document{"123"}, "published")`
state: Mapped[str] = oso.attribute()
class DocumentChunk(Base, oso.Resource):
...
# maps facts like `has_relation(DocumentChunk{"456"}, "document", Document{"123"})`
document: Mapped["Document"] = oso.relation()
Step 2: Write a Polar policy
Unlike SQLAlchemy models which are specific to one database, Polar is agnostic of where each piece of data comes from.
actor User {}
resource Organization {
roles = ["admin", "member"];
}
resource Document {
roles = ["author"];
permissions = ["read", "write"];
relations = {
organization: Organization
};
"read" if "author";
"read" if "admin" on "organization";
"read" if
"member" on "organization" and
has_state(resource, "published");
"write" if "author";
}
resource DocumentChunk {
permissions = ["read"];
relations = {
document: Document
};
"read" if "read" on "document";
}
Step 3: Profit
from .models import Base, DocumentChunk
import sqlalchemy_oso_cloud
sqlalchemy_oso_cloud.init(Base.registry)
def authorized_rag_retrieval(user, embedding):
return select(DocumentChunk)
.order_by(DocumentChunk.embedding.l2_distance(embedding))
.authorized(user, "read")
.limit(10)
Reference
Slack
Join our Slack community where Oso users and developers hang out! It's a great place to ask questions, share feedback, and get advice.
Contributing
See CONTRIBUTING.md
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy_oso_cloud-0.1.0b1.tar.gz.
File metadata
- Download URL: sqlalchemy_oso_cloud-0.1.0b1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83667a77c499674cd8dc3e664d5d8b8e3334896b3e74fd806ed6b24c0021cfc6
|
|
| MD5 |
fdd2294f8dad36f800aa9ec130ddae61
|
|
| BLAKE2b-256 |
85f21d818b2de4b91f9c302c4fc629290b35b1355f1c10de196b3a2d3eeab26d
|
Provenance
The following attestation bundles were made for sqlalchemy_oso_cloud-0.1.0b1.tar.gz:
Publisher:
publish.yml on osohq/sqlalchemy-oso-cloud
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_oso_cloud-0.1.0b1.tar.gz -
Subject digest:
83667a77c499674cd8dc3e664d5d8b8e3334896b3e74fd806ed6b24c0021cfc6 - Sigstore transparency entry: 261818745
- Sigstore integration time:
-
Permalink:
osohq/sqlalchemy-oso-cloud@4649c9eec20913bf67824345f3d20159a614297c -
Branch / Tag:
refs/heads/vijay/eng-1960-github-action-for-publishing-to-pypi - Owner: https://github.com/osohq
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4649c9eec20913bf67824345f3d20159a614297c -
Trigger Event:
push
-
Statement type:
File details
Details for the file sqlalchemy_oso_cloud-0.1.0b1-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_oso_cloud-0.1.0b1-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8978552f531f59d5aa821e27237d573b9685739e4509d5652ee621911288ccdb
|
|
| MD5 |
87ad1a4eefc4a5984a5258e08197cd50
|
|
| BLAKE2b-256 |
20c5287d4438a8426f09a484555a780239a1996f988a63a24d445f93955cd29b
|
Provenance
The following attestation bundles were made for sqlalchemy_oso_cloud-0.1.0b1-py3-none-any.whl:
Publisher:
publish.yml on osohq/sqlalchemy-oso-cloud
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_oso_cloud-0.1.0b1-py3-none-any.whl -
Subject digest:
8978552f531f59d5aa821e27237d573b9685739e4509d5652ee621911288ccdb - Sigstore transparency entry: 261818755
- Sigstore integration time:
-
Permalink:
osohq/sqlalchemy-oso-cloud@4649c9eec20913bf67824345f3d20159a614297c -
Branch / Tag:
refs/heads/vijay/eng-1960-github-action-for-publishing-to-pypi - Owner: https://github.com/osohq
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4649c9eec20913bf67824345f3d20159a614297c -
Trigger Event:
push
-
Statement type: