A Python binding for the web monetization Javascript API

Kelvin Wangonya - May 9 '20 - - Dev Community

For this hackathon, I'm thinking of building a python binding for the web monetization API. Here's what I have in mind:

According to the docs, if you want to check if a user is web monetized, you check the state using:

document.monetization.state
Enter fullscreen mode Exit fullscreen mode

You would then proceed to implement your logic based on the state.

As a backend python developer, it would be cool if I could do that in python. If I'm using Flask for example, and I have a monetized route, I would want to write something like:

from monetize import check_state

@app.route('/monetized')
def monetized_page():
    state = check_state()
    if state == 'started':
        # implement logic to offer monetized content
    else:
        # do something else
Enter fullscreen mode Exit fullscreen mode

This is a simple example but that's the general idea - to have all the methods exposed by the js API in python. Javascript would of course still be working behind the scenes once this gets to the browser.

I believe something like this would make it easier to implement the monetization API for python developers working with web frameworks like flask and django.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player