Metadata-Version: 2.4
Name: jamlib
Version: 4.1.2
Summary: Simple and universal library for authorization.
Author-email: Makridenko Adrian <adrianmakridenko@duck.com>, Ksenia Travnikova <kseniatravnikova@duck.com>
License: Apache-2.0
Project-URL: Homepage, https://jam.makridenko.ru
Project-URL: Repository, https://github.com/mkrdnk/jam
Project-URL: Issues, https://github.com/mkrdnk/jam/issues
Project-URL: Changelog, https://github.com/mkrdnk/jam/blob/master/CHANGELOG.md
Keywords: Authentication,Authorization,Backend,JOSE,PASETO,SAML,Sessions,OTP,TOTP,OAuth2,Litestar,FastAPI,Starlette,Flask,Django,Django REST Framework,DRF
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Development Status :: 5 - Production/Stable
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Internet :: WWW/HTTP :: Session
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet
Classifier: Typing :: Typed
Classifier: Framework :: Flask
Classifier: Framework :: FastAPI
Classifier: Framework :: Django
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: cryptography>=50.0.0
Requires-Dist: packaging>=24.0
Provides-Extra: cli
Requires-Dist: click>=8.3.1; extra == "cli"
Provides-Extra: redis
Requires-Dist: redis>=7.3.0; extra == "redis"
Provides-Extra: json
Requires-Dist: tinydb>=4.8.2; extra == "json"
Provides-Extra: oauth2
Requires-Dist: httpx>=0.28.1; extra == "oauth2"
Provides-Extra: yaml
Requires-Dist: pyyaml>=6.0.3; extra == "yaml"
Provides-Extra: toml
Requires-Dist: toml>=0.10.2; extra == "toml"
Provides-Extra: litestar
Requires-Dist: litestar>=2.21.1; extra == "litestar"
Provides-Extra: starlette
Requires-Dist: starlette>=0.52.1; extra == "starlette"
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.135.1; extra == "fastapi"
Provides-Extra: flask
Requires-Dist: flask>=3.1.2; extra == "flask"
Provides-Extra: django
Requires-Dist: django>=5.2; extra == "django"
Provides-Extra: drf
Requires-Dist: django>=5.2; extra == "drf"
Requires-Dist: djangorestframework>=3.18.1; extra == "drf"
Provides-Extra: dmr
Requires-Dist: django>=5.2; python_version >= "3.11" and extra == "dmr"
Requires-Dist: django-modern-rest>=0.15.0; python_version >= "3.11" and extra == "dmr"
Dynamic: license-file

# Jam

![logo](https://github.com/mkrdnk/jam/blob/master/docs/public/assets/h_logo_n_title.png?raw=true)

![Python Version](https://img.shields.io/badge/Python-3.10+-blue?logo=python&logoColor=white)
[![PyPI - Version](https://img.shields.io/pypi/v/jamlib)](https://pypi.org/project/jamlib/)
[![PyPI Downloads](https://static.pepy.tech/personalized-badge/jamlib?period=total&units=INTERNATIONAL_SYSTEM&left_color=GRAY&right_color=RED&left_text=Downloads)](https://pypi.org/project/jamlib/)
![tests](https://github.com/mkrdnk/jam/actions/workflows/run-tests.yml/badge.svg)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/mkrdnk/jam)
[![GitHub License](https://img.shields.io/github/license/mkrdnk/jam)](https://github.com/mkrdnk/jam/blob/master/LICENSE.md)

**Jam (Jam Auth Module)** - Jam (Jam Auth Module) - A universal auth* framework that provides popular auth mechanisms strictly according to the specification.

* Documentation: [jam.makridenko.com](https://jam.makridenko.com)
* Changelog: [CHANGELOG.md](https://github.com/mkrdnk/jam/blob/master/CHANGELOG.md)


## Install
```bash
pip install jamlib
```

## Quick example
```python
from dataclasses import dataclass

from jam import BaseSubject, Jam


@dataclass
class User(BaseSubject):
    id: int
    email: str


jam = Jam(config="config.toml", subject=User)

user = User(id=1, email="user@example.com")

token = jam.issue(subject=user, via="jwt")
principal = jam.authenticate(token, via="jwt")
user = principal.subject

allowed: bool = jam.authorize(
    principal=principal,
    permission="post:create"
)
```

## Why Jam?
Jam is a library that provides the most popular AUTH* mechanisms right out of the box.

* [JOSE](https://jam.makridenko.com/4.1.0/authentication/jose/index)
* [PASETO](https://jam.makridenko.com/4.1.0/authentication/paseto)
* [Server side sessions](https://jam.makridenko.com/4.1.0/authentication/sessions/)
* [OTP](https://jam.makridenko.com/4.1.0/authentication/otp/)
* [OAuth2](https://jam.makridenko.com/4.1.0/identity/oauth2/)
* [SAML](https://jam.makridenko.com/4.1.0/authentication/saml/)

### Authorization
Jam combines permissions granted to one credential with server-side policy rules. This makes it possible to issue two tokens for the same user with different permissions and to restrict those permissions using the current time, resource or request.

```python
principal = jam.authenticate(token, via="jwt")

if jam.authorize(principal, "user:delete"):
    ...
```

### Framework integrations

Jam provides ready-to-use integrations for the most popular frameworks:

* [Django](https://jam.makridenko.com/4.1.0/integrations/django)
* [FastAPI](https://jam.makridenko.com/4.1.0/integrations/fastapi)
* [Starlette](https://jam.makridenko.com/4.1.0/integrations/starlette)
* [Litestar](https://jam.makridenko.com/4.1.0/integrations/litestar)
* [Flask](https://jam.makridenko.com/4.1.0/integrations/flask)

Each integration offers built-in middleware or plugin support for JWT and session-based authentication.

### Why choose Jam?
Jam supports many authentication methods out of the box with minimal dependencies.
Here is a comparison with other libraries:


| Features / Library    | **Jam** | [Authx](https://authx.yezz.me/) | [PyJWT](https://pyjwt.readthedocs.io) | [AuthLib](https://docs.authlib.org) | [OTP Auth](https://otp.authlib.org/) |
|-----------------------|--------|----------------------------------|---------------------------------------|-------------------------------------|--------------------------------------|
| JOSE                  | ✅     | ❌ only JWT                      | ❌ only JWT                           | ✅                                  | ❌                                   |
| JWT black/white lists | ✅     | ❌                               | ❌                                    | ❌                                  | ❌                                   |
| PASETO                | ✅     | ❌                               | ❌                                    | ❌                                  | ❌                                   |
| Server side sessions  | ✅     | ✅                               | ❌                                    | ❌                                  | ❌                                   |
| OTP                   | ✅     | ❌                               | ❌                                    | ❌                                  | ✅                                   |
| OAuth2                | ✅     | ✅                               | ❌                                    | ✅                                  | ❌                                   |
| SAML 2.0              | ✅     | ❌                               | ❌                                    | ❌                                  | ❌                                   |
| Flexible config       | ✅     | ❌                               | ❌                                    | ❌                                  | ❌                                   |
| Modularity            | ✅     | ❌                               | ❌                                    | ❌                                  | ❌                                   |
