Skip to content

jam.jose.lists

lists

Module for managing JWT black and white lists.

Modules:

Name Description
json
memory
redis

Classes:

Name Description
BaseJWTList

Abstract class for lists manipulation.

JSONList

JSON file-based JWT black/white list.

MemoryList

In-memory JWT black/white list.

RedisList

Redis-based JWT black/white list.

BaseJWTList

Bases: ABC

Abstract class for lists manipulation.

Methods:

Name Description
add

Add a single token to the list.

add_many

Add multiple tokens to the list.

check

Check if a token is present in the list.

check_many

Check multiple tokens in the list.

delete

Remove a single token from the list.

delete_many

Remove multiple tokens from the list.

add abstractmethod

add(token: str) -> None

Add a single token to the list.

add_many abstractmethod

add_many(tokens: list[str]) -> None

Add multiple tokens to the list.

check abstractmethod

check(token: str) -> bool

Check if a token is present in the list.

check_many abstractmethod

check_many(tokens: list[str]) -> dict[str, bool]

Check multiple tokens in the list.

delete abstractmethod

delete(token: str) -> None

Remove a single token from the list.

delete_many abstractmethod

delete_many(tokens: list[str]) -> None

Remove multiple tokens from the list.

JSONList

JSONList(
    type: Literal["white", "black"],
    prefix: str = "jwt_list",
    json_path: str = "whitelist.json",
    logger: BaseLogger | None = None,
)

Bases: BaseJWTList

JSON file-based JWT black/white list.

Not recommended for blacklists - no TTL support, user must manage token lifetime.

Dependency required: pip install jamlib[json]

Attributes:

Name Type Description
_db TinyDB

TinyDB instance.

_prefix str

Key prefix.

Methods:

Name Description
add

add single token to list

add_many

add multiple tokens to list

check

check if token exists in list

check_many

check multiple tokens in list

delete

remove token from list

delete_many

remove multiple tokens from list

Parameters:

Name Type Description Default
type Literal['white', 'black']

Type of list.

required
prefix str

Key prefix (used for logging).

'jwt_list'
json_path str

Path to JSON file.

'whitelist.json'
logger BaseLogger | None

Logger instance.

None

add

add(token: str) -> None

Add a single token to the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

add_many

add_many(tokens: list[str]) -> None

Add multiple tokens to the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

check

check(token: str) -> bool

Check if a token is present in the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

Returns:

Name Type Description
bool bool

True if token exists in list.

check_many

check_many(tokens: list[str]) -> dict[str, bool]

Check multiple tokens in the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

Returns:

Type Description
dict[str, bool]

dict[str, bool]: Mapping of token to presence.

delete

delete(token: str) -> None

Remove a token from the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

delete_many

delete_many(tokens: list[str]) -> None

Remove multiple tokens from the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

MemoryList

MemoryList(
    type: Literal["white", "black"],
    prefix: str = "jwt_list",
    logger: BaseLogger | None = None,
)

Bases: BaseJWTList

In-memory JWT black/white list.

Suitable for development, testing, or when external storage is not needed. No TTL support - tokens persist until explicitly removed.

Attributes:

Name Type Description
_storage dict

Internal storage for tokens.

Methods:

Name Description
add

add single token to list

add_many

add multiple tokens to list

check

check if token exists in list

check_many

check multiple tokens in list

delete

remove token from list

delete_many

remove multiple tokens from list

Parameters:

Name Type Description Default
type Literal['white', 'black']

Type of list.

required
prefix str

Key prefix for storage.

'jwt_list'
logger BaseLogger | None

Logger instance.

None

add

add(token: str) -> None

Add a single token to the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

add_many

add_many(tokens: list[str]) -> None

Add multiple tokens to the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

check

check(token: str) -> bool

Check if a token is present in the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

Returns:

Name Type Description
bool bool

True if token exists in list.

check_many

check_many(tokens: list[str]) -> dict[str, bool]

Check multiple tokens in the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

Returns:

Type Description
dict[str, bool]

dict[str, bool]: Mapping of token to presence.

delete

delete(token: str) -> None

Remove a token from the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

delete_many

delete_many(tokens: list[str]) -> None

Remove multiple tokens from the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

RedisList

RedisList(
    type: Literal["white", "black"],
    prefix: str = "jwt_list",
    redis_uri: str | Redis | None = None,
    redis: Redis | None = None,
    ttl: int | None = None,
    logger: BaseLogger | None = None,
)

Bases: BaseJWTList

Redis-based JWT black/white list.

Most optimal for production use with TTL support.

Dependency required: pip install jamlib[redis]

Attributes:

Name Type Description
_redis Redis

Redis instance.

_prefix str

Key prefix.

Methods:

Name Description
add

add single token to list

add_many

add multiple tokens to list

check

check if token exists in list

check_many

check multiple tokens in list

delete

remove token from list

delete_many

remove multiple tokens from list

Parameters:

Name Type Description Default
type Literal['white', 'black']

Type of list.

required
prefix str

Key prefix for Redis keys.

'jwt_list'
redis_uri str | Redis

Redis connection URI or Redis instance.

None
redis Redis | None

Redis instance (alias for redis_uri).

None
ttl int | None

Token TTL in seconds.

None
logger BaseLogger | None

Logger instance.

None

add

add(token: str) -> None

Add a single token to the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

add_many

add_many(tokens: list[str]) -> None

Add multiple tokens to the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

check

check(token: str) -> bool

Check if a token is present in the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

Returns:

Name Type Description
bool bool

True if token exists in list.

check_many

check_many(tokens: list[str]) -> dict[str, bool]

Check multiple tokens in the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required

Returns:

Type Description
dict[str, bool]

dict[str, bool]: Mapping of token to presence.

delete

delete(token: str) -> None

Remove a token from the list.

Parameters:

Name Type Description Default
token str

JWT token.

required

delete_many

delete_many(tokens: list[str]) -> None

Remove multiple tokens from the list.

Parameters:

Name Type Description Default
tokens list[str]

List of JWT tokens.

required