Python Libraries for Startups


Whitenoise handles Gzipping your content and setting far-future cache headers on content. With a trivial amount of work, you can configure your app to automatically append a hash to each of your static files every time you deploy changes, so that you can set the cache headers as so.

A WSGI compliant app literally requires a few lines of code changes to deploy Whitenoise:

from whitenoise import WhiteNoise

from my_project import MyWSGIApp

application = MyWSGIApp()
application = WhiteNoise(application, root='/path/to/static/files')
application.add_files('/path/to/more/static/files', prefix='more-files/')

Why is this important? Using Gzip significantly reduces file sizes / page load for static files. Search engines also detect Gzip compression, penalizing websites that don’t implement it. Being discovered is critical for any early-stage Start-up.

You can find Whitenoise here.

Phonenumbers (lite)

Validating phone numbers is not easy, and there are tons of valid formats that make using regular expressions impossible. Moreover, even if a number passes a regular expression for formatting, it may still not be valid.

Invalid: 222-222-2222 (but it would pass common regular expression tests) Valid: 313-442-1231 ext. 901

Relying solely on a regular expression would mean you reject valid phone numbers and accept invalid ones!

Solution: use python-phonenumbers, a port of Google’s libphonenumber.

This library makes it trivial to validate phone numbers. Using this library ensures that you accept a variety of formats, with various formats / schemes and ensure they are valid.


Pdfkit makes it simple to generate PDFs from html. Why would one use this? Let’s say you have an invoice page in your app – you can use the same code to render that page to render a downloadable PDF for customers or your own records. Here’s how simple it is:

import pdfkit

pdfkit.from_file('test.html', 'out.pdf')

# Generating PDFs from strings and web-pages is equally easy:

pdfkit.from_string('Hello!', 'out.pdf')
pdfkit.from_url('', 'out.pdf')

Another perk of this library is that it is a binding to the extremely resilient and maintained library wkhtmltopdf.

You can find pdfkit here.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s