Skip to main content

Raptorize WSGI Middleware

Fact: every WSGI app is better with a velociraptor.

https://github.com/ralphbean/raptorizemw/raw/master/raptorizemw/resources/raptor.png

Installation

You could install it yourself with pip:

$ pip install raptorizemw

Or you could add raptorizemw to the list of required packages in the setup.py file of your project.

Usage in Pyramid

Edit myapp/__init__.py and replace the return config.make_wsgi_app() line with the following:

import raptorizemw
app = config.make_wsgi_app()
app = raptorizemw.make_middleware(app)
return app

Restart your app, but watch out for raptors!

Usage in Flask

Edit yourapp.py and replace the app.run() line with the following:

import raptorizemw
app.wsgi_app = raptorizemw.make_middleware(app.wsgi_app)
app.run()

ZOMG!

Usage in TurboGears 2

Simply edit myapp/config/middleware.py and add the following to make_app(...):

# Wrap your base TurboGears 2 application with custom middleware here
import raptorizemw
app = raptorizemw.make_middleware(app)

Usage in a PasteDeploy pipeline

You can also add raptors into your PasteDeploy pipeline like so:

[pipeline:main]
pipeline =
    raptorize
    my-app

[filter:raptorize]
use = egg:raptorizemw
enterOn = konami-code
delayTime = 3000
random_chance = 0.25
only_on_april_1st = True

[app:myapp]
...

Essentially, you’re able to specify raportizemw as a filter within your WSGI pipeline, and configure options accordingly as per the Configuration section below.

Configuration

make_middleware(...) and RaptorizeMiddleware.__init__(...) both take a number of configuration keywords:

  • enterOn can be one of two actions: ‘timer’ or ‘konami-code’. If ‘timer’ is specified, then the raptor is shown on page load. If ‘konami-code’, then the raptor is shown if the page-viewing user enters the sacred sequence. Default is ‘timer’.

  • delayTime must be an int and is the number of milliseconds until the raptor is shown. Default is 2000.

  • random_chance must be a float between 0.0 and 1.0 representing a ‘percent chance’ to load the raptor. A value of 1.0 means the raptor will be injected every time; a value of 0.0 means it will never be injected; a value of 0.5 will result in a 50% chance of raptors. Default is 1.0.

  • only_on_april_1st should be a bool value that will restrict raptors only to April Fool’s day. The configuration will coerce Boolean-like strings (such as t, true, y, yes, on and 1) into a suitable format if provided in this manner (such as through a text-based pipeline configuration). Default is False.

For example:

app = raptorizemw.make_middleware(
    app,
    enterOn='konami-code',
    delayTime=500,
    random_chance=0.5,
    only_on_april_1st=True
)

will result in 50% of pages loaded with raptors on April Fool’s Day only. These raptors will only be displayed if the user also enters the konami code, and quite quickly, after only a half a second.

Credits

This WSGI-fication of the raptorize jquery plugin was written by Ralph Bean. Real credit goes to the people over at ZURB who authored the original jquery plugin.

Get the source

The code and bug tracker live over at http://github.com/ralphbean/raptorizemw. Please fork and improve!

Release files for raptorizemw 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for raptorizemw 0.2.1
File Size Uploaded
raptorizemw-0.2.1.tar.gz 2.4 MB Details

Release files / raptorizemw-0.2.1.tar.gz

Download URL raptorizemw-0.2.1.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
61a41514f541c95d82e4ea209fac7da8446ab0f163097598639d9c856f9a5b65
BLAKE2b-256 checksum
How to use checksums
dddb2f19e912e2f4d98ce9893f702a55a46b2bcd018ba954162394d775c9470d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page