2023-05-04 16:01:23
5 min read
Author: klaas
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.
PythonOnWheels is actually more some added glue between some great existing python libraries than a full blown framework itself. Added glue means to integrate the libraries seamlessly and give you a consistent and fluent workflow.
@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.
pip install -U pythononwheels
The focus is to make your 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.
Establish a super fluent workflow .. (using the generative ideas from ruby on rails)
PythonOnWheels integrates the superb tools, modules and libraries out there in an easy rails like workflow. The goal is to reduce your effort for configuration, boilerplate setup or coding boring and repetetive things.
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.
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:
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"] },
}
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.
@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
# ...
@route("/", dispatch=["get"])
PythonOnWheels will then call the index method of your handler if the route and the HTTP method matches.
@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))
@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)
model.validate() => executes cerberus validator
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.