Skip to content

hgrubbs/python_rpcfu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RPCfu - what is it?

RPCfu is a project to create a very lightweight Python 3x WSGI framework. It receives inputs via query-string field values and/or a single query-string field value containing a JSON.

Why not Django? Flask? Another WSGI framework?

Most popular WSGI frameworks obfuscate how a WSGI transaction takes place. They add in ORM's, complex URL routing rules, mandatory decorators, and other such black magic the programmer is asked to take on good faith. RPCfu does none of these things. Request processing and routing happens in one small file:, rcpfu_main.py. The entire process - from the web request arriving to the result being sent back - can be observed without following hundreds of lines of boilerplate code included in large frameworks. In short, by working directly with and understanding this process: you will become a better programmer.

Quick start

Diving in is easy. Within controllers/tests.py, there are a few simple functions defined, and we're going to test them out. Their definitions are:

  • greeter(**request)
  • personalized_greeter(name, **request)

To begin, run rpcfu_main.py, then visit the URL http://localhost:8080/tests/greeter to see the output of a simple call that takes no inputs.

You should receive this response from your browser:

{"greeting": "Hello world!"}

Now let's try a call that takes an input. With rpcfu_main.py running, visit the URL http://localhost:8080/tests/personalized_greeter?name=Developer.

You should receive this response from your browser:

{"greeting": "Hello Developer!"}

Simple enough? Notice how both calls have access to the **request dictionary, which contains the WSGI environ. Every call you write should declare **request as the last argument. This can be handy to get the client IP, or access multi-part fields sent along with a POST. The personalized_greeter()'s argument name should be self-explanatory as well. Positional arguments like name can be added as you see fit, just make sure **request is last in your function definition.

Built-in debug server

When invoked from the command line, rpcfu_main.py creates a single threaded debug server that listens on port 8080 by default. This should not be used for production, but is handy for debugging. You can use the pdb or pudb python debugging module(and any others you may prefer) to create breakpoints within your application, allowing you to debug in real time from the command line. The debug server is only created when invoked from the command line, and will not exist if called via WSGI.

URL Mapping

URL mapping is accomplished in the list url_map, at the top of rpcfu_main.py. This is what routes /tests/greeter to the file tests.py's function named greeter(**request). The dictionary url_map contains the regexp patterns to match URLs, which use the standard regular expression syntax. These may be familiar if you are used to writing urls.py files for Django.

About

Web RPC framework written in Python 3.x

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages