Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toastdriven/restless
A lightweight REST miniframework for Python.
https://github.com/toastdriven/restless
django flask hacktoberfest hacktoberfest2021 python restful-api
Last synced: 3 days ago
JSON representation
A lightweight REST miniframework for Python.
- Host: GitHub
- URL: https://github.com/toastdriven/restless
- Owner: toastdriven
- License: bsd-3-clause
- Created: 2014-01-13T02:54:50.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-05-08T12:41:03.000Z (6 months ago)
- Last Synced: 2024-05-22T15:10:18.507Z (6 months ago)
- Topics: django, flask, hacktoberfest, hacktoberfest2021, python, restful-api
- Language: Python
- Homepage: http://restless.readthedocs.org/en/latest/
- Size: 256 KB
- Stars: 829
- Watchers: 26
- Forks: 104
- Open Issues: 32
-
Metadata Files:
- Readme: README.rst
- Contributing: docs/contributing.rst
- License: LICENSE
- Security: docs/security.rst
- Authors: AUTHORS
Awesome Lists containing this project
- starred-awesome - restless - A lightweight REST miniframework for Python. (Python)
README
========
restless
========.. image:: https://travis-ci.org/toastdriven/restless.svg?branch=master
:target: https://travis-ci.org/toastdriven/restless.. image:: https://coveralls.io/repos/github/toastdriven/restless/badge.svg?branch=master
:target: https://coveralls.io/github/toastdriven/restless?branch=masterA lightweight REST miniframework for Python.
Documentation is at https://restless.readthedocs.io/.
Works great with Django_, Flask_, Pyramid_, Tornado_ & Itty_, but should be useful for
many other Python web frameworks. Based on the lessons learned from Tastypie_
& other REST libraries... _Django: https://www.djangoproject.com/
.. _Flask: http://flask.pocoo.org/
.. _Pyramid: https://pylonsproject.org/
.. _Itty: https://pypi.org/project/itty/
.. _Tastypie: http://tastypieapi.org/
.. _Tornado: https://www.tornadoweb.org/
.. _tox: https://tox.readthedocs.io/Features
========* Small, fast codebase
* JSON output by default, but overridable
* RESTful
* Python 3.6+
* Django 2.2+
* FlexibleAnti-Features
=============(Things that will never be added...)
* Automatic ORM integration
* Authorization (per-object or not)
* Extensive filtering options
* XML output (though you can implement your own)
* Metaclasses
* Mixins
* HATEOASWhy?
====Quite simply, I care about creating flexible & RESTFul APIs. In building
Tastypie, I tried to create something extremely complete & comprehensive.
The result was writing a lot of hook methods (for easy extensibility) & a lot
of (perceived) bloat, as I tried to accommodate for everything people might
want/need in a flexible/overridable manner.But in reality, all I really ever personally want are the RESTful verbs, JSON
serialization & the ability of override behavior.This one is written for me, but maybe it's useful to you.
Manifesto
=========Rather than try to build something that automatically does the typically
correct thing within each of the views, it's up to you to implement the bodies
of various HTTP methods.Example code:
.. code:: python
# posts/api.py
from django.contrib.auth.models import Userfrom restless.dj import DjangoResource
from restless.preparers import FieldsPreparerfrom posts.models import Post
class PostResource(DjangoResource):
# Controls what data is included in the serialized output.
preparer = FieldsPreparer(fields={
'id': 'id',
'title': 'title',
'author': 'user.username',
'body': 'content',
'posted_on': 'posted_on',
})# GET /
def list(self):
return Post.objects.all()# GET /pk/
def detail(self, pk):
return Post.objects.get(id=pk)# POST /
def create(self):
return Post.objects.create(
title=self.data['title'],
user=User.objects.get(username=self.data['author']),
content=self.data['body']
)# PUT /pk/
def update(self, pk):
try:
post = Post.objects.get(id=pk)
except Post.DoesNotExist:
post = Post()post.title = self.data['title']
post.user = User.objects.get(username=self.data['author'])
post.content = self.data['body']
post.save()
return post# DELETE /pk/
def delete(self, pk):
Post.objects.get(id=pk).delete()Hooking it up:
.. code:: python
# api/urls.py
from django.conf.urls.default import url, includefrom posts.api import PostResource
urlpatterns = [
# The usual suspects, then...url(r'^api/posts/', include(PostResource.urls())),
]Licence
=======BSD
Running the Tests
=================The test suite uses tox_ for simultaneous support of multiple versions of both
Python and Django. The current versions of Python supported are:* CPython 3.6
* CPython 3.7
* CPython 3.8
* CPython 3.9
* PyPyYou just need to install the Python interpreters above and the `tox` package
(available via `pip`), then run the `tox` command.