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.4.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.4.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy_adapter-1.4.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.4.0.tar.gz
Algorithm Hash digest
SHA256 d11e676c3c98cf34eac9cb25f23c5138a2d505c1ea62f0501d7a8657c63afd5a
MD5 e4e6a2d451629bfdff1b27c04a8ecd4d
BLAKE2b-256 e90619d04da6125c14f4eebc4cf3f5fa69ddf072c5875c6f9a40c9403f821ceb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlalchemy_adapter-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8dda2f628511b6f55fadeb54dfd4c8711511d1fe5b3a339c942674e605c8f97e
MD5 26d0b64ca1c7902b246158a6edcb60a2
BLAKE2b-256 e5cffdafe244bd5090f46a60d3647a2a8a043ae2c19e15bd8bc3248640569299

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