python-redis-factory


Namepython-redis-factory JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA universal Redis client factory for Python—just pass a single connection string (supporting standalone, Sentinel, or Cluster modes) and get back a ready-to-use redis.Redis instance.
upload_time2025-07-27 18:51:35
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT
keywords async client cluster connection factory redis sentinel
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python Redis Factory

[![CI](https://github.com/smirnoffmg/python-redis-factory/workflows/CI/badge.svg)](https://github.com/smirnoffmg/python-redis-factory/actions)
[![Test Coverage](https://codecov.io/gh/smirnoffmg/python-redis-factory/branch/main/graph/badge.svg)](https://codecov.io/gh/smirnoffmg/python-redis-factory)
[![Python Version](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://www.python.org/downloads/)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![PyPI Version](https://img.shields.io/pypi/v/python-redis-factory.svg)](https://pypi.org/project/python-redis-factory/)
[![Downloads](https://img.shields.io/pypi/dm/python-redis-factory.svg)](https://pypi.org/project/python-redis-factory/)

A universal Redis client factory for Python—just pass a single connection string (supporting standalone, Sentinel, or Cluster modes) and get back a ready-to-use redis.Redis instance.

## Features

- **Universal Interface**: Single API for all Redis deployment modes
- **Automatic Detection**: Automatically detects deployment mode from URI
- **Async Support**: Full async/await support with the same simple API
- **Connection Pooling**: Automatic connection pool management
- **SSL Support**: Built-in SSL/TLS support
- **Error Handling**: Comprehensive error handling and validation

## Quick Start

```python
from python_redis_factory import get_redis_client

# Standalone Redis
client = get_redis_client("redis://localhost:6379")

# Standalone with password
client = get_redis_client("redis://:secret@localhost:6379")

# Standalone with database selection
client = get_redis_client("redis://localhost:6379/1")

# Async Standalone
client = get_redis_client("redis://localhost:6379", async_client=True)

# Sentinel
client = get_redis_client("redis+sentinel://sentinel1:26379/mymaster")

# Cluster
client = get_redis_client("redis+cluster://node1:7000,node2:7001")

# SSL
client = get_redis_client("rediss://localhost:6379")
```

## Installation

```bash
pip install python-redis-factory
```

## Development Setup

```bash
# Clone the repository
git clone <repository-url>
cd python-redis-factory

# Install dependencies
make install

# Run tests in parallel (recommended)
make test-parallel

# Run specific test categories
uv run pytest tests/unit/ -n auto      # Unit tests only
uv run pytest tests/integration/ -n auto  # Integration tests only

# Run with coverage
make test-coverage

# Linting and type checking
make lint
make type-check

# Run full CI checks
make ci
```

### Setup PyPI and Codecov

For PyPI publishing and Codecov integration setup, see [SETUP.md](SETUP.md).

### Quick Commands

```bash
make help          # Show all available commands
make version       # Show current version
make release-patch # Release patch version (0.1.0 -> 0.1.1)
make release-minor # Release minor version (0.1.0 -> 0.2.0)
make release-major # Release major version (0.1.0 -> 1.0.0)
```

## Making Releases

The project supports automated releases via GitHub Actions. For detailed release instructions, see [RELEASE.md](RELEASE.md).

### Quick Release Process

```bash
# 1. Ensure all tests pass
make ci

# 2. Choose release type and execute
make release-patch  # Bug fixes
make release-minor  # New features  
make release-major  # Breaking changes

# 3. GitHub Actions automatically:
#    - Runs quality checks
#    - Bumps version
#    - Creates git tag
#    - Publishes to PyPI
#    - Creates GitHub release
```

## Testing

The project uses comprehensive testing with parallel execution:

### Test Categories
- **Unit Tests**: Fast, no external dependencies (`tests/unit/`)
- **Integration Tests**: Use testcontainers for real Redis instances (`tests/integration/`)

### Parallel Testing
Tests run in parallel by default using `pytest-xdist`:
- **Auto-detection**: `-n auto` (uses all CPU cores)
- **Fixed workers**: `-n 4` (uses 4 workers)
- **Disable parallel**: `-n 0` (sequential execution)

### Test Commands
```bash
# All tests in parallel (recommended)
uv run pytest -n auto

# Unit tests only (fast)
uv run pytest tests/unit/ -n auto

# Integration tests only (slower, requires Docker)
uv run pytest tests/integration/ -n auto

# With coverage report
uv run pytest --cov=python_redis_factory --cov-report=html -n auto

# Specific test file
uv run pytest tests/unit/test_simple_api.py -n auto
```

## Supported URI Formats

### Standalone Redis
```
redis://[user:password@]host[:port][/db]
rediss://[user:password@]host[:port][/db]  # SSL
```

### Redis Sentinel
```
redis+sentinel://[password@]sentinel1:port,sentinel2:port/service_name
```

### Redis Cluster
```
redis+cluster://[password@]node1:port,node2:port
```

## API Reference

### `get_redis_client(redis_dsn: str, async_client: bool = False)`

Creates a Redis client from a connection string.

**Parameters:**
- `redis_dsn`: Redis connection string (URI format)
- `async_client`: If True, returns an async Redis client

**Returns:**
- A Redis client instance (sync or async)

**Examples:**
```python
# Sync client
client = get_redis_client("redis://localhost:6379")
result = client.get("key")

# Async client
client = get_redis_client("redis://localhost:6379", async_client=True)
result = await client.get("key")
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "python-redis-factory",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": "Maksim Smirnov <smirnoffmg@gmail.com>",
    "keywords": "async, client, cluster, connection, factory, redis, sentinel",
    "author": null,
    "author_email": "Maksim Smirnov <smirnoffmg@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/4f/bd/6d691e0f960f2e0f2aa5e318efddccaa9fd2be2232eda00449559e5849be/python_redis_factory-0.1.0.tar.gz",
    "platform": null,
    "description": "# Python Redis Factory\n\n[![CI](https://github.com/smirnoffmg/python-redis-factory/workflows/CI/badge.svg)](https://github.com/smirnoffmg/python-redis-factory/actions)\n[![Test Coverage](https://codecov.io/gh/smirnoffmg/python-redis-factory/branch/main/graph/badge.svg)](https://codecov.io/gh/smirnoffmg/python-redis-factory)\n[![Python Version](https://img.shields.io/badge/python-3.12%2B-blue.svg)](https://www.python.org/downloads/)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)\n[![PyPI Version](https://img.shields.io/pypi/v/python-redis-factory.svg)](https://pypi.org/project/python-redis-factory/)\n[![Downloads](https://img.shields.io/pypi/dm/python-redis-factory.svg)](https://pypi.org/project/python-redis-factory/)\n\nA universal Redis client factory for Python\u2014just pass a single connection string (supporting standalone, Sentinel, or Cluster modes) and get back a ready-to-use redis.Redis instance.\n\n## Features\n\n- **Universal Interface**: Single API for all Redis deployment modes\n- **Automatic Detection**: Automatically detects deployment mode from URI\n- **Async Support**: Full async/await support with the same simple API\n- **Connection Pooling**: Automatic connection pool management\n- **SSL Support**: Built-in SSL/TLS support\n- **Error Handling**: Comprehensive error handling and validation\n\n## Quick Start\n\n```python\nfrom python_redis_factory import get_redis_client\n\n# Standalone Redis\nclient = get_redis_client(\"redis://localhost:6379\")\n\n# Standalone with password\nclient = get_redis_client(\"redis://:secret@localhost:6379\")\n\n# Standalone with database selection\nclient = get_redis_client(\"redis://localhost:6379/1\")\n\n# Async Standalone\nclient = get_redis_client(\"redis://localhost:6379\", async_client=True)\n\n# Sentinel\nclient = get_redis_client(\"redis+sentinel://sentinel1:26379/mymaster\")\n\n# Cluster\nclient = get_redis_client(\"redis+cluster://node1:7000,node2:7001\")\n\n# SSL\nclient = get_redis_client(\"rediss://localhost:6379\")\n```\n\n## Installation\n\n```bash\npip install python-redis-factory\n```\n\n## Development Setup\n\n```bash\n# Clone the repository\ngit clone <repository-url>\ncd python-redis-factory\n\n# Install dependencies\nmake install\n\n# Run tests in parallel (recommended)\nmake test-parallel\n\n# Run specific test categories\nuv run pytest tests/unit/ -n auto      # Unit tests only\nuv run pytest tests/integration/ -n auto  # Integration tests only\n\n# Run with coverage\nmake test-coverage\n\n# Linting and type checking\nmake lint\nmake type-check\n\n# Run full CI checks\nmake ci\n```\n\n### Setup PyPI and Codecov\n\nFor PyPI publishing and Codecov integration setup, see [SETUP.md](SETUP.md).\n\n### Quick Commands\n\n```bash\nmake help          # Show all available commands\nmake version       # Show current version\nmake release-patch # Release patch version (0.1.0 -> 0.1.1)\nmake release-minor # Release minor version (0.1.0 -> 0.2.0)\nmake release-major # Release major version (0.1.0 -> 1.0.0)\n```\n\n## Making Releases\n\nThe project supports automated releases via GitHub Actions. For detailed release instructions, see [RELEASE.md](RELEASE.md).\n\n### Quick Release Process\n\n```bash\n# 1. Ensure all tests pass\nmake ci\n\n# 2. Choose release type and execute\nmake release-patch  # Bug fixes\nmake release-minor  # New features  \nmake release-major  # Breaking changes\n\n# 3. GitHub Actions automatically:\n#    - Runs quality checks\n#    - Bumps version\n#    - Creates git tag\n#    - Publishes to PyPI\n#    - Creates GitHub release\n```\n\n## Testing\n\nThe project uses comprehensive testing with parallel execution:\n\n### Test Categories\n- **Unit Tests**: Fast, no external dependencies (`tests/unit/`)\n- **Integration Tests**: Use testcontainers for real Redis instances (`tests/integration/`)\n\n### Parallel Testing\nTests run in parallel by default using `pytest-xdist`:\n- **Auto-detection**: `-n auto` (uses all CPU cores)\n- **Fixed workers**: `-n 4` (uses 4 workers)\n- **Disable parallel**: `-n 0` (sequential execution)\n\n### Test Commands\n```bash\n# All tests in parallel (recommended)\nuv run pytest -n auto\n\n# Unit tests only (fast)\nuv run pytest tests/unit/ -n auto\n\n# Integration tests only (slower, requires Docker)\nuv run pytest tests/integration/ -n auto\n\n# With coverage report\nuv run pytest --cov=python_redis_factory --cov-report=html -n auto\n\n# Specific test file\nuv run pytest tests/unit/test_simple_api.py -n auto\n```\n\n## Supported URI Formats\n\n### Standalone Redis\n```\nredis://[user:password@]host[:port][/db]\nrediss://[user:password@]host[:port][/db]  # SSL\n```\n\n### Redis Sentinel\n```\nredis+sentinel://[password@]sentinel1:port,sentinel2:port/service_name\n```\n\n### Redis Cluster\n```\nredis+cluster://[password@]node1:port,node2:port\n```\n\n## API Reference\n\n### `get_redis_client(redis_dsn: str, async_client: bool = False)`\n\nCreates a Redis client from a connection string.\n\n**Parameters:**\n- `redis_dsn`: Redis connection string (URI format)\n- `async_client`: If True, returns an async Redis client\n\n**Returns:**\n- A Redis client instance (sync or async)\n\n**Examples:**\n```python\n# Sync client\nclient = get_redis_client(\"redis://localhost:6379\")\nresult = client.get(\"key\")\n\n# Async client\nclient = get_redis_client(\"redis://localhost:6379\", async_client=True)\nresult = await client.get(\"key\")\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A universal Redis client factory for Python\u2014just pass a single connection string (supporting standalone, Sentinel, or Cluster modes) and get back a ready-to-use redis.Redis instance.",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/smirnoffmg/python-redis-factory/issues",
        "Changelog": "https://github.com/smirnoffmg/python-redis-factory/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/smirnoffmg/python-redis-factory#readme",
        "Homepage": "https://github.com/smirnoffmg/python-redis-factory",
        "Repository": "https://github.com/smirnoffmg/python-redis-factory"
    },
    "split_keywords": [
        "async",
        " client",
        " cluster",
        " connection",
        " factory",
        " redis",
        " sentinel"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ab59639c4d5c16f7773b09b565588545a24b406b7d54fa935d782e841c2a78e4",
                "md5": "5ae29f89cf50d6034721b328d120e60d",
                "sha256": "54139366865a5216d00142dcfdc8be8bfd75ea1385f95ae0a42fb3b0ce760e56"
            },
            "downloads": -1,
            "filename": "python_redis_factory-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5ae29f89cf50d6034721b328d120e60d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 12919,
            "upload_time": "2025-07-27T18:51:33",
            "upload_time_iso_8601": "2025-07-27T18:51:33.905213Z",
            "url": "https://files.pythonhosted.org/packages/ab/59/639c4d5c16f7773b09b565588545a24b406b7d54fa935d782e841c2a78e4/python_redis_factory-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4fbd6d691e0f960f2e0f2aa5e318efddccaa9fd2be2232eda00449559e5849be",
                "md5": "54b52175b1f5d4c0f40d71c8d9b8b04c",
                "sha256": "e47aca6badf3b27ed11b1a91de241ed867d9ddd9dcb6528022d6cb1b5e8d6861"
            },
            "downloads": -1,
            "filename": "python_redis_factory-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "54b52175b1f5d4c0f40d71c8d9b8b04c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 56204,
            "upload_time": "2025-07-27T18:51:35",
            "upload_time_iso_8601": "2025-07-27T18:51:35.272892Z",
            "url": "https://files.pythonhosted.org/packages/4f/bd/6d691e0f960f2e0f2aa5e318efddccaa9fd2be2232eda00449559e5849be/python_redis_factory-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-27 18:51:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "smirnoffmg",
    "github_project": "python-redis-factory",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "python-redis-factory"
}
        
Elapsed time: 1.38614s