Skip to main content

Embedded, auto-managed Valkey server for Python

Project description

valkey-embedded

CI License: BSD-3-Clause Python versions

Embedded, auto-managed Valkey server for Python. Construct a client and a private valkey-server starts; it shuts down and cleans up when the last client closes. No separate server install or running daemon required.

from valkey_embedded import Valkey

conn = Valkey()
conn.set("key", "value")
conn.get("key")          # b'value'
# server is stopped and cleaned up when the process exits

This project is motivated by redislite — the same embed-the-real-engine idea, reimplemented from scratch under BSD-3-Clause and targeting Valkey so the embedded binary can be freely redistributed on PyPI.

When to use valkey-embedded

valkey-embedded runs the real Valkey engine as an embedded, auto-managed server on a single machine, persisting via RDB snapshots (a cache/buffer, not a durable system-of-record). Those four properties decide where it fits.

Strong fit — this is what it's for:

  • Testing Redis/Valkey code. Every Valkey() is a private, clean server, so tests isolate cleanly and run in parallel. Because it's the real engine, expiry, eviction, blocking ops, MULTI/EXEC, and your Lua scripts behave exactly as in production — unlike reimplementations that drift.
  • CI without service containers. No services: redis, no docker-compose, no testcontainers, no "wait for healthy" — just pip install and run.
  • Local development & onboarding. Clone, run, works. No daemon to install or keep alive; the binary is bundled, so it works offline.
  • Demos, tutorials, notebooks. Ship something that just runs, with zero prerequisites.

Works, with caveats:

  • Single-box inter-process coordination / queues (shared mode). Treat it as an ephemeral buffer unless you open it with connect(path, durable=True); don't call .shutdown() from one process while others share the server; set maxmemory and TTLs to bound memory growth.
  • Local cache for a single-node app or CLI. Reach for it when you specifically want Redis data structures, pub/sub, or TTL semantics — otherwise SQLite is simpler.

Wrong tool — use something else:

You want… Use instead
Production serving, HA, or multi-host a real Valkey/Redis deployment
A durable system-of-record PostgreSQL
A durable single-file in-process database SQLite
Cross-machine shared state a real Valkey/Redis deployment
Windows-native (without WSL) a real Valkey/Redis deployment

In short: valkey-embedded owns the "I need the real Valkey engine, on one box, with zero infra — mostly for testing and local dev" niche. It is an embedded server, not an in-process database.

Install

pip install valkey-embedded          # prebuilt wheels: Linux x86_64, macOS 14+ arm64

Other POSIX platforms build Valkey from source at install time (needs gcc/clang and make). Windows is unsupported (WSL works).

Usage

  • Isolated server: Valkey() — a private server per instance.

  • Persistent / shared: Valkey("/path/to/db.rdb") — persists across runs; instances sharing the path attach to one server (last to close shuts it down).

    Note: the first positional argument is the RDB file path, not host — the embedded server has no host. Pass server overrides via serverconfig={"maxmemory": "64mb"}.

  • SQLite-style open with durability: connect() is sugar over Valkey() that reads like sqlite3.connect — open a file-backed store, opt into crash-safety, and release it by leaving a with block:

    import valkey_embedded
    
    with valkey_embedded.connect("data.db", durable=True) as db:
        db.set("user:1", "ada")     # AOF-backed: survives a crash, not just a clean exit
    # leaving the block persists and stops the embedded server
    

    durable=True enables the append-only file with appendfsync everysec (≤1s of writes lost on a crash); durable="always" fsyncs every write. Default (durable=False) is RDB snapshots only, which can lose writes since the last snapshot. durable= requires a path — an isolated server's data is discarded on exit. Force a snapshot anytime with db.bgsave().

  • Explicit server with a TCP endpoint: ValkeyServer is the other half of the API — you control start/stop, and the server listens on host/port so any Redis-compatible client (or another process) can connect:

    from valkey_embedded import ValkeyServer
    
    with ValkeyServer() as server:          # port auto-assigned; or ValkeyServer(port=6380)
        print(server.connection_url)        # valkey://127.0.0.1:<port>
        client = server.client()            # built-in valkey-py client
        client.set("k", "v")
        # bring your own: valkey.Valkey(**server.connection_kwargs)
    

    Explicit form: server = ValkeyServer(); server.start(); ...; server.stop() (is_running(), terminate(), persist=True, data_dir=…, config={…} too).

    Valkey() stays unix-socket-only with no TCP listener (private by default); reach for ValkeyServer when you need a port.

  • Pytest fixtures: installing the package registers fixtures automatically — no conftest wiring. One server runs per test session; each test gets a client with a clean keyspace (FLUSHALL on setup):

    def test_thing(valkey_client):           # client to the session server, keys wiped per test
        valkey_client.set("k", "v")
        assert valkey_client.get("k") == b"v"
    
    def test_other(valkey_server, valkey_url):
        assert valkey_server.is_running()    # the session ValkeyServer; valkey_url is its URL
    
    def test_pristine(valkey_server_factory):
        private = valkey_server_factory(persist=False)   # fresh server just for this test
        assert private.client().ping()
    

    Only keys are reset between tests; server-level state (CONFIG SET, loaded Lua scripts) persists for the session — use valkey_server_factory when a test needs a pristine process. Under pytest-xdist each worker gets its own server.

  • Command line: run a server in the foreground:

    valkey-embedded --port 6380        # or: python -m valkey_embedded
    
  • Diagnostics: python -m valkey_embedded.debug

  • Errors: failures to start the embedded server raise valkey_embedded.ServerStartError; its base class ValkeyEmbeddedError catches every error this library raises. (Command errors from the server itself are raised by valkey-py as usual.)

  • Also exported: StrictValkey (alias of Valkey, mirroring valkey-py); durable="everysec" as the explicit spelling of durable=True; __valkey_executable__ (path to the bundled valkey-server) and __valkey_server_version__ (its version, e.g. 8.1.8). A bundled valkey-cli ships next to the server binary for manual inspection:

    import os, valkey_embedded
    cli = os.path.join(os.path.dirname(valkey_embedded.__valkey_executable__), "valkey-cli")
    

Examples

Runnable scripts for each feature live in examples/ (basic usage, persistence, shared vs. isolated servers, patching, serverconfig, replication, and diagnostics):

python examples/01_basic.py

Migration from redislite

redislite valkey-embedded
redislite.Redis valkey_embedded.Valkey
redislite.patch.patch_redis valkey_embedded.patch.patch_valkey

Valkey is wire-compatible with Redis and valkey-py is forked from redis-py, so application logic is unchanged — only imports and class names differ.

Versioning & support

valkey-embedded follows Semantic Versioning. While on 0.x the API may still change between minor versions; any change is recorded in CHANGELOG.md. Supported Python versions are 3.9–3.13 on Linux and macOS (14+ arm64); Windows is supported only under WSL.

Contributing

See CONTRIBUTING.md for dev setup, the test tiers, and the procedure for pinning a new Valkey release. Participation is governed by our Code of Conduct; security issues go through SECURITY.md.

License

valkey-embedded is licensed under BSD-3-Clause. Built wheels bundle a compiled valkey-server binary, also BSD-3-Clause; its license — and the notices of the third-party code statically linked into it (Lua, hdr_histogram, fpconv, linenoise) — ship as valkey_embedded/bin/VALKEY_COPYING.txt alongside the binary. The valkey Python client is a runtime dependency, not redistributed here.

Trademark

valkey-embedded is an independent project and is not affiliated with, sponsored, or endorsed by the Valkey project or the Linux Foundation. Valkey is a trademark of LF Projects, LLC.

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

valkey_embedded-0.1.0.tar.gz (35.1 kB view details)

Uploaded Source

Built Distributions

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

valkey_embedded-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

valkey_embedded-0.1.0-cp313-cp313-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

valkey_embedded-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

valkey_embedded-0.1.0-cp312-cp312-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

valkey_embedded-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

valkey_embedded-0.1.0-cp311-cp311-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

valkey_embedded-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

valkey_embedded-0.1.0-cp310-cp310-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

valkey_embedded-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

valkey_embedded-0.1.0-cp39-cp39-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

File details

Details for the file valkey_embedded-0.1.0.tar.gz.

File metadata

  • Download URL: valkey_embedded-0.1.0.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for valkey_embedded-0.1.0.tar.gz
Algorithm Hash digest
SHA256 817e0d37588a4641da3326a84327cf124bae4eb4b2012a3186950d195080ebb5
MD5 1cd9e3df9ab4cfb33ab5a11be1169898
BLAKE2b-256 56b8ee35a2fd4b6d2a9a470efb7948bb094b514cebf686d14f0c31ebb40da101

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0.tar.gz:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4c0e821d34eef2bcee445f4f14a78093b47670c3250247adab7a209e55c9922f
MD5 c9f6cddac4cc0403f00278d746d28cc4
BLAKE2b-256 50510d7f27080c5119c1fe3bb393497af58934816963d944851f6931970f6ae9

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9e94df3e5258a49bc5671393c33b5df027eeea4bf6567883a16738aeb49a62a2
MD5 bea7737411f5a932dead3352e6283dc2
BLAKE2b-256 33c02cfd1df715556bfca99eb686c2e96eac70ff6540bef082e79b2824bd659a

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6dff5707af3c81c4c2edd408f9eddae4fe66fcee60678769f39e817800463d82
MD5 c492ce30b367bf161deac5d16e945dbd
BLAKE2b-256 0895f9b5c823c173b92369bd4534fcb300afa576cb5a837c26ab31f7ca745ad7

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bc0341b6f11c782984851c3ac68e7620afbb7d57fdc4735cae7195bc446e6f89
MD5 07e6258b0bbfe324d1d894ab5172312c
BLAKE2b-256 28a7147656c025fcf2669aad5e20ed694a6651526f434ea5b5ca6f90c88b23ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5bae222b82e6390f55a0b4fa3a6a24e9189af16901482e99b6c344f2ad425b8d
MD5 d716a5ad35dc9c66a1c4c7ae499afe81
BLAKE2b-256 289abcfa90bf4818633dd476bbe4d5b3e144ec4179a3f9fda026a831fcc808ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9a4bc4ecf80953dc59b9c480797aeee4c597de2910d07bf638d798c804365322
MD5 ffe9024601f4c9b9408771956366dae7
BLAKE2b-256 46505ce820bd83e61e0b9865d08cecf7684d2f2fa25d15dd61d9fb102cadb72c

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7f1144ef6ee49b515950620f6a1b4eebd396daa1e85355cd3a0a3144407ddca
MD5 106bb1354b3f86272155545597550326
BLAKE2b-256 04c9b88f7335ca1a156d7c76a56505bc11c100c4392a28b56050d7e5bd4c411a

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d960b5fc53b5187793da20b19bef9f36ddc113eb7b4dffdf9f7f105ff03f34ac
MD5 ba458d08b99d6e0a6a7bff5079bb5b11
BLAKE2b-256 bc0c03143744e958b920671a6237ddac87bb6655294a8d53b7da9b79a98619bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp310-cp310-macosx_14_0_arm64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1ee5f3a2b7210024743e789ef9ae1a720c82d4e45f68904b393fb446a7541dd8
MD5 35e5d8bedc3d0f456691eee5a3fd7998
BLAKE2b-256 8845b2a1b641f3e31e763b6c98f7caf1668d17ee7a439d6945c2bd0862cb4172

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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

File details

Details for the file valkey_embedded-0.1.0-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for valkey_embedded-0.1.0-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b9e654ed23aa85aea6cb1057ebd513899bc2a646c7cc5416feec8eaadfe2b381
MD5 7ef7bd870dea4be114bea6926ffb1aa1
BLAKE2b-256 01988bd47bcaabebd67a937fb1fdcff0e50018eae693973913d42f1055032e5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkey_embedded-0.1.0-cp39-cp39-macosx_14_0_arm64.whl:

Publisher: release.yml on abhiksark/valkey-embedded

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