Skip to main content

Assortment of various utilities for Flask applications

Project description

FlaskWarts are a set of utility classes and functions for making it easier to overcome some of the warts that one always seem to encounter when developing Flask applications. It’s called ‘warts’ because ‘utils’ was taken. The main package is still called utils, because that’s what it was called in a few apps author was using the code in, and was too lazy to refactor them all.

Overview

The library is not too generic. In fact, it’s quite opinionated. It’s made available as is if you care to use it, but it’s mainly there for the author’s use cases.

While not an immediate goal, it is author’s intention to make this a fully-comliant Flask extension at some point, and far more flexible. It may be brokend down into multiple separate libraries as well. Currently, it is a multi-purpose library that expects you to organize your site as a single application and uses flask.current_app extensively. While this is not a good pattern in general, it’s a pattern that works (for the time being).

It also expects that you place your configuration in app.config.

Note that not all code is fully developed and tested. Some of the code even misses unit tests, and documentation doesn’t exist. So this is pretty much pre-alpha software. Also, don’t expect anything in the way of API stability in any form.

Features

The utils have following features:

  • Class-based route handlers (utils.routes)

  • Form-handling with Formencode (utils.forms)

  • CSRF middleware (utils.middlewares)

  • Basic timezone manipulation support (utils.timezone)

  • One decorator for denying non-XHR requests (utils.decorators)

Installation

Either:

easy_install FlaskWarts

Or:

pip install FlaskWarts

Class-based route handling

Please see the sources for now. More detailed docs are planned for future releases. It’s similar to Django’s CBVs but not quite the same.

Form-handling with Formencode

Allows basic form validation using Formencode’s htmlfill_schemabuilder. Docs on the way, so stay tuned.

CSRF middleware

A bit rough at the moment, but works. Uses os.urandom for random number generation, you’ve been warned. It also makes Jinja2 a requirement.

Basic usage is simply:

from utils.middlewares import csrf
csrf(app)

In template:

<form method="POST">
    {{ csrf_tag }}
    ...
</form>

Docs? Who said anything about docs? :D

Timezone manipulation

Requires pytz. Again, no docs yet, so please look at the module.

Decorators

To prevent non-XHR requests to your endpoint, just do this:

from utils.decorators import xhr_only

@app.route('/')
@xhr_only
def my_view():
    pass

It will abort a non-XHR request with HTTP 400 status.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

FlaskWarts-0.1a3.zip (12.5 kB view details)

Uploaded Source

FlaskWarts-0.1a3.tar.gz (8.7 kB view details)

Uploaded Source

File details

Details for the file FlaskWarts-0.1a3.zip.

File metadata

  • Download URL: FlaskWarts-0.1a3.zip
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for FlaskWarts-0.1a3.zip
Algorithm Hash digest
SHA256 b057e7a2e38989b4a3fca075397d6a6f4580a6318e3f0e7dbc8fca4540b1b279
MD5 fb9ba1747bc16888e402f51bd443b01a
BLAKE2b-256 56cb4ee9cec0fba9e564644ff84aab1e94a8fb6195073e64873d82020d956d8c

See more details on using hashes here.

File details

Details for the file FlaskWarts-0.1a3.tar.gz.

File metadata

  • Download URL: FlaskWarts-0.1a3.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for FlaskWarts-0.1a3.tar.gz
Algorithm Hash digest
SHA256 0ee9963fbc382ba4ee9d5220980aeeba16ac9b01cf1c4eea2dddb64851db1b77
MD5 91b62a822332ff693f7209e3f82dba94
BLAKE2b-256 74aad0d37275892c9639d297fe1bf217b86d9473f7adb9fce7f6e6658bd917d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page