Skip to main content

Async user / group / permission management library backed by a Rust core (SQLite, Argon2, JWT, optional HTTP relay)

Project description

user-permission-py

PyPI - License PyPI - Version Pepy Total Downloads

ユーザーとグループを管理するための非同期ライブラリ user-permissionPython バインディング です。

Rust 実装本体は別リポジトリに分離されました: mokuichi147/user-permission

このリポジトリは PyO3 + maturin による薄いラッパーのみを含み、PyPI パッケージ user-permission をビルド・公開します。

クイックスタート (サーバーを試す)

インストール不要で、uvx から直接サーバーを起動できます。

uvx user-permission serve --webui

ブラウザで http://127.0.0.1:8000/ui を開くと Web 管理画面が利用できます。 オプション一覧は サーバー起動 を参照してください。

インストール

pip install user-permission

依存パッケージはありません (Rust 拡張に同梱)。Python 3.9 以降の abi3 wheel を公開しています。

ソースからビルドする場合:

maturin develop          # 開発用に現在の venv に組み込む
maturin build --release  # リリース wheel をビルド

使い方

初期化

import asyncio
from user_permission import Database

async def main():
    # 初回実行時にシークレットキーを自動生成(以降はファイルから読み込み)
    async with Database("app.db", secret="secret.key") as db:
        user = await db.users.create("alice", "password123")
        group = await db.groups.create("admins")

asyncio.run(main())

ユーザー管理

user = await db.users.create("alice", "password123", display_name="Alice")
user = await db.users.get_by_id(1)
user = await db.users.get_by_username("alice")
users = await db.users.list_all()

await db.users.update(user.id, password="new_password")
await db.users.update(user.id, display_name="Alice Smith")
await db.users.update(user.id, is_active=False)
await db.users.delete(user.id)

認証・トークン

from datetime import timedelta

token = await db.users.authenticate("alice", "password123")
token = await db.users.authenticate(
    "alice", "password123", expires_delta=timedelta(hours=24)
)

payload = db.token_manager.verify_token(token)
print(payload["sub"])        # ユーザーID(文字列)
print(payload["username"])   # ユーザー名
print(payload["is_admin"])   # bool

グループ管理

group = await db.groups.create("admins", description="Administrator group")
group = await db.groups.get_by_id(1)
group = await db.groups.get_by_name("admins")
groups = await db.groups.list_all()

await db.groups.update(group.id, description="Updated description")
await db.groups.delete(group.id)

グループメンバー管理

await db.groups.add_user(group.id, user.id)
await db.groups.remove_user(group.id, user.id)
members = await db.groups.get_members(group.id)
groups = await db.groups.get_user_groups(user.id)

サーバー起動

import asyncio
from user_permission import serve

asyncio.run(serve(host="0.0.0.0", port=8001, prefix="/api", webui=True))

CLI からも起動できます。

user-permission serve --host 0.0.0.0 --port 8001 --prefix /api --webui
オプション デフォルト 説明
--host 127.0.0.1 バインドアドレス
--port 8000 バインドポート
--database user_permission.db SQLiteデータベースのパス
--secret secret.key シークレットキーファイルのパス
--prefix (なし) APIルートプレフィックス(例: /api
--webui 無効 Web管理画面を有効化
--webui-prefix /ui 管理画面のURLプレフィックス

リレー(中継)

Database に URL を渡すと、ローカル SQLite と中央サーバーを同じインターフェースで切り替えられます。

from user_permission import Database

# ファイルパス → ローカル SQLite
db = Database("app.db", secret="secret.key")

# URL → リモートサーバーへ HTTP 中継
async with Database("http://localhost:8001") as db:
    token = await db.login("alice", "password123")
    users = await db.users.list_all()

db.login(...) で取得したトークンは Database が内部に保持し、以降のリクエストの Authorization: Bearer に自動付与されます。

REST API・管理者ロール・スキーマ

REST エンドポイント仕様、groups.is_admin による管理者ロールの扱い、データベーススキーマは Rust リポジトリの README を参照してください。

開発

# Python wheel をビルドして現在の venv に組み込む
maturin develop

# Python 統合テスト
pip install pytest pytest-asyncio
pytest tests/python

# リリース wheel をビルド
maturin build --release

リリース

pyproject.toml のバージョンを更新し、v で始まる Git タグを push すると GitHub Actions が 全プラットフォームの wheel をビルドして PyPI に公開します (詳細は .github/workflows/release.yml)。

ライセンス

MIT OR Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

user_permission-0.5.1.tar.gz (39.6 kB view details)

Uploaded Source

Built Distributions

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

user_permission-0.5.1-cp39-abi3-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.9+Windows x86-64

user_permission-0.5.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

user_permission-0.5.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.6 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

user_permission-0.5.1-cp39-abi3-macosx_11_0_arm64.whl (3.5 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

user_permission-0.5.1-cp39-abi3-macosx_10_12_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file user_permission-0.5.1.tar.gz.

File metadata

  • Download URL: user_permission-0.5.1.tar.gz
  • Upload date:
  • Size: 39.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for user_permission-0.5.1.tar.gz
Algorithm Hash digest
SHA256 6d8487dee2c6a9e6ab5fe1d6e98c7d9ea8cdb8a9d94578dc8842489ced7add69
MD5 27ffb437eeb356945a9c3fd9a5b05b63
BLAKE2b-256 a69545a88b58e682b9849e32950e0079d0c56f1174d2ce8ccf904f72bd0917cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for user_permission-0.5.1.tar.gz:

Publisher: release.yml on Mokuichi147/user-permission-py

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

File details

Details for the file user_permission-0.5.1-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for user_permission-0.5.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4a1f67c79f7d85e812b484d34a2bafdd3f8b49b92136fc121495ada3245967ec
MD5 bf0b7eb311570aa62ff11274d94e64fe
BLAKE2b-256 ee8516318cf15e6025078481dafa5e65b21d0680fb0058f23dedeec9aa416564

See more details on using hashes here.

Provenance

The following attestation bundles were made for user_permission-0.5.1-cp39-abi3-win_amd64.whl:

Publisher: release.yml on Mokuichi147/user-permission-py

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

File details

Details for the file user_permission-0.5.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for user_permission-0.5.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc3915399e30489b539d43bf1771f66467ee75828e958400e00567e6d6e4e3b1
MD5 5d0c3b3ccfc62fc4c66f8d036d7639fc
BLAKE2b-256 9739618a15f3844ffad35852682375ecb44a092c72252b8a20dcaf20117307d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for user_permission-0.5.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Mokuichi147/user-permission-py

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

File details

Details for the file user_permission-0.5.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for user_permission-0.5.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4a500ea9cad4c167d4ae028909801fa228d569a7caec58a218a06cdda8baeea3
MD5 d2845a9288a7517bc337b85ab5c969b8
BLAKE2b-256 932fbcaf7efb82e1a5d6debabe9049d70e72fb43c41a118ef059dc8d45882f57

See more details on using hashes here.

Provenance

The following attestation bundles were made for user_permission-0.5.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on Mokuichi147/user-permission-py

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

File details

Details for the file user_permission-0.5.1-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for user_permission-0.5.1-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 585a1875256c02d124e3bd9d7d264e8b74d1878dcf15e8f73c496adee08c7ad9
MD5 0e4ae9acb4d76a4c9bb9a134f37bb834
BLAKE2b-256 bd5eaf502dd9a89a2e1c6b0d6ef1263abcafd0540b412a33ecb0c8c635d0a1ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for user_permission-0.5.1-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on Mokuichi147/user-permission-py

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

File details

Details for the file user_permission-0.5.1-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for user_permission-0.5.1-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d73b46d46d62021fa968ff3953e3d57f08297aaeb93f6a6fbd8d2e7b85b2420b
MD5 b8424f1ca89d284b1ab600d0f3aa2a0b
BLAKE2b-256 2be908e99d02cb45d3ec2c3dea7813b75efe0b682e9049301ae16f6aa62043b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for user_permission-0.5.1-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on Mokuichi147/user-permission-py

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page