A python ORM for Redis - RORM
Of late, I have been using Redis a lot, using the redis-py library on the client side. To speed up things and increase productivity I used Amix’s redis_wrap module. One feature I missed out, due to moving from Postgres to Redis was Django’s ORM. My code was full of repetitive patterns and boilerplate, but luckily python is an awesome language and you can fix it easily using magic methods and metaclasses.
For this ORM wrapper, I used __getattr__ and __setattr__, which allow you to handle the events where an object’s fields are set or retrieved. I changed the default behaviour to getting and setting from Redis instead.
I also used some metaclasses to integrate with the cool list, set and hash wrappers Amix made.
So now I can use it like this
I agree that this may not be very elegant, but that’s not a bad tradeoff, considering it is only 80 lines and took half an hour to write.
You can check the code here