Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

include LICENSE NOTICE DISCLAIMER README.md RELEASING.md requirements.txt requirements_dev.txt .rat-excludes
recursive-include tests *.py *.ini
recursive-include examples *.conf *.csv
recursive-include .github *.py *.yml
79 changes: 73 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
PyCasbin
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

Apache Casbin (Incubating) — PyCasbin
====

Apache Casbin (Incubating) is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Apache Incubator PMC.

Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.

While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Python 3.9 or newer is required. See [RELEASING.md](RELEASING.md) for source verification, local tests and the Apache release process. Versions through 2.8.0 predate Apache incubation.

[![build](https://github.com/apache/casbin-pycasbin/actions/workflows/build.yml/badge.svg)](https://github.com/apache/casbin-pycasbin/actions/workflows/build.yml)
[![Coverage Status](https://coveralls.io/repos/github/apache/casbin-pycasbin/badge.svg)](https://coveralls.io/github/apache/casbin-pycasbin)
[![Version](https://img.shields.io/pypi/v/pycasbin.svg)](https://pypi.org/project/pycasbin/)
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/pycasbin.svg)](https://pypi.org/project/pycasbin/)
[![Pyversions](https://img.shields.io/pypi/pyversions/pycasbin.svg)](https://pypi.org/project/pycasbin/)
[![Download](https://static.pepy.tech/badge/pycasbin)](https://pypi.org/project/pycasbin/)
[![Version](https://img.shields.io/pypi/v/apache-casbin.svg)](https://pypi.org/project/apache-casbin/)
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/apache-casbin.svg)](https://pypi.org/project/apache-casbin/)
[![Pyversions](https://img.shields.io/pypi/pyversions/apache-casbin.svg)](https://pypi.org/project/apache-casbin/)
[![Download](https://static.pepy.tech/badge/apache-casbin)](https://pypi.org/project/apache-casbin/)
[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)

**News**: 🔥 How to use it with `Django` ? Try [Django Authorization](https://github.com/officialpycasbin/django-authorization), an authorization library for `Django` framework.
Expand Down Expand Up @@ -136,12 +163,52 @@ What Casbin does NOT do:
1. authentication (aka verify ``username`` and ``password`` when a user logs in)
2. manage the list of users or roles. I believe it's more convenient for the project itself to manage these entities. Users usually have their passwords, and Casbin is not designed as a password container. However, Casbin stores the user-role mapping for the RBAC scenario.

## Cached enforcers

`CachedEnforcer`, `SyncedCachedEnforcer` and `AsyncCachedEnforcer` expose the
corresponding enforcer API with cached authorization decisions. For example:

```python
import casbin

e = casbin.CachedEnforcer("model.conf", "policy.csv")
allowed = e.enforce("alice", "data1", "read")
```

Changes through the enforcer's policy-management API invalidate its cache.
Changes to external data or directly to a model/role manager require
`invalidate_cache()` or an application-appropriate `set_expire_time(seconds)`.
Conditional-role models bypass caching by default; setting a positive, finite
expiry opts into a bounded staleness window. Zero, negative and non-finite
expiries keep that bypass in effect. Async policy-management methods must be awaited,
while `enforce()` stays synchronous.

Models, policies and regular-expression patterns are trusted configuration.
`regexMatch` uses Python's regular-expression engine and does not guarantee a
match timeout. `ipMatch` raises `ValueError` for a malformed request address;
applications should validate addresses or treat that error as a denied request.

## Installation

```
pip install pycasbin
python -m pip install apache-casbin
```

The Python import stays `import casbin`. When migrating an existing environment,
remove both legacy distributions before installing the Apache distribution:

```sh
python -m pip uninstall casbin pycasbin
python -m pip install apache-casbin
```

These distributions own overlapping `casbin/` files and must not be installed
together. Adapters that still declare a dependency on `casbin` or `pycasbin` can
reinstall a legacy distribution; use a compatible adapter release declaring
`apache-casbin`, or keep the existing environment until its migration is supported.
The async adapter example below describes the API, not a claim that every
published adapter has migrated its package dependencies.

## Documentation

https://casbin.apache.org/docs/overview/
Expand Down
78 changes: 78 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# Releasing Apache Casbin (Incubating) — PyCasbin

Apache Casbin (Incubating) is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Apache Incubator PMC.

Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.

While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Apache source packages are the release artifacts. PyPI wheels and sdists are convenience distributions built from the approved Apache source. Historical versions through 2.8.0 predate incubation. A branch build or GitHub tag does not establish release approval.

The Apache distribution is `apache-casbin` and the import package remains `casbin`. The package identity is separate from registry ownership and release approval. Avoid co-installing legacy `casbin`/`pycasbin`, which contain overlapping import files. Adapter dependency migrations are separate components and do not silently substitute an old core in candidate verification.

The synchronized enforcer uses the separately installed MIT-licensed `readerwriterlock` dependency. A small Casbin wrapper retains the context/direct API and gives each acquisition a separate handle, including when several threads share the same read context. It replaces the historical implementation carrying an unresolved Wikipedia-adaptation notice rather than re-licensing that code. The dependency is not bundled in the Apache source or Python distributions; inspect its resolved version/license separately.

## Prepare and test

Use Python 3.9 or newer for the library, and Python 3.12 for release tooling. The dependency requirements already require Python 3.9. Prepare the committed version, all scoped fixes, ASF headers, legal files, metadata, distributions and workflow changes together in one preparation PR. Retain origin notices and resolve third-party licensing before submission.

```sh
python -m pip install -r requirements_dev.txt coverage build twine
python -m unittest discover -s tests -t tests
python -m black --check .
python -m unittest discover -s .github/scripts -p 'test_*.py'
python -m build
python -m twine check --strict dist/*
java -jar /path/to/apache-rat.jar --scan-hidden-directories --exclude-file .rat-excludes --dir .
python .github/scripts/release.py python-check dist/<package>.whl
python .github/scripts/release.py python-check dist/<package>.tar.gz
```

To include the shared conformance suite, check out `apache/casbin` at commit `6a018f27246f5f270f6cfa6ca3e8c82f45812bec` separately and set `CASBIN_CONFORMANCE_DIR` to its `conformance` directory. This pins CI's test input; it does not bundle the other project's source. Without that environment variable the conformance test is explicitly skipped. Extracted-source builds should retain that input when testing the RC.

Test the built wheel in a fresh environment outside the checkout. Inspect both distributions for the exact committed version, full README disclaimer, all library modules and LICENSE/NOTICE/DISCLAIMER. The sdist also carries tests and example policies so it can be tested independently.

## Stage an RC

After merge, bind the actual merged commit and successful CI to the candidate. With the release manager's authorization, tag that commit as `vX.Y.Z-rcN`. Only RC-tag pushes trigger automatic candidate export. The workflow exports an **unsigned** `apache-casbin-pycasbin-X.Y.Z-incubating-src.tar.gz` and SHA-512 and creates a clearly marked GitHub prerelease with `latest=false`. It never uploads an RC to PyPI.

The release manager reviews the exact archive and legal/provenance evidence, signs it with an ASF key present in the project's KEYS, stages those same bytes under the ASF dev area, and verifies fresh public downloads and an independent extracted build. Obtain valid project/PPMC and IPMC approvals with source, signature/checksum and review links. Human review and voting are separate from the scripts' checks.

## Publish approved originals

Promote the approved source archive, `.asc` and `.sha512` unchanged to:

```text
https://downloads.apache.org/incubator/casbin/pycasbin-X.Y.Z-incubating/
```

Create the final `vX.Y.Z` tag at the approved candidate commit. A final-tag push performs no publication. After the approvals and ASF promotion, dispatch `release.yml` **from master** with that existing tag and the actual public project and IPMC result-thread URLs. The URLs are auditable references; a URL-shaped string does not prove that a vote passed. The release manager must validate their scope, votes and candidate binding before dispatch.

The workflow refuses an existing GitHub release, verifies committed version and strict tag syntax, downloads the promoted ASF originals, validates SHA-512 and GPG against downloaded KEYS, and compares every archived file's bytes and permissions with the tag. Only then does it build convenience packages from the extracted approved source, run tests, inspect Python contents and use `PYPI_TOKEN_CASBIN` to publish. Source assets are reused unchanged; the final archive is never regenerated. GitHub notes include the disclaimer, result links and verification instructions.

Record registry administration and credential access for the PPMC separately from GitHub/tag and ASF SVN permissions. Never test the release by performing a real registry upload. Inspect the actual installed PyPI package, official downloads, website and announcements after approved publication.

## Safe retries

Output directories must be empty, archives and stable tags must not be overwritten, and RCs never set the stable `latest` alias. If a run fails, inspect ASF, PyPI and GitHub first. PyPI is immutable: a partial upload must not cause a second upload or a rebuild of voted originals. The publish action's `skip-existing` option is deliberately not enabled. Use a reviewed channel-specific recovery for a partial publication rather than rerunning the entire job blindly.

The tooling validates integrity, contents and the configured route. It does not grant publication permission, certify source originality, verify vote eligibility, control registry ownership or replace human review.
42 changes: 31 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[project]
name = "pycasbin"
version = "2.6.1"
name = "apache-casbin"
version = "2.9.0"
authors = [
{name = "Apache Casbin (Incubating)", email = "dev@casbin.apache.org"},
{name = "Casbin", email = "admin@casbin.org"},
]
description = "An authorization library that supports access control models like ACL, RBAC, ABAC in Python"
description = "Apache Casbin (Incubating): authorization for Python with ACL, RBAC and ABAC models"
readme = "README.md"
keywords = [
"casbin",
Expand All @@ -19,31 +37,33 @@ keywords = [
"permission",
]
dynamic = ["dependencies"]
requires-python = ">=3.8"
license = {text = "Apache 2.0"}
requires-python = ">=3.9"
license = "Apache-2.0"
license-files = ["LICENSE", "NOTICE", "DISCLAIMER"]
classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
]

[project.urls]
"Home-page" = "https://github.com/apache/casbin-pycasbin"
Homepage = "https://casbin.apache.org/"
Documentation = "https://casbin.apache.org/docs/overview/"
Repository = "https://github.com/apache/casbin-pycasbin"
Issues = "https://github.com/apache/casbin-pycasbin/issues"

[build-system]
requires = ["setuptools"]
requires = ["setuptools>=77.0.3"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
exclude = ["tests", "tests.*"]
include = ["casbin", "casbin.*"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}

[tool.black]
line-length = 120
line-length = 120
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
simpleeval >= 1.0.3
wcmatch >= 10.1
simpleeval >= 1.0.5
wcmatch >= 10.1
Loading