Rhetoric 0.2.0

Pyramid-like routes for Django projects

Rhetoric

Status: Beta, Unstable API.

Naive implementation of Pyramid-like routes for Django projects.

Why it is worth your while

There's a great article on why Pyramid routing subsystem is so convenient for web developers - Pyramid view configuration: Let me count the ways.

As a person who uses Pyramid as a foundation for his pet-projects, and Django - at work, I (the author) had a good opportunity to compare two different approaches to routing configuration provided by these frameworks. And I totally agree with the key points of the article - Pyramid routes are more flexible and convenient for developers writing RESTful services.

The lack of flexibility of standard Django url dispatcher motivated me to create this project. I hope it will be useful for you, and if you liked the idea behind Rhetoric URL Dispatcher, please consider Pyramid Web Framework for one of your future projects.

Project premises

  • Rhetoric components try to follow corresponding Pyramid components whenever possible.
  • Integration with django applications shall be transparent to existing code whenever possible.
  • Performance of Rhetoric URL Dispatcher is worse than of the one of Pyramid, due to naivety of the implementation and limitations imposed by the compatibility with Django API.

Installation

Rhetoric is available as a PyPI package:

$ pip install Rhetoric

The package shall be compatible with Python2.7, and Python3.3 or higher.

Integration with Django

  1. Replace django.middleware.csrf.CsrfViewMiddleware with rhetoric.middleware.CsrfProtectedViewDispatchMiddleware in your project's MIDDLEWARE_CLASSES:

    # somewhere in a project_name.settings module
    
    MIDDLEWARE_CLASSES = [
        # ...
        'rhetoric.middleware.CsrfProtectedViewDispatchMiddleware',
        #'django.middleware.csrf.CsrfViewMiddleware',
        # ...
    ]
    
  2. Inside the project's root urlconf (usually project_name.urls):

    from django.conf.urls import patterns, include, url
    # ... other imports ...
    from rhetoric import Configurator
    
    # ... various definitions ...
    
    urlpatterns = patterns('',
        # ... a number of standard django url definitions ...
    )
    
    # Rhetorical routing
    # ------------------
    config = Configurator()
    config.add_route('test.new.routes', '/test/new/routes/{param:[a-z]+}')
    config.scan(ignore=[
        # do not scan test modules included into the project tree
        re.compile('^.*[.]?tests[.]?.*$').match,
        # do not scan settings modules
        re.compile('^project_name.settings[_]?[_a-z09]*$').match,
    ])
    urlpatterns.extend(config.django_urls())
    
  3. Register views:

    # project_name.some_app.some_module
    
    from rhetoric import view_config
    
    
    @view_config(route_name="test.new.routes", renderer='json')
    def view_get(request, param):
        return {
            'Hello': param
        }
    
    @view_config(route_name="test.new.routes", renderer='json', request_method='POST')
    def view_post(request, param):
        return {
            'Hello': 'POST'
        }
    
  4. From this point you can request /test/new/routes/<param> with different methods.

Documentation

See complete documentation at http://rhetoric.readthedocs.org/

Changelog

  • 0.2.0
  • 0.1.13
    • Depend on Venusian 1.0 and higher.
    • Allow re-assignment of the same ADT case implementations on subsequent venusian scans.
  • 0.1.9
    • Added support for the request.json_body property.
  • 0.1.8
    • Added support for the request.response API.
  • 0.1.7
    • Added support for the api_version predicate.
    • Added the view_defaults decorator.
  • 0.1.5
    • Feature: added support for decorator argument of view_config.
  • 0.1.4
    • Feature: added support for custom renderers.
  • 0.1.2
    • [Bugfix #2]: resolved race condition in rhetoric.view.ViewCallback.
    • [API]: rhetoric.middleware.UrlResolverMiddleware was renamed to rhetoric.middleware.CsrfProtectedViewDispatchMiddleware.
    • [Django integration]: rhetoric.middleware.CsrfProtectedViewDispatchMiddleware should now completely substitute django.middleware.csrf.CsrfViewMiddleware in MIDDLEWARE_CLASSES.
  • 0.1.0 - initial PyPI release. Early development, unstable API.
MIT

Author

Maxim Avanov

Pip

Rhetoric==0.2.0

Classifiers

  • Topic :: Software Development :: Libraries :: Python Modules
  • Topic :: Software Development :: Libraries :: Application Frameworks
  • Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware
  • Topic :: Internet :: WWW/HTTP :: Dynamic Content
  • Topic :: Internet :: WWW/HTTP
  • Programming Language :: Python :: 3.4
  • Programming Language :: Python :: 3.3
  • Programming Language :: Python :: 2.7
  • Programming Language :: Python
  • Operating System :: POSIX
  • Operating System :: Microsoft
  • Operating System :: MacOS
  • License :: OSI Approved :: MIT License
  • License :: OSI Approved
  • Intended Audience :: Developers
  • Framework :: Django
  • Environment :: Web Environment
  • Development Status :: 4 - Beta
File Type Python Version Uploaded On Downloads
Rhetoric-0.2.0.tar.gz Source Jan. 28, 2015 168
Rhetoric-0.2.0-py3-none-any.whl Wheel 3.4 Jan. 28, 2015 160
Version Release Date
0.2.0 Jan. 28, 2015
0.1.18 Jan. 16, 2015
0.1.17 Oct. 28, 2014
0.1.16 Oct. 27, 2014
0.1.15 Oct. 25, 2014
0.1.14 Oct. 25, 2014
0.1.13 Oct. 20, 2014
0.1.12 April 25, 2014
0.1.11 April 16, 2014
0.1.10 April 12, 2014
0.1.9 March 24, 2014
0.1.8 Jan. 8, 2014
0.1.7 Jan. 8, 2014
0.1.6 Sept. 16, 2013
0.1.5 Sept. 10, 2013
0.1.4 Sept. 9, 2013
0.1.3 Sept. 9, 2013
0.1.2 Sept. 8, 2013
0.1.1 Sept. 6, 2013
0.1.0 Sept. 6, 2013
Date Package Version Action
April 18, 2015, 9:55 p.m. Rhetoric 0.1.7 Release Created
April 18, 2015, 9:55 p.m. Rhetoric 0.1.6 Release Created
April 18, 2015, 9:55 p.m. Rhetoric 0.1.5 Release Created
April 18, 2015, 9:55 p.m. Rhetoric 0.1.4 Release Created
April 18, 2015, 9:55 p.m. Rhetoric 0.1.3 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.2 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.1 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.0 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.2.0 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.9 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.8 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.18 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.15 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.14 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.17 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.16 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.11 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.10 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.13 Release Created
April 18, 2015, 9:54 p.m. Rhetoric 0.1.12 Release Created
April 18, 2015, 9:54 p.m. Rhetoric Package Created