Skip to main content

SQLAlchemy Adapter for PyCasbin

Project description

SQLAlchemy Adapter for PyCasbin

GitHub Actions Coverage Status Version PyPI - Wheel Pyversions Download License

SQLAlchemy Adapter is the SQLAlchemy adapter for PyCasbin. With this library, Casbin can load policy from SQLAlchemy supported database or save policy to it.

Based on Officially Supported Databases, The current supported databases are:

  • PostgreSQL
  • MySQL
  • SQLite
  • Oracle
  • Microsoft SQL Server
  • Firebird
  • Sybase

Installation

pip install sqlalchemy_adapter

Simple Example

You can save and load policy to database.

import sqlalchemy_adapter
import casbin

adapter = sqlalchemy_adapter.Adapter('sqlite:///test.db')

e = casbin.Enforcer('path/to/model.conf', adapter)

sub = "alice"  # the user that wants to access a resource.
obj = "data1"  # the resource that is going to be accessed.
act = "read"  # the operation that the user performs on the resource.

if e.enforce(sub, obj, act):
    # permit alice to read data1
    pass
else:
    # deny the request, show an error
    pass

By default, policies are stored in the casbin_rule table. You can custom the table where the policy is stored by using the table_name parameter.

import sqlalchemy_adapter
import casbin

custom_table_name = "<custom_table_name>"

# create adapter with custom table name.
adapter = sqlalchemy_adapter.Adapter('sqlite:///test.db', table_name=custom_table_name)

e = casbin.Enforcer('path/to/model.conf', adapter)

Getting Help

License

This project is licensed under the Apache 2.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlalchemy_adapter-1.5.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_adapter-1.5.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_adapter-1.5.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_adapter-1.5.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for sqlalchemy_adapter-1.5.0.tar.gz
Algorithm Hash digest
SHA256 9fce324dc959c826d25b91606435a0256b24d84dfe3906ac9c88804ec4aae388
MD5 e615854d2f54eefff86a8e76ab55af8d
BLAKE2b-256 1e6b14ad56c80070e40773eaab3e21fd358654f5bb1f1f0fef3f026abe9dfe7f

See more details on using hashes here.

File details

Details for the file sqlalchemy_adapter-1.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_adapter-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23c733f4556d590c5a56ce9178463cd4ad9d64fbeb0b6e6972029026e5fd87b6
MD5 d2bf853815d0353be7e08dc05e3474a6
BLAKE2b-256 ffca63f12d36bff6510edbb9ad5854a8192c4bdef529f59f8e4559c4dfd87a4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page