Python without ifs and buts - an ORM layer for Python objects, inspired by Django
APACHE-2.0 License
reobject is an ORM layer for your objects. It allows you to track and query objects at runtime using a familiar query langauge inspired by Django ORM.
Note: reobject is NOT a database ORM. It keeps track of regular objects in the memory.
This is highly experimental code, and not safe for production.
reobject supports Python 3 only.
pip install reobject
from reobject.models import Model, Field
class Book(Model):
title = Field()
authors = Field()
price = Field()
>>> # Create a bunch of objects
>>> Book(title='The C Programming Language', authors=['Kernighan', 'Ritchie'], price=52)
>>> Book(title='The Go Programming Language', authors=['Donovan', 'Kernighan'], price=30)
>>> Book.objects.all() # All books
[Book(title='The C Programming Language', authors=['Kernighan', 'Ritchie'], price=52),
Book(title='The Go Programming Language', authors=['Donovan', 'Kernighan'], price=30)]
>>> Book.objects.filter(price__lt=50).values('title') # Titles of books priced under $50
[{'title': 'The Go Programming Language'}, {'title': 'The C Programming Language'}]
>>> # Titles of books co-authored by Brian Kernighan
>>> Book.objects.filter(authors__contains='Kernighan').values_list('title', flat=True)
['The Go Programming Language', 'The C Programming Language']
Pattern | Description | Pure Python | reobject |
---|---|---|---|
Flyweight | Reuse existing instances of objects with identical state | Link | Link |
Memento | Transactional rollback of an object to a previous state in case of an exception | Link | Link |
Prototype | Create clones of a prototype without instantiation | Link | Link |
Singleton | Restrict a class to provide only a single instance | Link | Link |
Facade | Encapsulate a complex subsystem within a single interface object | Link | Link |
Flux | Event-driven state management inspired by Facebook Flux | Link | Link |
Note: Some of the examples above may be inaccurate. The idea is to demonstrate what reobject is capable of. Pull requests are most welcome.
Want to help? You can contribute to the project by: