Skip to main content

Embedded Valkey server for Python - like redislite but with Valkey!

Project description

valkeylite

PyPI version Python versions License Sponsored by Cyborg Inc.

Install and run Valkey directly from Python

valkeylite is a Python package that bundles the Valkey server (the open-source continuation of Redis) as a library. It provides an embedded Valkey server that can be started and stopped from Python code, eliminating the need for external Valkey installations or Docker containers during development and testing.

It's like redislite but with Valkey!

Features

  • 🚀 Drop-in replacement for redislite with Valkey
  • 🔧 Two APIs - Simple client wrapper OR explicit server control
  • 🧪 Perfect for testing - Isolated instances with auto-cleanup
  • Latest Valkey - Currently bundles Valkey 9.0.0
  • 🎯 Pytest fixtures - Built-in pytest integration
  • 🔓 Open source - MIT license, bundles BSD-3-Clause Valkey

Supported Platforms

Platform Architecture Status
Linux x86_64 ✅ Supported
Linux aarch64 (ARM64) ✅ Supported
macOS x86_64 (Intel) ✅ Supported
macOS arm64 (Apple Silicon) ✅ Supported
Windows - ❌ Not supported

Installation

pip install valkeylite

Includes valkey-py client automatically. For testing extras:

pip install valkeylite[test]

Quick Start

Client API (Like redislite)

from valkeylite import Valkey

# Just works - server starts automatically
r = Valkey()
r.set('key', 'value')
assert r.get('key') == b'value'
r.close()

# Or with context manager
with Valkey() as r:
    r.set('key', 'value')
    assert r.get('key') == b'value'

# With persistence
r = Valkey('/tmp/mydata.db')
r.set('key', 'value')
r.close()

Server API

from valkeylite import ValkeyServer

# Full control over server lifecycle
with ValkeyServer() as server:
    print(f"Valkey running at {server.host}:{server.port}")

    # Use built-in client
    client = server.client()
    client.set('key', 'value')

    # Or bring your own (any Redis-compatible client)
    import aredis
    client = aredis.Redis(**server.connection_kwargs)

Pytest Integration

# Automatically available with valkeylite[test]

def test_with_server(valkeylite):
    """Use the server fixture."""
    import valkey
    client = valkey.Valkey(**valkeylite.connection_kwargs)
    client.set('test', 'data')
    assert client.get('test') == b'data'

def test_with_client(valkey_client):
    """Use the pre-configured client fixture."""
    valkey_client.set('test', 'data')
    assert valkey_client.get('test') == b'data'

Command-Line Interface

# Start server in foreground
valkeylite

# Or with python -m
python -m valkeylite

# Specify port
valkeylite --port 6380

# See all options
valkeylite --help

Advanced Usage

Custom Configuration

from valkeylite import ValkeyServer
from pathlib import Path

server = ValkeyServer(
    port=6380,                    # Specific port (None = auto-assign)
    host='127.0.0.1',            # Bind address
    data_dir=Path('/tmp/valkey'), # Data directory (None = temp)
    persist=True,                 # Keep data after shutdown
    config={
        'maxmemory': '100mb',
        'maxmemory-policy': 'allkeys-lru',
        'loglevel': 'debug',
    }
)

server.start()
# ... use server ...
server.stop()

Multiple Instances

from valkeylite import ValkeyServer

# Run multiple isolated servers
with ValkeyServer(port=6379) as server1:
    with ValkeyServer(port=6380) as server2:
        # Two independent Valkey instances
        client1 = server1.client()
        client2 = server2.client()

Manual Lifecycle Management

from valkeylite import ValkeyServer

server = ValkeyServer()
server.start(timeout=10.0)  # Wait up to 10s for startup

try:
    # Use server
    print(f"Server running: {server.is_running()}")
    print(f"Connection URL: {server.connection_url}")
finally:
    server.stop()  # Graceful shutdown
    # or server.terminate() for immediate kill

API Reference

Valkey (Client API)

class Valkey(valkey.Valkey):
    """
    Valkey client with embedded server (like redislite.Redis).

    Inherits all methods from valkey.Valkey client.
    """

    def __init__(
        self,
        dbfilename: Optional[Path] = None,
        host: str = "127.0.0.1",
        port: Optional[int] = None,
        **kwargs: Any,
    ) -> None:
        """
        Initialize client with embedded server.

        Args:
            dbfilename: Path for persistent data (None = temporary)
            host: Host to bind to
            port: Port to bind to (None = auto-assign)
            **kwargs: Additional valkey.Valkey arguments
        """

    @property
    def server(self) -> ValkeyServer:
        """Access underlying ValkeyServer instance."""

ValkeyServer (Server API)

class ValkeyServer:
    """Explicit server lifecycle management."""

    def __init__(
        self,
        port: Optional[int] = None,
        host: str = "127.0.0.1",
        data_dir: Optional[Path] = None,
        config: Optional[Dict[str, Any]] = None,
        persist: bool = False,
        **config_overrides: Any,
    ) -> None:
        """Initialize Valkey server instance."""

    def start(self, timeout: float = 10.0) -> None:
        """Start server and wait until ready."""

    def stop(self, timeout: float = 5.0) -> None:
        """Gracefully stop server."""

    def client(self, **kwargs: Any) -> valkey.Valkey:
        """Create valkey-py client connected to this server."""

    @property
    def port(self) -> int:
        """Get server port."""

    @property
    def connection_kwargs(self) -> Dict[str, Any]:
        """Get connection parameters for any client."""

Pytest Fixtures

# Available with pip install valkeylite[test]

@pytest.fixture
def valkeylite() -> ValkeyServer:
    """Provides ValkeyServer instance."""

@pytest.fixture
def valkey_client(valkeylite) -> valkey.Valkey:
    """Provides connected valkey-py client."""

@pytest.fixture
def valkey_url(valkeylite) -> str:
    """Provides connection URL string."""

Migration from redislite

# Before
from redislite import Redis
r = Redis()
r.set('key', 'value')

# After
from valkeylite import Valkey
r = Valkey()
r.set('key', 'value')

With persistence:

# Before
from redislite import Redis
r = Redis('/tmp/redis.db')

# After
from valkeylite import Valkey
r = Valkey('/tmp/redis.db')

Development

# Clone repository
git clone https://github.com/cyborginc/valkeylite.git
cd valkeylite

# Install in development mode
pip install -e .[test]

# Run tests
pytest

Contributing

Contributions welcome! Please:

  1. Open an issue for bugs or feature requests
  2. Submit PRs with tests and documentation
  3. Follow existing code style

License

MIT License - see LICENSE file

Valkey is licensed under BSD 3-Clause License

Acknowledgments

This project is sponsored and maintained by Cyborg Inc.

  • Built on Valkey, the open-source continuation of Redis
  • Inspired by redislite

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

valkeylite-9.0.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distributions

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

valkeylite-9.0.0-py3-none-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

valkeylite-9.0.0-py3-none-manylinux_2_28_aarch64.whl (1.7 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

valkeylite-9.0.0-py3-none-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

valkeylite-9.0.0-py3-none-macosx_10_13_x86_64.whl (1.1 MB view details)

Uploaded Python 3macOS 10.13+ x86-64

File details

Details for the file valkeylite-9.0.0.tar.gz.

File metadata

  • Download URL: valkeylite-9.0.0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for valkeylite-9.0.0.tar.gz
Algorithm Hash digest
SHA256 3ab55288f27d1124650830076135fa2d52dc8ac1de13bf8bcc5d0e239caa55b6
MD5 b8a00af8423ad9cc23b5b6f47b6d80b6
BLAKE2b-256 9c0ff588872504c59f71ad2871c40a74faa4603f574ed5c1b4b48006bb8ff8db

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkeylite-9.0.0.tar.gz:

Publisher: build-and-release.yml on cyborginc/valkeylite

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

File details

Details for the file valkeylite-9.0.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for valkeylite-9.0.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 477a5894622c91dd099d8854b2b1cda2d2fe86f265ad85f535ae28685e8c1095
MD5 b1ea15f34b7e14b1ad806f2756b925a1
BLAKE2b-256 56f97a7794c26ecb31331332df68b4588154e2f203f2e59be43ae8e4fbe9e76d

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkeylite-9.0.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: build-and-release.yml on cyborginc/valkeylite

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

File details

Details for the file valkeylite-9.0.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for valkeylite-9.0.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b23de2a0cb9521d1d64254779541395bffeb6db16f3af854dc60998e0ffaef85
MD5 df4ed33ac0637973be66ea80921471eb
BLAKE2b-256 1c2fddd81afa4ade1bff7b04dd4f788165c4bf4ca7d780b9bfb1e1a077d27b75

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkeylite-9.0.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: build-and-release.yml on cyborginc/valkeylite

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

File details

Details for the file valkeylite-9.0.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for valkeylite-9.0.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98d106c75a108e6a67af6ecc9417db544a882fd38c9b6b23494c0acb970d0bfc
MD5 5e1d7a2d80f66b5ec22c87091ce1fef4
BLAKE2b-256 3f509b0762b97e4cbdedce16e55ea3b6470f248d1cdb38c0f19cffd6080f2196

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkeylite-9.0.0-py3-none-macosx_11_0_arm64.whl:

Publisher: build-and-release.yml on cyborginc/valkeylite

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

File details

Details for the file valkeylite-9.0.0-py3-none-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for valkeylite-9.0.0-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 80a4f427e6fe6a65048051a999dec302e4cc7c80edba6f9de538c130e833b71c
MD5 ddc0af56856a963301aba920c96ac4cd
BLAKE2b-256 76af865b8c660e633fc4221943110a9856558c1a1678de0467a45707a7908af9

See more details on using hashes here.

Provenance

The following attestation bundles were made for valkeylite-9.0.0-py3-none-macosx_10_13_x86_64.whl:

Publisher: build-and-release.yml on cyborginc/valkeylite

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