Skip to main content
userharbor

GitHub License Tests Codecov PyPI - Python Version PyPI - Version uv Pytest

userharbor-inmemory is a minimal, contract-tested UserStore implementation for UserHarbor. It can be installed directly for tests and examples or used as a GitHub template when building a custom storage integration.

[!WARNING] All data is process-local and is lost when the store instance is discarded. This package is not a persistent database and is not intended for production storage.

Installation

pip install userharbor-inmemory

The package depends on userharbor and has no database or framework dependencies.

Usage

from userharbor import UserHarbor
from userharbor_inmemory import InMemoryUserStore


store = InMemoryUserStore()

harbor = UserHarbor(
    secret_key="your-secret-key",
    store=store,
    email_sender=email_sender,
)

Each InMemoryUserStore instance starts empty and keeps its data for the lifetime of that instance.

The store implements the complete UserHarbor persistence contract:

  • users and password hashes
  • case-insensitive username lookup and uniqueness with original casing preserved
  • email verification and password reset tokens
  • sessions and session refresh
  • roles and permissions
  • user-role and role-permission assignments
  • commit, rollback, and nested transaction behavior

Each user has at most one active email verification token and one active password reset token. Storing a replacement invalidates the previous token. Users may have multiple active sessions.

Use as an integration template

Select Use this template on GitHub and create a new repository. The generated repository starts with a complete implementation and a passing contract suite, so backend code can be replaced incrementally while the tests continue to verify UserStore behavior.

GitHub copies files without replacing project-specific names. After creating a repository:

  1. Rename the distribution in pyproject.toml.
  2. Rename the userharbor_inmemory package and InMemoryUserStore class.
  3. Update project metadata, links, badges, and this README.
  4. Replace the in-memory dictionaries and snapshot transaction with the target backend.
  5. Adapt the user_store fixture in tests/conftest.py to create and clean up the backend.
  6. Keep backend-specific tests separate from the shared contract suite.
  7. Run the complete test suite before publishing.

The contract tests stay intentionally small in this repository:

# tests/test_user_store_contract.py

from userharbor.testing.user_store_contract import *  # noqa: F403
# tests/conftest.py

import pytest

from userharbor_inmemory import InMemoryUserStore


@pytest.fixture
def user_store() -> InMemoryUserStore:
    return InMemoryUserStore()

See the UserStore contract testing guide and custom integrations guide for the complete behavioral requirements.

Development

Install the project and run its tests:

uv sync
uv run pytest

The suite imports the shared contract distributed with UserHarbor. Tests specific to this package remain in tests/test_public_api.py.

To develop against an unpublished local UserHarbor checkout, keep both repositories in the same parent directory and run:

uv run --with-editable ../userharbor pytest

Limitations

InMemoryUserStore is deliberately small. It does not provide persistence across process restarts, cross-process sharing, durable transactions, or concurrency guarantees. Its snapshot-based transaction implementation exists to reproduce the atomic behavior required by UserHarbor in tests and examples.

License

UserHarbor In-Memory is licensed under the MIT License. See LICENSE for details.

Metadata

Release files for userharbor-inmemory 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for userharbor-inmemory 0.2.1
File Size Uploaded
userharbor_inmemory-0.2.1.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for userharbor-inmemory 0.2.1
File Interpreter ABI Platform
userharbor_inmemory-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / userharbor_inmemory-0.2.1.tar.gz

Download URL userharbor_inmemory-0.2.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
91d0e5bb4b32fcf495c40973a1da98312ce22fd2a07957f007c71a94da381fa6
BLAKE2b-256 checksum
How to use checksums
a5cc8e36b51ff60366d673615caf9c12155fd19344634c28a394ad125e300ec1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / userharbor_inmemory-0.2.1-py3-none-any.whl

Download URL userharbor_inmemory-0.2.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc648ba1d431399843d20c2ab4f45862f844b83435a5164d68df23b1cd943ede
BLAKE2b-256 checksum
How to use checksums
474c5392665bb25bbcb3eb49bc1ffc80757d9c08a8e755c8a1b1a2f64d127153
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.3.0

2 release files

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release 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