Simple framework for creating REST APIs

CoCongV, updated 🕥 2022-12-08 03:50:03

Build Status codebeat badge Maintainability Test Coverage PyPI version

Sanic-RESTful

Sanic-RESTful is an extension for Sanic that adds support for quickly building REST APIs. It is a lightweight abstraction that works with your existing ORM/libraries. Sanic-RESTful encourage best practices with minimal setup. if you are familiar with Sanic, Sanic-RESTful should be easy to pick up. It provides a coherent collection of decorators and tools to describe your API

Note

There are still references to modules from Flask and Werkzeug in the repo. But It work fine now.

Compatibility

Sanic-RESTful requires Python 3.6+

Installtion

pip install sanic-restful

Quick start

With Sanic-RESTful, you only import the api instance to route or sanic class instance, and document your endpoints Example (class-view): ```python from sanic import Sanic from sanic_restful import Api, Resource, reqparse

app = Sanic(name) api = Api(app, errors=errors)

TODOS = { 'todo1': {'task': 'build an API'}, 'todo2': {'task': '?????'}, 'todo3': {'task': 'profit!'}, }

parser = reqparse.RequestParser() parser.add_argument('id', location=form)

class Todo(Resource): async def get(self, request, to_id): return TODOS[to_id]

async def delete(self, request, todo_id):
    del TODOS[todo_id]
    return '', 204

async def put(self, request, todo_id):
    args = parser.parse_args(request)
    task = {'task': args['task']}
    TODOS[todo_id] = task
    return task, 201

async def patch(self, request, todo_id):
    raise Unauthorized('Fail')

api.add_resource(Todo, '/todos/')

if name == 'main': app.run(debug=True) ```

Decorators example: ```python from functools import wraps

from sanic import Sanic, Blueprint from sanic_restful import Resource, Api

TODOS = { 'todo1': {'task': 'build an API'}, 'todo2': {'task': '?????'}, 'todo3': {'task': 'profit!'}, }

def decorator(func): @wraps(func) async def wrapper(request, args, kwargs): print(type(request)) request.user = 'User' return await func(request, args, **kwargs) return wrapper

class TodoSimple(Resource): """ You can try this example as follow: $ curl http://localhost:5000/todo1 -d "data=Remember the milk" -X PUT $ curl http://localhost:5000/todo1 {"todo1": "Remember the milk"} $ curl http://localhost:5000/todo2 -d "data=Change my breakpads" -X PUT $ curl http://localhost:5000/todo2 {"todo2": "Change my breakpads"}

Or from python if you have requests :
 >>> from requests import put, get
 >>> put('http://localhost:5000/todo1', data={'data': 'Remember the milk'}).json
 {u'todo1': u'Remember the milk'}
 >>> get('http://localhost:5000/todo1').json
 {u'todo1': u'Remember the milk'}
 >>> put('http://localhost:5000/todo2', data={'data': 'Change my breakpads'}).json
 {u'todo2': u'Change my breakpads'}
 >>> get('http://localhost:5000/todo2').json
 {u'todo2': u'Change my breakpads'}

"""
method_decorators = {'get': decorator}

async def get(self, request, todo_id):
    return {todo_id: TODOS[todo_id]}

async def put(self, request, todo_id):
    TODOS[todo_id] = request.form.get('data')
    return {todo_id: TODOS[todo_id]}

app = Sanic(name) bp = Blueprint(name, url_prefix='/test') api = Api(bp)

api.add_resource(TodoSimple, '/<todo_id:string') app.register_blueprint(bp)

if name == 'main': app.run(debug=True) ``` Note: Sanic-RESTful is different with Flask-RESTful, Must be "async" that decoratored function. Otherwise, The app will raise "TypeError: xxxx can't be used in 'await' expression"

User Guide

This part of the documention will show you how to get started in using Sanic-RESTful with Sanic here

Additional Notes

Running the Tests

python setup.py test

PYPI

Sanic-RESTful @ PyPI

Issues

Bump certifi from 2019.11.28 to 2022.12.7

opened on 2022-12-08 03:50:02 by dependabot[bot]

Bumps certifi from 2019.11.28 to 2022.12.7.

Commits


Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/CoCongV/sanic-restful/network/alerts).

Bump py from 1.8.1 to 1.10.0

opened on 2022-10-18 19:53:53 by dependabot[bot]

Bumps py from 1.8.1 to 1.10.0.

Changelog

Sourced from py's changelog.

1.10.0 (2020-12-12)

  • Fix a regular expression DoS vulnerability in the py.path.svnwc SVN blame functionality (CVE-2020-29651)
  • Update vendored apipkg: 1.4 => 1.5
  • Update vendored iniconfig: 1.0.0 => 1.1.1

1.9.0 (2020-06-24)

  • Add type annotation stubs for the following modules:

    • py.error
    • py.iniconfig
    • py.path (not including SVN paths)
    • py.io
    • py.xml

    There are no plans to type other modules at this time.

    The type annotations are provided in external .pyi files, not inline in the code, and may therefore contain small errors or omissions. If you use py in conjunction with a type checker, and encounter any type errors you believe should be accepted, please report it in an issue.

1.8.2 (2020-06-15)

  • On Windows, py.path.locals which differ only in case now have the same Python hash value. Previously, such paths were considered equal but had different hashes, which is not allowed and breaks the assumptions made by dicts, sets and other users of hashes.
Commits
  • e5ff378 Update CHANGELOG for 1.10.0
  • 94cf44f Update vendored libs
  • 5e8ded5 testing: comment out an assert which fails on Python 3.9 for now
  • afdffcc Rename HOWTORELEASE.rst to RELEASING.rst
  • 2de53a6 Merge pull request #266 from nicoddemus/gh-actions
  • fa1b32e Merge pull request #264 from hugovk/patch-2
  • 887d6b8 Skip test_samefile_symlink on pypy3 on Windows
  • e94e670 Fix test_comments() in test_source
  • fef9a32 Adapt test
  • 4a694b0 Add GitHub Actions badge to README
  • Additional commits viewable in compare view


Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/CoCongV/sanic-restful/network/alerts).

Bump sanic from 19.12.2 to 20.12.7

opened on 2022-08-06 05:33:55 by dependabot[bot]

Bumps sanic from 19.12.2 to 20.12.7.

Release notes

Sourced from sanic's releases.

Version 20.12.7

Resolves #2477 and #2478 See also #2495 and https://github.com/sanic-org/sanic/security/advisories/GHSA-8cw9-5hmv-77w6

Full Changelog: https://github.com/sanic-org/sanic/compare/v20.12.6...v20.12.7

Version 20.12.6

What's Changed

Full Changelog: https://github.com/sanic-org/sanic/compare/v20.12.5...v20.12.6

Version 20.12.5

#2366 Upgrade websockets version - SECURITY UPDATE

Version 20.12.4

Version 20.12.3

Bugfixes

  • #2021 Remove prefix from websocket handler name

Version 20.12.2

Dependencies

  • #2026 Fix uvloop to 0.14 because 0.15 drops Python 3.6 support
  • #2029 Remove old chardet requirement, add in hard multidict requirement

Version 20.12.1

Features

  • #1993 Add disable app registry

Version 20.12.0

Features

  • [#1945][] Static route more verbose if file not found
  • [#1954][] Fix static routes registration on a blueprint
  • [#1961][] Add Python 3.9 support
  • [#1962][] Sanic CLI upgrade
  • [#1967][] Update aiofile version requirements
  • [#1969][] Update multidict version requirements
  • [#1970][] Add py.typed file
  • [#1972][] Speed optimization in request handler
  • [#1979][] Add app registry and Sanic class level app retrieval

Bugfixes

... (truncated)

Changelog

Sourced from sanic's changelog.

.. note::

CHANGELOG files are maintained in ./docs/sanic/releases. To view the full CHANGELOG, please visit https://sanic.readthedocs.io/en/stable/sanic/changelog.html.

Version 21.6.1

Bugfixes

  • [#2178](https://github.com/sanic-org/sanic/issues/2178) <https://github.com/sanic-org/sanic/pull/2178>_ Update sanic-routing to allow for better splitting of complex URI templates
  • [#2183](https://github.com/sanic-org/sanic/issues/2183) <https://github.com/sanic-org/sanic/pull/2183>_ Proper handling of chunked request bodies to resolve phantom 503 in logs
  • [#2181](https://github.com/sanic-org/sanic/issues/2181) <https://github.com/sanic-org/sanic/pull/2181>_ Resolve regression in exception logging
  • [#2201](https://github.com/sanic-org/sanic/issues/2201) <https://github.com/sanic-org/sanic/pull/2201>_ Cleanup request info in pipelined requests

Version 21.6.0

Features

  • [#2094](https://github.com/sanic-org/sanic/issues/2094) <https://github.com/sanic-org/sanic/pull/2094>_ Add response.eof() method for closing a stream in a handler

  • [#2097](https://github.com/sanic-org/sanic/issues/2097) <https://github.com/sanic-org/sanic/pull/2097>_ Allow case-insensitive HTTP Upgrade header

  • [#2104](https://github.com/sanic-org/sanic/issues/2104) <https://github.com/sanic-org/sanic/pull/2104>_ Explicit usage of CIMultiDict getters

  • [#2109](https://github.com/sanic-org/sanic/issues/2109) <https://github.com/sanic-org/sanic/pull/2109>_ Consistent use of error loggers

  • [#2114](https://github.com/sanic-org/sanic/issues/2114) <https://github.com/sanic-org/sanic/pull/2114>_ New client_ip access of connection info instance

  • [#2119](https://github.com/sanic-org/sanic/issues/2119) <https://github.com/sanic-org/sanic/pull/2119>_ Alternatate classes on instantiation for Config and Sanic.ctx

  • [#2133](https://github.com/sanic-org/sanic/issues/2133) <https://github.com/sanic-org/sanic/pull/2133>_ Implement new version of AST router

    • Proper differentiation between alpha and string param types
    • Adds a slug param type, example: <foo:slug>
    • Deprecates <foo:string> in favor of <foo:str>
    • Deprecates <foo:number> in favor of <foo:float>
    • Adds a route.uri accessor
  • [#2136](https://github.com/sanic-org/sanic/issues/2136) <https://github.com/sanic-org/sanic/pull/2136>_ CLI improvements with new optional params

  • [#2137](https://github.com/sanic-org/sanic/issues/2137) <https://github.com/sanic-org/sanic/pull/2137>_ Add version_prefix to URL builders

  • [#2140](https://github.com/sanic-org/sanic/issues/2140) <https://github.com/sanic-org/sanic/pull/2140>_ Event autoregistration with EVENT_AUTOREGISTER

... (truncated)

Commits
  • 05002d7 Path protection with pathlib
  • b4360d4 Path protection with pathlib
  • 3b85b3b Potential server crash if running Python 3.10 w/ Sanic 20.12 (#2400)
  • 6e55e73 fix: websocket dependency for websockets 9.1 security fix (#2366)
  • 89d9424 Merge branch 'pr2129' into 20.12LTS
  • 4d6205e Bump version
  • 1684b0b remove reference to yanked packages
  • 4f5faa4 unpin uvloop
  • cbb77b5 fix issue where request.args.pop removed parameters inconsistently (#2112)
  • 35c7625 Bump version 20.12.3 (#2062)
  • Additional commits viewable in compare view


Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/CoCongV/sanic-restful/network/alerts).

Bump aiohttp from 3.6.2 to 3.8.1

opened on 2022-06-25 07:53:07 by dependabot[bot]

Bumps aiohttp from 3.6.2 to 3.8.1.

Release notes

Sourced from aiohttp's releases.

v3.8.1

Bugfixes

  • Fix the error in handling the return value of getaddrinfo. getaddrinfo will return an (int, bytes) tuple, if CPython could not handle the address family. It will cause a index out of range error in aiohttp. For example, if user compile CPython with --disable-ipv6 option but his system enable the ipv6. (#5901)
  • Do not install "examples" as a top-level package. (#6189)
  • Restored ability to connect IPv6-only host. (#6195)
  • Remove Signal from __all__, replace aiohttp.Signal with aiosignal.Signal in docs (#6201)
  • Made chunked encoding HTTP header check stricter. (#6305)

Improved Documentation

  • update quick starter demo codes. (#6240)
  • Added an explanation of how tiny timeouts affect performance to the client reference document. (#6274)
  • Add flake8-docstrings to flake8 configuration, enable subset of checks. (#6276)
  • Added information on running complex applications with additional tasks/processes -- :user:Dreamsorcerer. (#6278)

Misc


v3.8.0

Features

  • Added a GunicornWebWorker feature for extending the aiohttp server configuration by allowing the 'wsgi' coroutine to return web.AppRunner object. (#2988)_
  • Switch from http-parser to llhttp (#3561)_
  • Use Brotli instead of brotlipy (#3803)_

... (truncated)

Changelog

Sourced from aiohttp's changelog.

3.8.1 (2021-11-14)

Bugfixes

  • Fix the error in handling the return value of getaddrinfo. getaddrinfo will return an (int, bytes) tuple, if CPython could not handle the address family. It will cause an index out of range error in aiohttp. For example, if user compile CPython with --disable-ipv6 option, but his system enable the ipv6. [#5901](https://github.com/aio-libs/aiohttp/issues/5901) <https://github.com/aio-libs/aiohttp/issues/5901>_
  • Do not install "examples" as a top-level package. [#6189](https://github.com/aio-libs/aiohttp/issues/6189) <https://github.com/aio-libs/aiohttp/issues/6189>_
  • Restored ability to connect IPv6-only host. [#6195](https://github.com/aio-libs/aiohttp/issues/6195) <https://github.com/aio-libs/aiohttp/issues/6195>_
  • Remove Signal from __all__, replace aiohttp.Signal with aiosignal.Signal in docs [#6201](https://github.com/aio-libs/aiohttp/issues/6201) <https://github.com/aio-libs/aiohttp/issues/6201>_
  • Made chunked encoding HTTP header check stricter. [#6305](https://github.com/aio-libs/aiohttp/issues/6305) <https://github.com/aio-libs/aiohttp/issues/6305>_

Improved Documentation

  • update quick starter demo codes. [#6240](https://github.com/aio-libs/aiohttp/issues/6240) <https://github.com/aio-libs/aiohttp/issues/6240>_
  • Added an explanation of how tiny timeouts affect performance to the client reference document. [#6274](https://github.com/aio-libs/aiohttp/issues/6274) <https://github.com/aio-libs/aiohttp/issues/6274>_
  • Add flake8-docstrings to flake8 configuration, enable subset of checks. [#6276](https://github.com/aio-libs/aiohttp/issues/6276) <https://github.com/aio-libs/aiohttp/issues/6276>_
  • Added information on running complex applications with additional tasks/processes -- :user:Dreamsorcerer. [#6278](https://github.com/aio-libs/aiohttp/issues/6278) <https://github.com/aio-libs/aiohttp/issues/6278>_

Misc

  • [#6205](https://github.com/aio-libs/aiohttp/issues/6205) <https://github.com/aio-libs/aiohttp/issues/6205>_

3.8.0 (2021-10-31)

Features

  • Added a GunicornWebWorker feature for extending the aiohttp server configuration by allowing the 'wsgi' coroutine to return web.AppRunner object.

... (truncated)

Commits


Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/CoCongV/sanic-restful/network/alerts).

Bump ipython from 7.12.0 to 7.16.3

opened on 2022-01-21 20:32:16 by dependabot[bot]

Bumps ipython from 7.12.0 to 7.16.3.

Commits


Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/CoCongV/sanic-restful/network/alerts).

Warning! this repo was deprecated, not work any more!

opened on 2021-02-16 06:43:01 by xkungfu None