Skip to main content

almasix-permission

PyPI CI coverage python license

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.before so user.can(…), @can, and can middleware 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_type before 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

almasix_permission-0.1.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

almasix_permission-0.1.0-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

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

Hashes for almasix_permission-0.1.0.tar.gz
Algorithm Hash digest
SHA256 052e41795711b7f6d163c95ce77fa7bc0e43d6685c84564296efceace12836d2
MD5 e3e3303425cab9a8e702482c66ab7ef2
BLAKE2b-256 9765e4424e8e206c711a3fb2adac3b7679097f3a52b9cb69b3ebf48071d1ab86

See more details on using hashes here.

Provenance

The following attestation bundles were made for almasix_permission-0.1.0.tar.gz:

Publisher: publish.yml on almasix-dev/almasix-permission

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file almasix_permission-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for almasix_permission-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb7b9bc5f81514e98c8d2390b8b8a9b30ee097ee799e07178694ed1036a5f9a9
MD5 57a98ab0a8c2c2c22e323af6f3f852cf
BLAKE2b-256 75e27027df8ce7d97dea73b1f947f25f8f1b8cca36df4fa3e0408328408cc8a2

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page