Develop applications for Pythonista using web tools.
Paper is a library that allows Pythonista users to develop aplications using HTML, CSS and JavaScript.
Initialize the library:
import paper
# Initialize Paper
app = paper.app('./app')
# Expose the function 'hello' to the JS API
@app.expose
def hello():
return 'Oh, hi!'
# Run your app
app.run()
Make your app (inside “app” folder):
<!DOCTYPE html>
<html>
<head>
<title>Paper</title>
<!-- Paper API -->
<script src="./jquery.min.js"></script>
<script src=“./paper.js”></script>
</head>
<body>
<h1>Hello, Paper!</h1>
<button onclick=“sayHello()”>Hello!</button>
<script>
function sayHello() {
response = paper.py.hello();
alert(response);
}
</script>
</body>
</html>
Voilá.
Important:
- Return exceptions to JavaScript instead of crashing the server.
- Garbage collection for Python objects and references.
- Good performance when working with heavy data.
Modules:
- Import Python modules from JavaScript.
-
import x.y
Functions:
- Convert Python built-in functions to JavaScript functions.
- Call Python function with
kwargs
.
- Call Python function with
- Convert a JavaScript function to a Python function.
Types:
- Create JavaScript references of Python objects.
- Convert basic Python types to JavaScript equivalents (
int
,float
,string
,complex
,list
,dict
andtuple
). - Convert basic JavaScript types to Python equivalents (
int
,float
,string
,array
andobject
). - Create JavaScript objects from Python objects.
- Create Python objects from JavaScript objects.
Classes:
- Create Python class instances using JavaScript.
- Convert Python class instances to JavaScript objects.
- Create Python classes using JavaScript.
- Expand Python classes using JavaScript.
Suggestions, as well as pull requests and bug reports are welcome.
MIT