Git Product home page Git Product logo

sanic_crud's Introduction

sanic_crud

Build Status PyPI PyPI version

sanic_crud is a REST API framework for creating a CRUD (Create/Retrieve/Update/Delete) API using Sanic and PeeWee You can use sanic_crud to automatically create an API from your PeeWee models, see how it works in the Documentation Contributions to the repository are welcome!

Example

from peewee import CharField, DateTimeField, SqliteDatabase, Model
import datetime
from sanic import Sanic
from sanic_crud import generate_crud

db = SqliteDatabase('my_app.db')

class BaseModel(Model):
    class Meta:
        database = db

class Person(BaseModel):
    name = CharField()
    email = CharField()
    create_datetime = DateTimeField(default=datetime.datetime.now, null=True)

db.create_tables([Person])

app = Sanic(__name__)
generate_crud(app, [Person])
app.run(host="0.0.0.0", port=8000, debug=True)

Installation

  • python -m pip install sanic-crud

Documentation

Documentation can be found in the docs directory.

TODO

sanic_crud's People

Contributors

reinami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sanic_crud's Issues

Does not work wth latest Sanic release.

Cool lib but there was problem with latest release of Sanic and peewee 3.8.0. First was the import error with log, After fixing that with from sanic.log import logger as log ended up with an error that points to this:

class CrudShortcuts(object):
    def __init__(self, model):
        self.table_name = model._meta.db_table
        self.model = model

I get the following error.

self.table_name = model._meta.db_table AttributeError: 'Metadata' object has no attribute 'db_table'

This is a great handy lib. Will be nice to get a fix.

Code cleanup

Quick cleanup of code, see if there are better ways to organize and optimize

Limit the number of methods available via API.

That's more a question, is it possible to limit number of HTTP methods for a resource?

e.g. I'd like only allow POST and GET ?

Or any other way to prevent users from modifying data?

Let's assume I have a BLOG page where admin user should be allowed to create, delete, modify and view posts, but user should be only allowed to fetch list of posts or a particular one. How do I achieve that? Unfortunately could not find anything in the docs.

Make model configs only overwrite parts of base app config

If you set a config on a model and also have a base route, it will completely overwrite the base route. Set it up so it is possible to only list the changes you want in the model and it will overwrite only the changed fields in the config.

ImportError: cannot import name 'generate_crud'

Noob here. I have this error
ImportError: cannot import name 'generate_crud'
when I try to run example code for sanic_crud

I have this installed, should be ok, but seems I am missing some info, any help?

aiofiles (0.3.2)
httptools (0.0.10)
peewee (2.8.5)
pip (9.0.1)
Sanic (0.3.0)
sanic-crud (0.2.4)
setuptools (28.8.0)
ujson (1.35)
uvloop (0.9.1)
websockets (4.0.1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.