{"library":"redis-om","title":"Redis OM Python","description":"Redis OM Python is an object-mapping library that provides high-level abstractions to easily model, validate, and query data in Redis with modern Python applications. It leverages Pydantic for robust data validation and supports both Redis Hashes (`HashModel`) and JSON documents (`JsonModel`) for data storage, including automatic index generation and a fluent query API. Currently at version 1.1.0, the library maintains an active development pace with frequent updates and major version releases every few months.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install redis-om"],"cli":null},"imports":["from redis_om import HashModel","from redis_om import JsonModel","from redis_om import Field","from redis_om import Migrator"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom datetime import date\nfrom redis_om import HashModel, Migrator\n\n# Ensure Redis Stack is running, e.g., with Docker:\n# docker run -d -p 6379:6379 -p 8001:8001 redis/redis-stack\n\n# Set the Redis connection URL (or it defaults to redis://localhost:6379)\nos.environ['REDIS_OM_URL'] = os.environ.get('REDIS_OM_URL', 'redis://localhost:6379')\n\nclass Customer(HashModel):\n    first_name: str\n    last_name: str\n    email: str\n    join_date: date\n    age: int\n\n    class Meta:\n        global_key_prefix = \"my_app\"\n        model_key_prefix = \"customers\"\n        # By default, all fields are indexed in 1.0+, but can be specified individually\n        # for more granular control if not using a model-level index.\n\n# Run index migrations at application startup\n# For models defined as `HashModel` or `JsonModel`\nMigrator().run()\n\n# Create a customer\nnew_customer = Customer(\n    first_name=\"John\",\n    last_name=\"Doe\",\n    email=\"john.doe@example.com\",\n    join_date=date(2023, 1, 15),\n    age=30\n)\n\n# Save the customer to Redis\nnew_customer.save()\nprint(f\"Saved customer with PK: {new_customer.pk}\")\n\n# Retrieve the customer by its primary key (pk)\nfound_customer = Customer.get(new_customer.pk)\nprint(f\"Retrieved customer: {found_customer.first_name} {found_customer.last_name}\")\n\n# Find customers by query\nold_customers = Customer.find(Customer.age > 25).all()\nfor c in old_customers:\n    print(f\"Old customer: {c.first_name} (Age: {c.age})\")\n","lang":"python","description":"This quickstart demonstrates defining a `HashModel`, connecting to Redis via an environment variable, running schema migrations, creating and saving model instances, and retrieving them by primary key and through a basic query. It assumes a Redis Stack instance is running locally (e.g., via Docker).","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}