- Notifications
You must be signed in to change notification settings - Fork8
Python without ifs and buts - an ORM layer for Python objects, inspired by Django
License
NotificationsYou must be signed in to change notification settings
onyb/reobject
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
reobject is an ORM layer for your objects. It allows you to track and queryobjects at runtime using a familiar query langauge inspired by Django ORM.
Note:reobject isNOT 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
fromreobject.modelsimportModel,FieldclassBook(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']
- Elegant data-model syntax inspired by Django ORM.
- Class-level model fields, out of the box object protocols, pretty reprs; powered byattrs.
- Advanced query language and chainable querysets. Read theQuerySet API docs.
- Transactions. Seeexample.
- Many-to-one model relationships. Seeexample
- [TBA] Attribute indexes for fast lookups.
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 whatreobject is capable of. Pull requests are most welcome.
Want to help? You can contribute to the project by:
- Using reobject in your projects, finding bugs, and proposing new features.
- Sending pull requests with recipes built using reobject.
- Trying your hand at somegood first bugs.
- Improving test coverage, and writing documentation.