Skip to main content

SQLAlchemy Adapter for PyCasbin

Project description

SQLAlchemy Adapter for PyCasbin

build 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.6.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.6.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_adapter-1.6.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.6.0.tar.gz
Algorithm Hash digest
SHA256 e42d8357386c524b3145084260561dee412404790496c866db040532f60c4a9c
MD5 d99f5f598d819ba8557fef1808206962
BLAKE2b-256 1271f87eac0c481a39fc6606c51ba44ca63e624c284fb458cba19387d0f97c9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlalchemy_adapter-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f8745736548d749208734cacc2a0624bcb33cadbe496073e95244a7be5b260a
MD5 75fa39cadd0eb337ebcc9e20c69601d6
BLAKE2b-256 3a20e4a0dc6e6f2eb21ee81a1f8bf363fa3cbdbcaf6eb0f88a35b6b271368b0e

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