5 min read Author: klaas

Just do your thing!

A python web framework, build on the Ruby on Rails principles.

Generators for models, controllers, scaffolding views and database migrations. Validation, convention over configuration..and much more. Focus on your thing instead of the boilerplate.

Hello World

@app.make_routes()  
class HelloHandler(BaseHandler):
@route('/hello', dispatch=["get"])
def hello(self):
self.write("Hello world!")

This will route a HTTP(S)/GET request to  the URL: /hello and call the HelloHandler.hello() method.

Pretty easy, but the main thing is not to make the best "Hello World" but the best development workflow! This is what PythonOnWheels is all about.

Installation

pip install -U pythononwheels

Everything you need on board. Batteries included.

Oh no, why one more Framework?

PythonOnWheels is a layer of glue around some great existing libraries/modules and tools to make your python life easier for the boring tasks. 

The idea of PythonOnWheels is to include and offer the features and tools that most of the people implementing smaller to medium sized projects probably want. Therefore it includes a little more than the microFrameworks and a little less then the big enterprise frameworks out there. 

The focus is on the workflow

PythonOnWheels offers these tools and features in an easy rails like workflow without much need for configuration, boilerplate setup or coding. 

Makes you focus on your app and your idea. Not on the application infrastructure.

To get an impression of the workflow check the 10 Minutes intro video creating a small todo app using a NoSQL DB, scaffolding bootstrap 4 views and creating a REST API.


All the helpers below are there but PythonOnWheels also gets out of the way if you want it. You can always use the underlying modules raw.

Probably the most simple SQL relations out there!

Based on sqlalchemy.

With PythonOnWheels you simply add a class decorator like 

@relation.has_many("comments")
class Post(Base):
# All your Post model code below here ..
.....

to your SQL Post-model and every Post can have comments. It will be automatically mapped to the DB (SQLite, Postgres, MySQL, MariaDb, Oracle, MSSQL ...) and to all related comment Models. DB Migrations are created automatically in the background.

supported relation types are:

  • has_many()
  • has_many_and_belongs_to()
  • many_to_many()
  • one_to_one()
  • tree()

All pow models (SQL or NoSQL) use a cerberus schema as definition.

This means you have validation on board for every model and you can easily switch from SQL to NoSQL

This is how a model schema looks like.

schema = { 
# string sqltypes can be TEXT or UNICODE or nothing
'author': {'type': 'string', 'maxlength' : 35 },
'title' : {'type': 'string', "required" : True },
'text' : {'type': 'string' },
'votes' : {'type': 'integer' },
'status': {'type': 'string', "allowed" : ["backlog", "wip", "done"] },
}

Probably the most simple REST routing out there. One decorator. Done!

With PythonOnWheels you simply add a class decorator like 

@app.add_rest_routes("basename")

to your handler and you get all the typical REST routes mapped to the according CRUD methods of your handler class.

By the way: this is what generate_handler generates for you when you use the --rest parameter:

@app.add_rest_routes("rest_test")
class RestTest(BaseHandler):
#
# every pow handler automatically gets these RESTful routes
# when you add the : app.add_rest_routes() decorator.
#
# 1 GET /todo #=> list
# 2 GET /todo/<uuid:identifier> #=> show
# 3 GET /todo/new #=> new
# 4 GET /todo/<uuid:identifier>/edit #=> edit
# 5 GET /todo/page/<uuid:identifier> #=> page
# 6 GET /todo/search #=> search
# 7 PUT /todo/<uuid:identifier> #=> update
# 8 PUT /todo #=> update (You have to send the id as json payload)
# 9 POST /todo #=> create
# 10 DELETE /todo/<uuid:identifier> #=> destroy
# ...

Routing: RegEx and Flask like routes included.

You can set routes by simply adding a class decorator to the handler class or decorate methods directly.

@route("/", dispatch=["get"])

PythonOnWheels will then call the index method of your handler if the route and the HTTP method matches.

Example for Flask like routing

@app.make_method_routes()
class HelloHandler(BaseHandler):
@route(r'/hello/<int:identifier>', dispatch=["get"])
def hello(self, identifier=None):
self.write("Hello world! " + str(identifier))

For Regex routes use

@app.add_route("/test/([0-9]+)*", dispatch={"get" : "test"}) 

to add a direct route: matching the regular expression : /test/([0-9+]) and then calling the given method of your handler class. The regex group ([0-9+]) will be handed as the first parameter to test(self, index)

And finally, a super easy workflow.

Quick to start and all the basics on board

  • generate_app (generates the whole app foundation fo you)
  • generate_model (You probably want to store some data)
  • generate_handlers (all the logic goes here)
  • start the server (python server.py) 
  • done!

Model Validation on board with cerberus schemas. 

All Model Schemas are Cerberus schemas automatically.

    model.validate() => executes cerberus validator

So that's easy. 

The vision

If you want start to develop your web-application and focus on the App, instead of the infrastructure, you are in the right place. PythonOnWheels feels right if you do not recognize that you use it.

Enjoy! 

Check the getting started or go to the documentation