casbin-async-django-orm-adapter 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. casbin_async_django_orm_adapter-1.0.0/LICENSE +201 -0
  2. casbin_async_django_orm_adapter-1.0.0/PKG-INFO +116 -0
  3. casbin_async_django_orm_adapter-1.0.0/README.md +95 -0
  4. casbin_async_django_orm_adapter-1.0.0/async_casbin_adapter/__init__.py +0 -0
  5. casbin_async_django_orm_adapter-1.0.0/async_casbin_adapter/adapter.py +100 -0
  6. casbin_async_django_orm_adapter-1.0.0/async_casbin_adapter/apps.py +24 -0
  7. casbin_async_django_orm_adapter-1.0.0/async_casbin_adapter/enforcer.py +81 -0
  8. casbin_async_django_orm_adapter-1.0.0/async_casbin_adapter/migrations/0001_initial.py +37 -0
  9. casbin_async_django_orm_adapter-1.0.0/async_casbin_adapter/migrations/__init__.py +0 -0
  10. casbin_async_django_orm_adapter-1.0.0/async_casbin_adapter/models.py +48 -0
  11. casbin_async_django_orm_adapter-1.0.0/async_casbin_adapter/utils.py +25 -0
  12. casbin_async_django_orm_adapter-1.0.0/casbin_async_django_orm_adapter.egg-info/PKG-INFO +116 -0
  13. casbin_async_django_orm_adapter-1.0.0/casbin_async_django_orm_adapter.egg-info/SOURCES.txt +80 -0
  14. casbin_async_django_orm_adapter-1.0.0/casbin_async_django_orm_adapter.egg-info/dependency_links.txt +1 -0
  15. casbin_async_django_orm_adapter-1.0.0/casbin_async_django_orm_adapter.egg-info/requires.txt +2 -0
  16. casbin_async_django_orm_adapter-1.0.0/casbin_async_django_orm_adapter.egg-info/top_level.txt +3 -0
  17. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  18. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
  19. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  20. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1272 -0
  21. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  22. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  23. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +152 -0
  24. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +270 -0
  25. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  26. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +704 -0
  27. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common.py +709 -0
  28. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +173 -0
  29. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +169 -0
  30. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
  31. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  32. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  33. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +805 -0
  34. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1172 -0
  35. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1319 -0
  36. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +128 -0
  37. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +104 -0
  38. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +462 -0
  39. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  40. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +56 -0
  41. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2745 -0
  42. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3976 -0
  43. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  44. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2965 -0
  45. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
  46. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1391 -0
  47. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +26 -0
  48. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py +3112 -0
  49. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +99 -0
  50. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +767 -0
  51. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1260 -0
  52. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  53. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  54. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +373 -0
  55. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  56. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +54 -0
  57. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +303 -0
  58. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3196 -0
  59. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  60. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
  61. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +108 -0
  62. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
  63. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
  64. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
  65. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
  66. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
  67. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/markers.py +252 -0
  68. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +825 -0
  69. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  70. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
  71. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
  72. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/tags.py +553 -0
  73. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
  74. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
  75. casbin_async_django_orm_adapter-1.0.0/node_modules/npm/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  76. casbin_async_django_orm_adapter-1.0.0/node_modules/semantic-release-pypi/dist/py/set_version.py +32 -0
  77. casbin_async_django_orm_adapter-1.0.0/node_modules/semantic-release-pypi/dist/py/verify_setup.py +24 -0
  78. casbin_async_django_orm_adapter-1.0.0/pyproject.toml +47 -0
  79. casbin_async_django_orm_adapter-1.0.0/requirements.txt +2 -0
  80. casbin_async_django_orm_adapter-1.0.0/setup.cfg +4 -0
  81. casbin_async_django_orm_adapter-1.0.0/tests/test_adapter.py +135 -0
  82. casbin_async_django_orm_adapter-1.0.0/tests/test_enforcer.py +49 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.4
2
+ Name: casbin-async-django-orm-adapter
3
+ Version: 1.0.0
4
+ Summary: Async Django ORM adapter for PyCasbin
5
+ Author-email: Yang Luo <hsluoyz@qq.com>
6
+ License: Apache 2.0
7
+ Project-URL: Home-page, https://github.com/officialpycasbin/async-django-orm-adapter
8
+ Keywords: async,pycasbin,casbin,adapter,storage-driver,django,orm,django-orm,access-control,authorization
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Requires-Python: >=3.7
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: pycasbin>=2.0.0
19
+ Requires-Dist: Django
20
+ Dynamic: license-file
21
+
22
+ # async-django-orm-adapter
23
+
24
+ [![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)
25
+
26
+ Asynchronous Django ORM Adapter is the async [Django](https://www.djangoproject.com/) [ORM](https://docs.djangoproject.com/en/3.0/ref/databases/) adapter for [PyCasbin](https://github.com/casbin/pycasbin). With this library, Casbin can load policy from Django ORM supported database or save policy to it.
27
+
28
+ Based on [Officially Supported Databases](https://docs.djangoproject.com/en/3.0/ref/databases/), The current supported databases are:
29
+
30
+ - PostgreSQL
31
+ - MariaDB
32
+ - MySQL
33
+ - Oracle
34
+ - SQLite
35
+ - IBM DB2
36
+ - Microsoft SQL Server
37
+ - Firebird
38
+ - ODBC
39
+
40
+ ## Installation
41
+
42
+ ```
43
+ pip install casbin-async-django-orm-adapter
44
+ ```
45
+
46
+ Add `async_casbin_adapter.apps.AsyncCasbinAdapterConfig` to your `INSTALLED_APPS`
47
+
48
+ ```python
49
+ # settings.py
50
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
51
+
52
+ INSTALLED_APPS = [
53
+ ...
54
+ 'async_casbin_adapter.apps.AsyncCasbinAdapterConfig',
55
+ ...
56
+ ]
57
+
58
+ CASBIN_MODEL = os.path.join(BASE_DIR, 'casbin.conf')
59
+ ```
60
+
61
+ To run schema migration, execute `python manage.py migrate async_casbin_adapter`
62
+
63
+ ## Simple Example
64
+
65
+ ```python
66
+ # views.py
67
+ from async_casbin_adapter.enforcer import get_enforcer
68
+
69
+ async def hello(request):
70
+ sub = "alice" # the user that wants to access a resource.
71
+ obj = "data1" # the resource that is going to be accessed.
72
+ act = "read" # the operation that the user performs on the resource.
73
+
74
+ enforcer = await get_enforcer()
75
+ if e.enforce(sub, obj, act):
76
+ # permit alice to read data1casbin_django_orm_adapter
77
+ pass
78
+ else:
79
+ # deny the request, show an error
80
+ pass
81
+ ```
82
+
83
+ ## Configuration
84
+
85
+ ### `CASBIN_MODEL`
86
+ A string containing the file location of your casbin model.
87
+
88
+ ### `CASBIN_ADAPTER`
89
+ A string containing the adapter import path. Default to the django adapter shipped with this package: `async_casbin_adapter.adapter.AsyncAdapter`
90
+
91
+ ### `CASBIN_ADAPTER_ARGS`
92
+ A tuple of arguments to be passed into the constructor of the adapter specified
93
+ in `CASBIN_ADAPTER`. Refer to adapters to see available arguments.
94
+
95
+ E.g. if you wish to use the file adapter
96
+ set the adapter to `casbin.persist.adapters.FileAdapter` and use
97
+ `CASBIN_ADAPTER_ARGS = ('path/to/policy_file.csv',)`
98
+
99
+ ### `CASBIN_DB_ALIAS`
100
+ The database the adapter uses. Default to "default".
101
+
102
+ ### `CASBIN_WATCHER`
103
+ Watcher instance to be set as the watcher on the enforcer instance.
104
+
105
+ ### `CASBIN_ROLE_MANAGER`
106
+ Role manager instance to be set as the role manager on the enforcer instance.
107
+
108
+
109
+ ### Getting Help
110
+
111
+ - [PyCasbin](https://github.com/casbin/pycasbin)
112
+
113
+ ### License
114
+
115
+ This project is licensed under the [Apache 2.0 license](LICENSE).
116
+
@@ -0,0 +1,95 @@
1
+ # async-django-orm-adapter
2
+
3
+ [![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)
4
+
5
+ Asynchronous Django ORM Adapter is the async [Django](https://www.djangoproject.com/) [ORM](https://docs.djangoproject.com/en/3.0/ref/databases/) adapter for [PyCasbin](https://github.com/casbin/pycasbin). With this library, Casbin can load policy from Django ORM supported database or save policy to it.
6
+
7
+ Based on [Officially Supported Databases](https://docs.djangoproject.com/en/3.0/ref/databases/), The current supported databases are:
8
+
9
+ - PostgreSQL
10
+ - MariaDB
11
+ - MySQL
12
+ - Oracle
13
+ - SQLite
14
+ - IBM DB2
15
+ - Microsoft SQL Server
16
+ - Firebird
17
+ - ODBC
18
+
19
+ ## Installation
20
+
21
+ ```
22
+ pip install casbin-async-django-orm-adapter
23
+ ```
24
+
25
+ Add `async_casbin_adapter.apps.AsyncCasbinAdapterConfig` to your `INSTALLED_APPS`
26
+
27
+ ```python
28
+ # settings.py
29
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
30
+
31
+ INSTALLED_APPS = [
32
+ ...
33
+ 'async_casbin_adapter.apps.AsyncCasbinAdapterConfig',
34
+ ...
35
+ ]
36
+
37
+ CASBIN_MODEL = os.path.join(BASE_DIR, 'casbin.conf')
38
+ ```
39
+
40
+ To run schema migration, execute `python manage.py migrate async_casbin_adapter`
41
+
42
+ ## Simple Example
43
+
44
+ ```python
45
+ # views.py
46
+ from async_casbin_adapter.enforcer import get_enforcer
47
+
48
+ async def hello(request):
49
+ sub = "alice" # the user that wants to access a resource.
50
+ obj = "data1" # the resource that is going to be accessed.
51
+ act = "read" # the operation that the user performs on the resource.
52
+
53
+ enforcer = await get_enforcer()
54
+ if e.enforce(sub, obj, act):
55
+ # permit alice to read data1casbin_django_orm_adapter
56
+ pass
57
+ else:
58
+ # deny the request, show an error
59
+ pass
60
+ ```
61
+
62
+ ## Configuration
63
+
64
+ ### `CASBIN_MODEL`
65
+ A string containing the file location of your casbin model.
66
+
67
+ ### `CASBIN_ADAPTER`
68
+ A string containing the adapter import path. Default to the django adapter shipped with this package: `async_casbin_adapter.adapter.AsyncAdapter`
69
+
70
+ ### `CASBIN_ADAPTER_ARGS`
71
+ A tuple of arguments to be passed into the constructor of the adapter specified
72
+ in `CASBIN_ADAPTER`. Refer to adapters to see available arguments.
73
+
74
+ E.g. if you wish to use the file adapter
75
+ set the adapter to `casbin.persist.adapters.FileAdapter` and use
76
+ `CASBIN_ADAPTER_ARGS = ('path/to/policy_file.csv',)`
77
+
78
+ ### `CASBIN_DB_ALIAS`
79
+ The database the adapter uses. Default to "default".
80
+
81
+ ### `CASBIN_WATCHER`
82
+ Watcher instance to be set as the watcher on the enforcer instance.
83
+
84
+ ### `CASBIN_ROLE_MANAGER`
85
+ Role manager instance to be set as the role manager on the enforcer instance.
86
+
87
+
88
+ ### Getting Help
89
+
90
+ - [PyCasbin](https://github.com/casbin/pycasbin)
91
+
92
+ ### License
93
+
94
+ This project is licensed under the [Apache 2.0 license](LICENSE).
95
+
@@ -0,0 +1,100 @@
1
+ # Copyright 2025 The casbin Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import logging
16
+
17
+ from casbin import persist
18
+ from casbin.persist.adapters.asyncio import AsyncAdapter
19
+ from django.db.utils import OperationalError, ProgrammingError
20
+
21
+ from .models import CasbinRule
22
+
23
+ logger = logging.getLogger(__name__)
24
+
25
+
26
+ class AsyncAdapter(AsyncAdapter):
27
+ """the interface for Casbin async adapters."""
28
+
29
+ def __init__(self, db_alias="default"):
30
+ self.db_alias = db_alias
31
+
32
+ async def load_policy(self, model):
33
+ """loads all policy rules from the storage."""
34
+ try:
35
+ lines = CasbinRule.objects.using(self.db_alias).all()
36
+
37
+ async for line in lines:
38
+ persist.load_policy_line(str(line), model)
39
+ except (OperationalError, ProgrammingError) as error:
40
+ logger.warning("Could not load policy from database: {}".format(error))
41
+
42
+ def _create_policy_line(self, ptype, rule):
43
+ line = CasbinRule(ptype=ptype)
44
+ if len(rule) > 0:
45
+ line.v0 = rule[0]
46
+ if len(rule) > 1:
47
+ line.v1 = rule[1]
48
+ if len(rule) > 2:
49
+ line.v2 = rule[2]
50
+ if len(rule) > 3:
51
+ line.v3 = rule[3]
52
+ if len(rule) > 4:
53
+ line.v4 = rule[4]
54
+ if len(rule) > 5:
55
+ line.v5 = rule[5]
56
+ return line
57
+
58
+ async def save_policy(self, model):
59
+ """saves all policy rules to the storage."""
60
+ # this will delete all rules
61
+ await CasbinRule.objects.using(self.db_alias).all().adelete()
62
+
63
+ lines = []
64
+ for sec in ["p", "g"]:
65
+ if sec not in model.model.keys():
66
+ continue
67
+ for ptype, ast in model.model[sec].items():
68
+ for rule in ast.policy:
69
+ lines.append(self._create_policy_line(ptype, rule))
70
+
71
+ db_alias = self.db_alias if self.db_alias else "default"
72
+ rows_created = await CasbinRule.objects.using(db_alias).abulk_create(lines)
73
+ return len(rows_created) > 0
74
+
75
+ async def add_policy(self, sec, ptype, rule):
76
+ """adds a policy rule to the storage."""
77
+ line = self._create_policy_line(ptype, rule)
78
+ await line.asave()
79
+
80
+ async def remove_policy(self, sec, ptype, rule):
81
+ """removes a policy rule from the storage."""
82
+ query_params = {"ptype": ptype}
83
+ for i, v in enumerate(rule):
84
+ query_params["v{}".format(i)] = v
85
+
86
+ rows_deleted, _ = await CasbinRule.objects.using(self.db_alias).filter(**query_params).adelete()
87
+ return rows_deleted > 0
88
+
89
+ async def remove_filtered_policy(self, sec, ptype, field_index, *field_values):
90
+ """removes policy rules that match the filter from the storage."""
91
+ query_params = {"ptype": ptype}
92
+ if not (0 <= field_index <= 5):
93
+ return False
94
+ if not (1 <= field_index + len(field_values) <= 6):
95
+ return False
96
+ for i, v in enumerate(field_values):
97
+ query_params["v{}".format(i + field_index)] = v
98
+
99
+ rows_deleted, _ = await CasbinRule.objects.using(self.db_alias).filter(**query_params).adelete()
100
+ return rows_deleted > 0
@@ -0,0 +1,24 @@
1
+ # Copyright 2025 The casbin Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from django.apps import AppConfig
16
+ import logging
17
+
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+
22
+ class AsyncCasbinAdapterConfig(AppConfig):
23
+ default_auto_field = "django.db.models.BigAutoField"
24
+ name = "async_casbin_adapter"
@@ -0,0 +1,81 @@
1
+ # Copyright 2025 The casbin Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import logging
16
+ from django.conf import settings
17
+ from django.db import connections
18
+ from asgiref.sync import sync_to_async
19
+
20
+ from casbin import AsyncEnforcer
21
+
22
+ from .utils import import_class
23
+
24
+
25
+ logger = logging.getLogger(__name__)
26
+
27
+
28
+ def _perform_sync_db_check(db_alias):
29
+ logger.info(f"Performing synchronous DB check for migration on alias '{db_alias}'...")
30
+ connection = connections[db_alias]
31
+ try:
32
+ with connection.cursor() as cursor:
33
+ cursor.execute(
34
+ """
35
+ SELECT app, name FROM django_migrations
36
+ WHERE app = 'async_casbin_adapter' AND name = '0001_initial';
37
+ """
38
+ )
39
+ row = cursor.fetchone()
40
+
41
+ if not row:
42
+ raise RuntimeError("Async Casbin Adapter initial migration not applied. ")
43
+ logger.info("Synchronous DB check passed.")
44
+ return True
45
+ except Exception as e:
46
+ logger.error(f"Synchronous DB check failed: {e}")
47
+ raise
48
+
49
+
50
+ async def get_enforcer(db_alias=None):
51
+ """
52
+ An asynchronous factory function for creating and initializing Casbin AsyncEnforcer
53
+ """
54
+ if db_alias is None:
55
+ db_alias = getattr(settings, "CASBIN_DB_ALIAS", "default")
56
+
57
+ async_db_check = sync_to_async(_perform_sync_db_check, thread_sensitive=True)
58
+ await async_db_check(db_alias)
59
+
60
+ model = getattr(settings, "CASBIN_MODEL")
61
+ adapter_loc = getattr(settings, "ASYNC_CASBIN_ADAPTER", "async_casbin_adapter.adapter.AsyncAdapter")
62
+ adapter_args = getattr(settings, "CASBIN_ADAPTER_ARGS", tuple())
63
+ Adapter = import_class(adapter_loc)
64
+ adapter = Adapter(db_alias, *adapter_args)
65
+
66
+ enforcer = AsyncEnforcer(model, adapter)
67
+
68
+ watcher_loc = getattr(settings, "CASBIN_WATCHER", None)
69
+ if watcher_loc:
70
+ Watcher = import_class(watcher_loc)
71
+ enforcer.set_watcher(Watcher())
72
+
73
+ role_manager_loc = getattr(settings, "CASBIN_ROLE_MANAGER", None)
74
+ if role_manager_loc:
75
+ RoleManager = import_class(role_manager_loc)
76
+ enforcer.set_role_manager(RoleManager())
77
+
78
+ await enforcer.load_policy()
79
+
80
+ logger.info("Casbin AsyncEnforcer initialized successfully.")
81
+ return enforcer
@@ -0,0 +1,37 @@
1
+ # Generated by Django 5.2.5 on 2025-09-05 09:40
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ initial = True
9
+
10
+ dependencies = []
11
+
12
+ operations = [
13
+ migrations.CreateModel(
14
+ name="CasbinRule",
15
+ fields=[
16
+ (
17
+ "id",
18
+ models.BigAutoField(
19
+ auto_created=True,
20
+ primary_key=True,
21
+ serialize=False,
22
+ verbose_name="ID",
23
+ ),
24
+ ),
25
+ ("ptype", models.CharField(max_length=255)),
26
+ ("v0", models.CharField(max_length=255)),
27
+ ("v1", models.CharField(max_length=255)),
28
+ ("v2", models.CharField(max_length=255)),
29
+ ("v3", models.CharField(max_length=255)),
30
+ ("v4", models.CharField(max_length=255)),
31
+ ("v5", models.CharField(max_length=255)),
32
+ ],
33
+ options={
34
+ "db_table": "casbin_rule",
35
+ },
36
+ ),
37
+ ]