{"id":19700361,"url":"https://github.com/officialpycasbin/pymongo-adapter","last_synced_at":"2025-08-26T20:06:00.963Z","repository":{"id":262303174,"uuid":"886831428","full_name":"officialpycasbin/pymongo-adapter","owner":"officialpycasbin","description":"PyMongo Adapter for PyCasbin","archived":false,"fork":false,"pushed_at":"2025-08-15T13:28:11.000Z","size":50,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-15T20:53:07.492Z","etag":null,"topics":["abac","acl","adapter","auth","authorization","authz","casbin","db","mongo","mongodb","pycasbin","pymongo","python","rbac"],"latest_commit_sha":null,"homepage":"https://github.com/casbin/pycasbin","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/officialpycasbin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-11T17:24:24.000Z","updated_at":"2025-08-15T13:28:14.000Z","dependencies_parsed_at":"2024-11-11T18:31:14.087Z","dependency_job_id":"b782b864-23bd-4964-8dfa-55e3c7ada579","html_url":"https://github.com/officialpycasbin/pymongo-adapter","commit_stats":null,"previous_names":["officialpycasbin/pymongo-adapter"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/officialpycasbin/pymongo-adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/officialpycasbin%2Fpymongo-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/officialpycasbin%2Fpymongo-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/officialpycasbin%2Fpymongo-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/officialpycasbin%2Fpymongo-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/officialpycasbin","download_url":"https://codeload.github.com/officialpycasbin/pymongo-adapter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/officialpycasbin%2Fpymongo-adapter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272252225,"owners_count":24900606,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-26T02:00:07.904Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abac","acl","adapter","auth","authorization","authz","casbin","db","mongo","mongodb","pycasbin","pymongo","python","rbac"],"created_at":"2024-11-11T21:05:43.010Z","updated_at":"2025-08-26T20:06:00.955Z","avatar_url":"https://github.com/officialpycasbin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"PyMongo Adapter for PyCasbin\r\n====\r\n\r\n[![build Status](https://github.com/officialpycasbin/pymongo-adapter/actions/workflows/main.yml/badge.svg)](https://github.com/officialpycasbin/pymongo-adapter/actions/workflows/main.yml)\r\n[![Coverage Status](https://coveralls.io/repos/github/officialpycasbin/pymongo-adapter/badge.svg)](https://coveralls.io/github/officialpycasbin/pymongo-adapter)\r\n[![Version](https://img.shields.io/pypi/v/casbin_pymongo_adapter.svg)](https://pypi.org/project/casbin_pymongo_adapter/)\r\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin_pymongo_adapter.svg)](https://pypi.org/project/casbin_pymongo_adapter/)\r\n[![Pyversions](https://img.shields.io/pypi/pyversions/casbin_pymongo_adapter.svg)](https://pypi.org/project/casbin_pymongo_adapter/)\r\n[![Download](https://static.pepy.tech/badge/casbin_pymongo_adapter)](https://pypi.org/project/casbin_pymongo_adapter/)\r\n[![License](https://img.shields.io/pypi/l/casbin_pymongo_adapter.svg)](https://pypi.org/project/casbin_pymongo_adapter/)\r\n\r\nPyMongo Adapter is the [PyMongo](https://pypi.org/project/pymongo/) adapter for [PyCasbin](https://github.com/casbin/pycasbin). With this library, Casbin can load policy from MongoDB or save policy to it.\r\n\r\nThis adapter supports both synchronous and asynchronous PyMongo APIs.\r\n\r\n## Installation\r\n\r\n```\r\npip install casbin_pymongo_adapter\r\n```\r\n\r\n## Simple Example\r\n\r\n```python\r\nimport casbin_pymongo_adapter\r\nimport casbin\r\n\r\nadapter = casbin_pymongo_adapter.Adapter('mongodb://localhost:27017/', \"dbname\")\r\n\r\ne = casbin.Enforcer('path/to/model.conf', adapter, True)\r\n\r\nsub = \"alice\"  # the user that wants to access a resource.\r\nobj = \"data1\"  # the resource that is going to be accessed.\r\nact = \"read\"  # the operation that the user performs on the resource.\r\n\r\nif e.enforce(sub, obj, act):\r\n    # permit alice to read data1casbin_sqlalchemy_adapter\r\n    pass\r\nelse:\r\n    # deny the request, show an error\r\n    pass\r\n\r\n# define filter conditions\r\nfrom casbin_pymongo_adapter import Filter\r\n\r\nfilter = Filter()\r\nfilter.ptype = [\"p\"]\r\nfilter.v0 = [\"alice\"]\r\n\r\n# support MongoDB native query\r\nfilter.raw_query = {\r\n    \"ptype\": \"p\",\r\n    \"v0\": {\r\n        \"$in\": [\"alice\"]\r\n    }\r\n}\r\n\r\n# In this case, load only policies with sub value alice\r\ne.load_filtered_policy(filter)\r\n```\r\n\r\n## Async Example\r\n\r\n```python\r\nfrom casbin_pymongo_adapter.asynchronous import Adapter\r\nimport casbin\r\n\r\nadapter = Adapter('mongodb://localhost:27017/', \"dbname\")\r\ne = casbin.AsyncEnforcer('path/to/model.conf', adapter)\r\n\r\n# Note: AsyncEnforcer does not automatically load policies.\r\n# You need to call load_policy() manually.\r\nawait e.load_policy()\r\n```\r\n\r\n\r\n### Getting Help\r\n\r\n- [PyCasbin](https://github.com/casbin/pycasbin)\r\n\r\n### License\r\n\r\nThis project is licensed under the [Apache 2.0 license](LICENSE).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofficialpycasbin%2Fpymongo-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fofficialpycasbin%2Fpymongo-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofficialpycasbin%2Fpymongo-adapter/lists"}