python microframeworks





A fast, simple and beginner-friendly

overview.



HI, I'm PAUL FINN


Was an enterprise .NET developer for a while

Mostly self-taught in web development

Switched from PHP -> Python, never looked back

I'm now a Web Developer at Saltwater Creative

WHY PYTHON?



High-Level, Beginner Friendly

Extremely Popular

Supportive Ecosystem

Emphasis on testing, documentation
and good coding practices












PYTHON WEB FRAMEWORKS


You've probably heard of 

- Admin backend
- User accounts/logins
- Object Relational Mapper (ORM)
- Cache System
- Syndatication System
- Internationaliztion



It's awesome. 

You should learn it: djangoproject.com

Some of the best documentation you'll find for an open source project.

WhAT'S A MICROFRAMEWORK?





MICROFRAMEWORKS


For handling HTTP requests
...and responses.

Maybe sessions.

Simple templating.

Not much else.



WHAT ARE WE LOOKING FOR?


Easy to understand
(documentation, minimal magic)

Easy to work with HTTP Request/Response
(GET? POST? Referrer? Cookies?)

URL Patterns/Routing ("REST-ful")

Static assets, deployment, etc.

MOST IMPORTANTLY...



Leaving most of the decisions up to you.

Pick-your-own database engine, templating engine, cookie management, sessions and authentication,
etc.

Very extendable. 

START SMALL




Bottle is a fast, simple and lightweight micro web-framework for Python. It is distributed as a single file and has no dependencies.


from bottle import route, run

@route('/hello')
def hello():
    return "Hello World!"

run(host='localhost', port=8080, debug=True)

@route('/')
@route('/hello/<name>')
def greet(name='Stranger'):
    return template('Hello {{name}}, how are you?', name=name)



from bottle import get, post, request

@get('/login') 
def login_form():
    return '''<form method="POST" action="/login">
                <input name="name"     type="text" />
                <input name="password" type="password" />
                <input type="submit" />
              </form>'''

@post('/login') 
def login_submit():
    name     = request.forms.get('name')
    password = request.forms.get('password')
    if check_login(name, password):
        return "<p>Your login was correct</p>"
    else:
        return "<p>Login failed</p>"

Flask



DJANGO

|
|
|
|
|

Flask

|
|
|

Bottle

WHAT'S SO GREAT ABOUT FLASK


Well-documented and extremely popular

Better, faster template engine

SQLAlchemy plugin for ORM

More features, better debugger

Flaskr - Tutorial on github

MY PREFERRED STACK


Python & Flask
(with SQLAlchemy, usually)

Deployed on Heroku

Amazon S3 & SimpleDB For Storing Objects/Files

Mailgun (for handling email)


DEPLOYING TO HEROKU


Getting Started With Python on Heroku
(Tutorial with Flask)



FLASK & API's == WIN 


Jumping to conclusions...


Python is fun, give it a shot!

Quickly make cool stuff on the web
with Bottle or Flask

Deploy right to Heroku
(or your Apache/nginx server)

Flask can scale!
(Read up on Flask Blueprints)



Thank You!





python microframeworks

By paulfinn

python microframeworks

  • 919