• Stars
    star
    831
  • Rank 54,863 (Top 2 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created almost 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight REST miniframework for Python.

restless

https://travis-ci.org/toastdriven/restless.svg?branch=master https://coveralls.io/repos/github/toastdriven/restless/badge.svg?branch=master

A 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.

Features

  • Small, fast codebase
  • JSON output by default, but overridable
  • RESTful
  • Python 3.6+
  • Django 2.2+
  • Flexible

Anti-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
  • HATEOAS

Why?

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:

# posts/api.py
from django.contrib.auth.models import User

from restless.dj import DjangoResource
from restless.preparers import FieldsPreparer

from 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:

# api/urls.py
from django.conf.urls.default import url, include

from 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
  • PyPy

You just need to install the Python interpreters above and the tox package (available via pip), then run the tox command.

More Repositories

1

itty

The itty-bitty Python web framework.
Python
409
star
2

shell

A better way to run shell commands in Python.
Python
161
star
3

littleworkers

Little process-based workers to do your bidding.
Python
149
star
4

guide-to-testing-in-django

The example project for adding tests.
Python
146
star
5

microsearch

A small search library.
Python
108
star
6

pylev

A pure Python Levenshtein implementation that's not freaking GPL'd.
Python
97
star
7

django-budget

A personal budgeting application for use with Django.
JavaScript
48
star
8

multiresponse

A Python class for Django that allows a request to provide content-type aware responses.
Python
45
star
9

friendlydb

A small & fast following/followers database written in Python.
Python
41
star
10

lua-base64

Another base64 implementation.
Lua
35
star
11

quads

A pure Python Quadtree implementation
Python
31
star
12

django-rsvp

A simple RSVP app.
Python
31
star
13

wsgi_longpolling

Supporting materials for my blog post on WSGI long-polling apps with gevent.
Python
30
star
14

toastbot

A clean, extensible IRC bot using Python & gevent.
Python
30
star
15

definite

Simple finite state machines.
Python
28
star
16

alligator

Simple offline task queues. For Python.
Python
27
star
17

bitty

A tiny storage layer. (v0.4) Serious Python Programmersβ„’ with Enterprise Requirements need not apply.
Python
26
star
18

pyskip

A pure Python skiplist implementation. For fun.
Python
23
star
19

feedme

A better (for me) RSS aggregator. Collects numerous RSS feeds and displays entries in chronological order. Similar to the "planet" concept.
Ruby
20
star
20

django-superflatpages

A capable, database-backed flatpages implementation.
Python
19
star
21

rose

A small library for keeping your version up-to-date easily & everywhere.
Python
19
star
22

deployable

A simple system for repeatable deploys. Language-agnostic, easy to use yet extensible, and above all, repeatable.
Python
18
star
23

piecrust

DEAD PROJECT - A REST layer for all Python applications
Python
16
star
24

sockless

A friendlier interface to `socket`.
Python
14
star
25

migrate_doctest_to_unittest

"In Django-land, unittests are much faster than doctests. Convert them."
Python
14
star
26

nanosearch

A tiny search engine.
JavaScript
13
star
27

boto3

**EXPERIMENTAL** Evolution of boto. Supports Py2/3.
Python
10
star
28

itty3

The itty-bitty Python web framework... **Now Rewritten For Python 3!**
Python
10
star
29

django-microapi

A tiny library to make writing CBV-based APIs easier in Django.
Python
8
star
30

todone

Todo lists done my way.
8
star
31

chrono

A (BSD licensed) context manager for timing execution.
Python
8
star
32

steamstalker

A Django pluggable app for stalking your Steam friends' activity.
JavaScript
8
star
33

pubsubittyhub

PubSubHubbub via webhooks. Mostly a port of watercoolr.
Python
8
star
34

dashbot

A node.js-powered IRC bot for the Django Dash.
JavaScript
7
star
35

colloquy_to_textual

Converts logs from Colloquy (XML) to Textual (plain text)
Python
6
star
36

dotfiles

Mah dotfiles + installer.
Shell
6
star
37

mathpractice

Math practice (for the kiddos)
Python
5
star
38

solidrocket

A fun little experimental datastore. Not interesting yet.
Lua
5
star
39

whisper

A toy micro-blog built on Node.js & Postgres.
JavaScript
5
star
40

localtable

A thin database-like wrapper over `window.localStorage`.
JavaScript
4
star
41

domicile

Programmatic creation of DOM elements. Vaguely similar to React's DOM bits.
JavaScript
4
star
42

euler

Project Euler (projecteuler.net) problems
Python
3
star
43

markov

A simple Markov chain generator done purely for fun.
Python
3
star
44

edgy

More NIH
3
star
45

filtering

Probably not useful to you.
Python
2
star
46

lilrocket

A Solr-alike for Whoosh.
Python
2
star
47

django-dashboard

Python
2
star
48

LAAS

It's Levenshtein-As-A-Service. You know, for the lulz.
Python
2
star
49

sciencemuseum

Nat + Simon's entry for the Science Museum's API competition
Python
2
star
50

goplayground

Experiments with Go.
Go
2
star
51

createproject

For creating new Python packages.
Python
2
star
52

django-dash

The code that powers the Django Dash.
Python
2
star
53

carrierpigeon

Contract-based messages.
Python
1
star
54

eliteracing

The source for the Elite Racing Federation website (edracers.com)
Python
1
star
55

GIS-Day

Hosted at KU
1
star
56

electronicinmyears

The Electronic In My Ears (Recommendations)
1
star
57

mistertest

You don't care about this.
Python
1
star
58

the-march-to-3

Python
1
star
59

bobbyblog

Python
1
star