Skip to main content

Fast B-tree–backed token store for stateful sessions

Project description

Shows a dark logo
Ruby SDK for the fast, file-backed, scalable JSON token engine

Buy Me a Coffee

⚠️ Version 1.0.0b0 — production testing phase
API is stable. Feedback is welcome before the final 1.0.0 release

Fast B-tree–backed token store for stateful user sessions
Provides authentication and authorization across multiple processes
Optimized for vertical scaling on a single server

Installation

pip install crudjt

How to use

  • One process starts the master
  • All other processes connect to it

Start CRUDJT master (once)

Start the CRUDJT master when your application boots

Only one process can do this for a single token storage

The master process manages sessions and coordination
All functions can also be used directly from it

Generate a new secret key (terminal)

export CRUDJT_SECRET_KEY=$(openssl rand -base64 48)

Start master (python)

import crudjt
import os

CRUDJT.Config.start_master(
  secret_key=os.environ['CRUDJT_SECRET_KEY'],
  store_jt_path='path/to/local/storage', # optional
  grpc_host='127.0.0.1', # default
  grpc_port=50051 # default
)

Important: Use the same secret_key across all sessions. If the key changes, previously stored tokens cannot be decrypted and will return nil or false

Start CRUDJT master in Docker

docker-compose.yml will be published after 1.0.0b0 Docker image builds

Connect to an existing CRUDJT master

Use this in all other processes

Typical examples:

  • multiple local processes
  • background jobs
  • forked processes
import crudjt

CRUDJT.Config.connect_to_master(
  grpc_host='127.0.0.1', # default
  grpc_port=50051 # default
)

Process layout

App boot
├─ Process A → start_master
├─ Process B → connect_to_master
└─ Process C → connect_to_master

C

data = {'user_id': 42, 'role': 11} # required
ttl = 3600 * 24 * 30 # optional: token lifetime (seconds)

# Optional: read limit
# Each read decrements the counter
# When it reaches zero — the token is deleted
silence_read = 10

token = CRUDJT.create(data, ttl, silence_read)
# token == 'HBmKFXoXgJ46mCqer1WXyQ'
# To disable token expiration or read limits, pass `None`
CRUDJT.create({'user_id': 42, 'role': 11}, None, None)

R

result = CRUDJT.read('HBmKFXoXgJ46mCqer1WXyQ')
# result == {'metadata': {'ttl': 101001, 'silence_read': 9}, 'data': {'user_id': 42, 'role': 11}}
# When expired or not found token
result = CRUDJT.read('HBmKFXoXgJ46mCqer1WXyQ')
# result == None

U

data = {'user_id': 42, 'role': 8}
# `None` disables limits
ttl = 600
silence_read = 100

result = CRUDJT.update('HBmKFXoXgJ46mCqer1WXyQ', data, ttl, silence_read)
# result == True
# When expired or not found token
result = CRUDJT.update('HBmKFXoXgJ46mCqer1WXyQ', { 'user_id': 42, 'role': 8 })
# result == False

D

result = CRUDJT.delete('HBmKFXoXgJ46mCqer1WXyQ')
# result == True
# When expired or not found token
result = CRUDJT.delete('HBmKFXoXgJ46mCqer1WXyQ')
# result == False

Performance

Metrics will be published after 1.0.0b0 GitHub Actions builds

Storage (File-backed)

Disk footprint

Metrics will be published after 1.0.0b0 GitHub Actions builds

Path Lookup Order

Stored tokens are placed in the file system according to the following order

  1. Explicitly set via CRUDJT.Config.start_master(store_jt_path='custom/path/to/file_system_db')
  2. Default system location
    • Linux: /var/lib/store_jt
    • macOS: /usr/local/var/store_jt
    • Windows: C:\Program Files\store_jt
  3. Project root directory (fallback)

Storage Characteristics

  • CRUDJT automatically removing expired tokens after start and every 24 hours without blocking the main thread
  • Storage automatically fsyncs every 500ms, meanwhile tokens ​​are available from cache

Multi-process Coordination

For multi-process scenarios, CRUDJT uses gRPC over an insecure local port for same-host communication only. It is not intended for inter-machine or internet-facing usage

Limits

The library has the following limits and requirements

  • Python version: tested with 3.12.5
  • Supported platforms: Linux, macOS, Windows (x86_64 / arm64)
  • Maximum json size per token: 256 bytes
  • secret_key format: must be Base64
  • secret_key size: must be 32, 48, or 64 bytes

Contact & Support

Shows a dark favicon in light color mode and a white one in dark color mode

Lincense

CRUDJT is released under the MIT License

💘 Shoot your g . ? Love me out via Patreon Sponsors!

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

crudjt-1.0.0b3.tar.gz (4.4 MB view details)

Uploaded Source

Built Distribution

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

crudjt-1.0.0b3-py3-none-any.whl (4.4 MB view details)

Uploaded Python 3

File details

Details for the file crudjt-1.0.0b3.tar.gz.

File metadata

  • Download URL: crudjt-1.0.0b3.tar.gz
  • Upload date:
  • Size: 4.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for crudjt-1.0.0b3.tar.gz
Algorithm Hash digest
SHA256 4343fb85abfd2fbb19c11879070320c0e12d6c6e2a6e537ae7da4d465b45fabe
MD5 59a31a020c12f02bb6f508718ada8599
BLAKE2b-256 684a68347ad06d7aeca5f2c0dab48948b321fb4477db2704b3eedf20510e8077

See more details on using hashes here.

File details

Details for the file crudjt-1.0.0b3-py3-none-any.whl.

File metadata

  • Download URL: crudjt-1.0.0b3-py3-none-any.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for crudjt-1.0.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 773a81aed3fd5e58c30cdbb4e459d4d8a79541a5371229f67d8e52ea3a662251
MD5 798c581bf3b94b457a14930d1caa8e64
BLAKE2b-256 358f5da14e626556f8c0f8ff78b9ec771b97840c8d4706a2f8eeee85fc7fc38f

See more details on using hashes here.

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