Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

Repository files navigation

Build StatusPyPI versionPyPIcodecov

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.

Installation

reobject supports Python 3 only.

pip install reobject

Example usage

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']

Features

  • 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.

Crunching Design Patterns

PatternDescriptionPure Pythonreobject
FlyweightReuse existing instances of objects with identical stateLinkLink
MementoTransactional rollback of an object to a previous state in case of an exceptionLinkLink
PrototypeCreate clones of a prototype without instantiationLinkLink
SingletonRestrict a class to provide only a single instanceLinkLink
FacadeEncapsulate a complex subsystem within a single interface objectLinkLink
FluxEvent-driven state management inspired by Facebook FluxLinkLink

Note: Some of the examples above may be inaccurate. The idea is to demonstrate whatreobject is capable of. Pull requests are most welcome.

Contributing

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.

About

Python without ifs and buts - an ORM layer for Python objects, inspired by Django

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp