Skip to main content

A very micro http framework.

Project description

yhttp-pony

PyPI Build Coverage Status

Pony ORM extension for yhttp.

Install

sudo apt install python3-dev libpq-dev postgresql  # Postgresql
pip install yhttp-pony

Usage

This is how to use the extension.

from yhttp import Appliation, json
from yhttp.ext import pony as ponyext 
from pony.orm import db_session as dbsession, PrimaryKey, Required


app = Application()
app.settings.merge('''
db:
  url: postgres://postgres:postgres@localhost/foo
''')
db = ponyext.install(app)


class Foo(db.Entity):
    id = PrimaryKey(int, auto=True)
    title = Required(str)


@app.route()
@json
@dbsession
def get(req):
    return {f.id:f.title for f in Foo.select()}


app.ready()

Command line interface

There is some command line interfaces which will be automatically added to your application when you call ponyext.install(app).

myapp db create
myapp db drop

Extending db sub-command

import easycli
from yhttp.ext.pony import initialize, deinitialize

from mypackage import app  # yhttp application


class InsertMockup(easycli.SubCommand):
    __command__ = 'insert-mockup-data'

    def __call__(self, args):
        initialize(app.db, app.settings.db)

        ...

        deinitialize(app.db)

...

db = install(app, cliarguments=[InsertMockup])

Use it as:

myapp db insert-mockup-data

Running tests

echo "ALTER USER postgres PASSWORD 'postgres'" | sudo -u postgres psql
make test
make cover

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

yhttp-pony-2.6.1.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

yhttp_pony-2.6.1-py3.8.egg (15.8 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