Skip to main content

Centralize database access

Project description

Schemapy allows you to generate objects for centralized database access. You define the schema for your API, the code that needs to be executed, then the validation part is dealt with for you. Everything is then encapsulated in a single object.

Schemapy relies on PyDAL for schema definition but is not tied to it.

See documentation for more informations.

License Development Status Latest release Supported Python versions Supported Python implementations Download format Build status Code test coverage Code Health

Installation

pip install schemapy

Usage

Using PyDAL:

from schemapy import API, DAL, Field
from datetime import datetime, timedelta

db = DAL('sqlite:memory')
db.define_table(
    'users',
    Field('name', type='string', required=True),
    Field('created_on', type='date')
)

db.define_table(
    'posts',
    Field('subject', type='string', required=True),
    Field('author', type='reference users', required=True),
    Field('created_on', type='date'),
    Field('content', type='text', required=True)
)

api = API(db)

@api.as_action(
    type='read',
    request=[
        Field('begin', type='date', required=True),
        Field('end', type='date', required=True)
    ],
    response=db.posts
)
def select_posts_by_date(db, req, action):
    query = (db.posts.created_on >= req.begin) | (db.posts.created_on <= req.end)
    return db(query).select()

now = datetime.now()
result = api.select_posts_by_date(
    begin=now - timedelta(days=1),
    end=now
)
print(list(result))

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

schemapy-0.2.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

schemapy-0.2.0-py2.py3-none-any.whl (10.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file schemapy-0.2.0.tar.gz.

File metadata

  • Download URL: schemapy-0.2.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for schemapy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c5109fdb761e0f44e0c8ba36867b0b0c5b79748219fc5a2a94fa04ce2af012f5
MD5 52e9dc256f160e39caa610ba1daadade
BLAKE2b-256 e7c8a132a714620c1ff4a799bea71d3b8109d4b6f16bc57cf48bb50ef81b0c2b

See more details on using hashes here.

File details

Details for the file schemapy-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for schemapy-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 695e3c0e7f645fba32bba483f751b3a6beff71c5c093966d950ee344552ba22e
MD5 ee8e530e8e44eaf95cc6b7a57e7d8084
BLAKE2b-256 4b245813792a37eee4267d71db9ad6c10bf449bd0168224e58d13be5b9655719

See more details on using hashes here.

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