Convert Figma logo to code with AI

coleifer logowalrus

Lightweight Python utilities for working with Redis

1,148
91
1,148
0

Top Related Projects

66,246

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs, Bitmaps.

8,011

Disque is a distributed message broker

13,406

memcached development tree

26,065

The MongoDB Database

26,695

The open-source database for the realtime web.

47,330

Distributed reliable key-value store for the most critical data of a distributed system

Quick Overview

Walrus is a lightweight Python ORM (Object-Relational Mapping) and query builder for SQLite. It provides a simple and intuitive API for working with SQLite databases, allowing developers to interact with their data using Python objects instead of raw SQL queries.

Pros

  • Simple and lightweight, with minimal dependencies
  • Supports both synchronous and asynchronous operations
  • Includes a powerful query builder for complex queries
  • Integrates well with Flask and other web frameworks

Cons

  • Limited to SQLite databases only
  • Lacks some advanced features found in larger ORMs like SQLAlchemy
  • May not be suitable for very large-scale applications
  • Documentation could be more comprehensive

Code Examples

  1. Defining a model:
from walrus import *

db = Database(':memory:')

class User(Model):
    name = CharField()
    email = CharField(unique=True)
    age = IntegerField()

    class Meta:
        database = db
  1. Creating and saving a record:
user = User(name='John Doe', email='john@example.com', age=30)
user.save()
  1. Querying records:
# Find a user by email
john = User.get(User.email == 'john@example.com')

# Query multiple users
adults = User.select().where(User.age >= 18)
for user in adults:
    print(user.name)
  1. Using the query builder:
query = (User
         .select(User.name, fn.AVG(User.age).alias('avg_age'))
         .group_by(User.name)
         .having(fn.AVG(User.age) > 25))

for result in query:
    print(f"{result.name}: {result.avg_age}")

Getting Started

To get started with Walrus, first install it using pip:

pip install walrus

Then, create a database connection and define your models:

from walrus import *

db = Database('my_database.db')

class MyModel(Model):
    field1 = CharField()
    field2 = IntegerField()

    class Meta:
        database = db

db.create_tables([MyModel])

Now you can start creating, querying, and manipulating records using the Walrus ORM.

Competitor Comparisons

66,246

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs, Bitmaps.

Pros of Redis

  • Mature, battle-tested codebase with extensive documentation and community support
  • High performance and scalability, suitable for large-scale production environments
  • Rich feature set including advanced data structures, pub/sub, and Lua scripting

Cons of Redis

  • Steeper learning curve due to its extensive feature set and configuration options
  • Requires more system resources and setup compared to lightweight alternatives
  • Less Python-specific functionality out of the box

Code Comparison

Redis (C):

void setKey(redisClient *c) {
    robj *key = c->argv[1], *val = c->argv[2];
    setGenericCommand(c,OBJ_SET,key,val,NULL,0,NULL,NULL);
}

Walrus (Python):

def set(self, key, value):
    return self.client.set(key, self.encode(value))

Summary

Redis is a powerful, feature-rich in-memory data store with broad language support, while Walrus is a lightweight Python-specific Redis client with added conveniences for Python developers. Redis offers superior performance and scalability but may be overkill for smaller projects. Walrus provides a more Pythonic interface and easier integration for Python applications but lacks some of Redis's advanced features and multi-language support.

8,011

Disque is a distributed message broker

Pros of Disque

  • Designed specifically for distributed job queues, offering robust features for this use case
  • Built with high availability and fault tolerance in mind
  • Supports automatic replication and distribution of jobs across nodes

Cons of Disque

  • More complex setup and configuration compared to Walrus
  • Requires additional infrastructure to run as a distributed system
  • Less flexible for general-purpose key-value storage

Code Comparison

Disque (job enqueue):

di_job *job = di_job_create();
di_job_set_body(job, "Hello, World!", 13);
di_job_set_queue(job, "my-queue");
di_enqueue_job(client, job);

Walrus (key-value set):

db = Database()
db['key'] = 'Hello, World!'

While both projects deal with data storage, they serve different purposes. Disque is specialized for distributed job queues, offering features like automatic replication and fault tolerance. Walrus, on the other hand, is a simpler key-value store built on top of Redis, providing a more straightforward interface for general-purpose data storage. The code comparison highlights the difference in complexity and focus between the two projects.

13,406

memcached development tree

Pros of Memcached

  • Widely adopted and battle-tested in production environments
  • Highly scalable and distributed caching system
  • Supports multiple programming languages and platforms

Cons of Memcached

  • Limited data structure support (primarily key-value pairs)
  • Lacks built-in persistence mechanisms
  • No native support for data replication or sharding

Code Comparison

Memcached (C):

memcached_return_t memcached_set(memcached_st *ptr,
                                 const char *key,
                                 size_t key_length,
                                 const char *value,
                                 size_t value_length,
                                 time_t expiration,
                                 uint32_t flags);

Walrus (Python):

@cache.cached(timeout=3600)
def get_user(user_id):
    return User.get(user_id)

Memcached is a distributed memory caching system written in C, focusing on high performance and scalability. It's widely used in large-scale applications but has limitations in data structure support and persistence.

Walrus, on the other hand, is a Python library that provides a higher-level abstraction for caching, including support for various backends (e.g., Redis, Memcached). It offers a more Pythonic interface and additional features like decorators for easy caching of function results.

While Memcached excels in raw performance and scalability, Walrus provides a more developer-friendly experience with added flexibility in Python environments.

26,065

The MongoDB Database

Pros of Mongo

  • Mature, widely-used database system with extensive documentation and community support
  • Highly scalable and designed for distributed systems
  • Offers advanced features like sharding, replication, and aggregation pipelines

Cons of Mongo

  • More complex setup and configuration compared to lightweight alternatives
  • Requires more system resources and can be overkill for smaller projects
  • Steeper learning curve for developers new to NoSQL databases

Code Comparison

Walrus (Python):

db = Database()
users = db.table('users')
users.insert(name='Charlie', email='charlie@example.com')

Mongo (Python with pymongo):

client = MongoClient()
db = client.database
users = db.users
users.insert_one({"name": "Charlie", "email": "charlie@example.com"})

Summary

Mongo is a robust, feature-rich database system suitable for large-scale applications, while Walrus is a lightweight, Python-specific alternative. Mongo offers more advanced features and scalability but comes with increased complexity. Walrus provides a simpler interface and is more suitable for smaller projects or rapid prototyping. The code comparison shows that both have relatively straightforward APIs for basic operations, with Mongo requiring slightly more setup due to its client-server architecture.

26,695

The open-source database for the realtime web.

Pros of RethinkDB

  • Scalable distributed database with automatic sharding and replication
  • Real-time push architecture for live updating queries
  • Flexible query language with support for complex joins and aggregations

Cons of RethinkDB

  • Steeper learning curve due to more complex architecture
  • Higher resource requirements for running a distributed system
  • Less active development since being acquired by the Linux Foundation

Code Comparison

RethinkDB query example:

r.table('users').filter(r.row['age'] > 18).order_by('name').limit(10).run(conn)

Walrus query example:

User.select().where(User.age > 18).order_by(User.name).limit(10)

Key Differences

Walrus is a lightweight Python ORM for Redis, while RethinkDB is a full-fledged distributed database system. Walrus offers simplicity and ease of use for Redis-based applications, whereas RethinkDB provides more advanced features for scalable, real-time applications.

Walrus is better suited for smaller projects or those already using Redis, while RethinkDB excels in larger, distributed systems requiring real-time updates and complex queries.

47,330

Distributed reliable key-value store for the most critical data of a distributed system

Pros of etcd

  • Highly scalable and distributed key-value store
  • Strong consistency and fault-tolerance
  • Widely adopted in production environments, especially for Kubernetes

Cons of etcd

  • More complex setup and configuration
  • Higher resource requirements
  • Steeper learning curve for beginners

Code Comparison

etcd (Go):

cli, _ := clientv3.New(clientv3.Config{Endpoints: []string{"localhost:2379"}})
defer cli.Close()
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
_, err := cli.Put(ctx, "key", "value")
cancel()

Walrus (Python):

db = Database()
db.set('key', 'value')
value = db.get('key')

Key Differences

  • etcd is designed for distributed systems, while Walrus is a lightweight local key-value store
  • etcd offers advanced features like watch, lease, and transactions, whereas Walrus focuses on simplicity
  • etcd uses gRPC for communication, while Walrus is a Python library for in-memory or file-based storage

Both projects serve different purposes: etcd for distributed systems and Walrus for local, lightweight storage needs.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Walrus

Lightweight Python utilities for working with Redis.

The purpose of walrus is to make working with Redis in Python a little easier. Rather than ask you to learn a new library, walrus subclasses and extends the popular redis-py client, allowing it to be used as a drop-in replacement. In addition to all the features in redis-py, walrus adds support for some newer commands, including full support for streams and consumer groups.

walrus consists of:

Models

Persistent structures implemented on top of Hashes. Supports secondary indexes to allow filtering on equality, inequality, ranges, less/greater-than, and a basic full-text search index. The full-text search features a boolean search query parser, porter stemmer, stop-word filtering, and optional double-metaphone implementation.

Found a bug?

Please open a github issue and I will try my best to fix it!

Alternative Backends

Walrus also can integrate with the Redis-like databases rlite, ledis, and vedis. Check the documentation for more details.