Skip to content

Aiven Logo
  • Pricing
  • Blog

Log in

Book a demo

Start for free

Developer Center
  1. Aiven Developer Center
  2. Databases

Migrating your Python Applications from Redis®* to Valkey™

You can quickly update your Python applications with Valkey™, the drop-in Redis®* replacement.

  • Valkey
  • Redis®
  • Developer
Subscribe to RSS
Loading...

Subscribe to RSS

Earlier this year, the team behind Redis®* made the decision to change their license from BSD to a proprietary license in combination with the SSPL v1. While licensing changes can be confusing, one solution is to migrate to a new platform that meets your licensing preferences.

Meet Valkey™, an open-source in memory data-store that was designed to be a drop-in replacement for Redis. The development team's goal is to make it easy to take your existing Redis implementation and replace it with Valkey without having to make a large amount of changes to configuration. Your biggest change will be using a Valkey-powered key store like the one provided by Aiven for Valkey.

Valkey Service in the Aiven Console

For Python developers we often use Redis in a transparent way. Like a task queue using Celery or a simple key cache for your web application to quickly retrieve information and save yourself from making unnecessary API calls. For these and many other use cases, you will not need to do much beyond install the valkey client and change your imports from redis to valkey.

That being said, we don’t know the plans for Redis after their licensing change so this guide will walk you through the steps of pointing your cache systems from Redis to Valkey. While this means we need to change a few more namespaces, Valkey has made it as simple as possible to make these changes quickly and confidently.

Install the Valkey Python package

The valkey Python package is available via PyPI and can be downloaded and installed using pip or any popular Python package manager.

pip install valkey

The Valkey Python Package is a fork from the last open-source version of the redis Python package which means you can install valkey[hiredis] to use the compiled response parser from the hiredis package.

Importing and using the Valkey package

For convenience, if you were using Redis version 7.0 or lower, you only need to change your import and you can continue to use the Redis class which is still available in Valkey. To do so only replace the import from redis to from valkey. You will need to also change the path to your new Service URI.

Look at how similar the redis.py connection is compared to the valkey connection is.

Here is the Redis connection file.

Loading code...

Here is the Valkey connection file.

Loading code...

Keep in mind the developers of Valkey cannot ensure that newer versions of Redis will be implemented in the same manner and the two products may deviate in development. That is why it is recommended you use the Valkey object inside of the package instead. Everything from that point should be the same as the Redis class object from version 7. This means all your set, get, query, and all commands that were exposed to the Redis package will be identical.

Loading code...

Aiven for Valkey is available across our many cloud providers and regions with backup and performance tiers to meet your needs.

Another Redis alternative supported by Valkey Python is Aiven for Dragonfly which supports for over 1TB of data per instance, processing over 500,000 requests per second, JSON and Vector Support for AI, compatibility with memcached, and more.

Table of contents

  • Install the Valkey Python package
  • Importing and using the Valkey package
Aiven Logo at footer
Loading...
  • Github
  • Facebook
  • LinkedIn
  • Twitter
  • Youtube

Company

  • About
  • Open source
  • Careers
  • Sustainability
  • Modern slavery statement
  • Press
  • Blog

Legal

  • Terms
  • SLA
  • AUP
  • Data processing
  • Privacy
  • DSA contact
  • Cookie policy
  • Website terms of use
  • Do not sell or share my personal information

Platform

  • Responsibility matrix
  • Subprocessors
  • Security and compliance
  • Resource library
  • Support services
  • Changelog
  • Aiven status

Contact

  • Contact us
  • Book a demo
  • Support
  • Invoice address
  • Events calendar

Copyright © Aiven 2016-2025. Apache, Apache Kafka, Kafka, Apache Flink, and Flink are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries. ClickHouse is a registered trademark of ClickHouse, Inc. https://clickhouse.com. OpenSearch, PostgreSQL, MySQL, Grafana, Dragonfly, Valkey, Thanos, Terraform, and Kubernetes are trademarks and property of their respective owners. All product and service names used in this website are for identification purposes only and do not imply endorsement.

from redis import Redis redis_connection = Redis.from_url( "rediss://<AIVEN_FOR_CACHING_SERVICE_URI>" decode_responses=True, )
from valkey import Redis # change `rediss://` to `valkeys://` valkey_connection = Redis.from_url( "valkeys://<AIVEN_FOR_CACHING_SERVICE_URI>" decode_responses=True, )
>>> from valkey import Valkey >>> valkey_connection = Valkey.from_url( "valkeys://<AIVEN_FOR_CACHING_SERVICE_URI>" decode_responses=True, ) # You will still have access to all of the endpoints >>> valkey.set("memstore", "valkey") # same for hget/hset, etc >>> valkey.get("memstore") "valkey"