5 min read Author: klaas

Welcome to PythonOnWheels

The quick and easy generative web framework for python3. Ready to go!

Based on the ruby on rails principles. Generators for models, controllers, views, migrations. Convention over configuration. And PoW gets out of the way if you want it.

Hello World

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

Installation

pip install -U pythononwheels

Everything you need on board. Batteries included.

PythonOnWheels is a generative, Rapid Application Development web framework for python. You need no extra tools to start. Everything from DB to Webserver and template engine is included. But you are not forced to use them and can go raw or easily or include the modules and tools of your choice tools whenever you want.

Based on a very Strong foundation

Oh no, why one more Framework?

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 trick is to offer these tools and features in an easy rails like workflow without much configuration need or boilerplate setup or coding. Makes you focus on your app, logic and visuals and 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 bootsrap4 views and creating a REST API for that.


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

generative approach (but not noisy)

  • generate_app
  • generate_models by script (You probably want to store some data)
  • generate_migrations by script (only needed for SQL DBs)
  • generate_handlers (aka controllers)
  • 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 thats easy. 

The vision

If you want start to develop your web-application and focus on the App, instead of the frameworks, 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