almasix-permission
Roles and permissions for Almasix.
Install as almasix.permission:
pip install almasix-permission
# or from the framework extras:
pip install "almasix[permission]"
from almasix.permission import HasRoles, Permission, Role
Install (editable)
pip install -e ".[dev]"
smith vendor:publish --tag=permission-config
smith vendor:publish --tag=permission-migrations
# Enable teams / UUID *before* migrating if you need them
smith migrate
Mix HasRoles onto your user model:
from almasix.auth import AuthenticatableMixin
from almasix.orm import Model
from almasix.permission import HasRoles
class User(HasRoles, AuthenticatableMixin, Model):
fillable = ("email", "name", "password")
Quick usage
from almasix.permission import Permission, Role
await Permission.create(name="edit articles")
await Role.create(name="writer")
role = await Role.find_by_name("writer")
await role.give_permission_to("edit articles")
await user.assign_role("writer")
await user.give_permission_to("delete articles")
assert await user.has_permission_to("edit articles")
assert user.can("edit articles") # via Gate.before
API surface
| Area | Methods / tools |
|---|---|
| Permissions | give_permission_to, revoke_permission_to, sync_permissions, has_permission_to, check_permission_to, has_direct_permission, get_all_permissions |
| Roles | assign_role, remove_role, sync_roles, has_role, has_any_role, has_all_roles, has_exact_roles |
| Teams | set_permissions_team_id / get_permissions_team_id |
| Prism | @role, @hasrole, @haspermission, … |
| Middleware | role:, permission:, role_or_permission: (optional ,guard) |
| Commands | smith permission:create-role (--team-id), create-permission, show (style), assign-role, cache-reset, setup-teams |
Features
- Roles and permissions (direct or via roles), polymorphic assignment
Gate.beforesouser.can(…),@can, andcanmiddleware work- Multi-guard namespacing
- Teams (
permission.teams+set_permissions_team_id) - Wildcard permissions (
permission.enable_wildcard_permission) - Enum names (
enum.Enum/StrEnum) - Cache +
permission:cache-reset - Opt-in events (
permission.events_enabled) - UUID/ULID via
permission.key_typebefore migrate - Extending models through
permission.models.*
Tests
make test
make test-cov # fail_under=98 on almasix.permission
Discovery
[project.entry-points."almasix.providers"]
permission = "almasix.permission.provider:PermissionServiceProvider"
Or list the provider explicitly in config/app.py.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file almasix_permission-0.1.0.tar.gz.
File metadata
- Download URL: almasix_permission-0.1.0.tar.gz
- Upload date:
- Size: 26.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
052e41795711b7f6d163c95ce77fa7bc0e43d6685c84564296efceace12836d2
|
|
| MD5 |
e3e3303425cab9a8e702482c66ab7ef2
|
|
| BLAKE2b-256 |
9765e4424e8e206c711a3fb2adac3b7679097f3a52b9cb69b3ebf48071d1ab86
|
Provenance
The following attestation bundles were made for almasix_permission-0.1.0.tar.gz:
Publisher:
publish.yml on almasix-dev/almasix-permission
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
almasix_permission-0.1.0.tar.gz -
Subject digest:
052e41795711b7f6d163c95ce77fa7bc0e43d6685c84564296efceace12836d2 - Sigstore transparency entry: 2853812184
- Sigstore integration time:
-
Permalink:
almasix-dev/almasix-permission@ddf39a433584cf638c48196996b4c30e5e40c188 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/almasix-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ddf39a433584cf638c48196996b4c30e5e40c188 -
Trigger Event:
release
-
Statement type:
File details
Details for the file almasix_permission-0.1.0-py3-none-any.whl.
File metadata
- Download URL: almasix_permission-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb7b9bc5f81514e98c8d2390b8b8a9b30ee097ee799e07178694ed1036a5f9a9
|
|
| MD5 |
57a98ab0a8c2c2c22e323af6f3f852cf
|
|
| BLAKE2b-256 |
75e27027df8ce7d97dea73b1f947f25f8f1b8cca36df4fa3e0408328408cc8a2
|
Provenance
The following attestation bundles were made for almasix_permission-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on almasix-dev/almasix-permission
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
almasix_permission-0.1.0-py3-none-any.whl -
Subject digest:
eb7b9bc5f81514e98c8d2390b8b8a9b30ee097ee799e07178694ed1036a5f9a9 - Sigstore transparency entry: 2853812228
- Sigstore integration time:
-
Permalink:
almasix-dev/almasix-permission@ddf39a433584cf638c48196996b4c30e5e40c188 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/almasix-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ddf39a433584cf638c48196996b4c30e5e40c188 -
Trigger Event:
release
-
Statement type: