Skip to main content

No project description provided

Project description

docs/source/_static/logo.png https://travis-ci.org/gabrielfalcao/plural.svg?branch=master

Instalation

pip install plural

Declaring Subjects

from plural import Plural
from plural import Subject

store = Plural('my-git-cms')

class Document(Subject):
    indexes = {'title'}
    predicates = (
        ('title', codec.Unicode),
        ('body', codec.Unicode),
        ('created_at', codec.DateTime),
        ('published_at', codec.DateTime),
    )

    incoming = {
        'authored_by': Author,
    }
    outgoing = {
        'contains': Tag,
    }

Create

uuid1 = 'deadbeefdeadbeefdeadbeefdeadbeef'

# providing your own uuid
docs1 = store.create(
    'Document',
    uuid=uuid1,
    title='Essay',
    body='body1',
)

# auto-generated uuid
docs2 = store.create(
    Document,
    title='Blog',
    body='body2',
)

store.commit()

uuid2 = docs2.uuid

Retrieve

One By UUID

# Using the class Document as subject type
docs1 = store.get_subject_by_uuid(Document, uuid1)

# Using the subject label
docs2 = store.get_subject_by_uuid('Document', uuid2)

Many By Indexed Predicate

from plural.query import predicate
# functional
query = lambda title: 'Blog' in title

# DSL
query = predicate('title').contains('Blog')
blog_documents = set(store.match_subjects_by_index(Document, 'title', query))

# With Regex
query = predicate('title').matches('([Bb]log|[Ee]ssa[yi]s?)')
blogs_and_essays = set(store.match_subjects_by_index(Document, 'title', query))

Update

docs1.title = 'new title'

docs2.title = 'documento dois'
docs2.body = '<p>Hello</p>'

store.merge(docs1, docs2)

# recreate the doc1
docs1 = store.create(
    Document,
    uuid=uuid1,
    title='Essay',
    body='body1',
)

Delete

store.delete(docs1)
store.commit()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plural-0.1.2.tar.gz (15.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page