Skip to main content

Live view for django and templates in pure python

Project description

Why hypergen?

Say bye bye to:

  • frontend

  • javascript

  • mangling making data ready for serialization

  • serialization/deserialization

  • template language

  • webpack/NPM/parcel/gulp/redux/react/etc/etc/etc

And hello to:

  • automatic liveview features

  • composable pure python templates

  • easy dataformat to perform custom frontend actions

  • automatic serialization/deserialization from backend->frontend and frontend->backend

Why not Hypergen?

  • every frontend change on the frontend requires a call to the server

  • python templating is not for everyone. Using Django templates is possible but not as polished yet

Value Proposition

The basic form that makes Hypergen great (for us) is exemplified in this simple counter:

from hypergen.core import *
from hypergen.core import callback as cb
from hypergen.contrib import hypergen_view, hypergen_callback, NO_PERM_REQUIRED

from django.templatetags.static import static

@hypergen_view(perm=NO_PERM_REQUIRED)
def counter(request):
    doctype()
    with html():
        with head():
            script(src=static("hypergen/hypergen.min.js"))
        with body(id_="body"):
            template(1)

@hypergen_callback(perm=NO_PERM_REQUIRED, target_id="body")
def increment(request, n):
    template(n + 1)

def template(n):
    label("Current value: ")
    input_(id_="n", type_="number", value=n)
    button("Increment", id_="increment", onclick=cb(increment, n))

Our journal to Hypergen

The journey leading up to building hypergen has been 15 years of experimenting with all the different methodologies of building websites for advanced business applications. It went something like this:

  • Custom non-frameworky PHP: Totally great cowboy style. Everything is a already a template.

  • Drupal obession: Why am I programming an UI for us programmers to build the site when we could just program the site? Try to think about the problem on your own before following current “best practices”. Use a framework that is actually a framework.

  • Switch to Django. Wow there is actually all the features I need, and great docs too. Ahh python makes sense. Django forms and the request/response cycle is great. Python is not a template language, hmm i guess djangos templates are ok.

  • Frontend level1: We need dynamic features, use the jQuery language to sprinkle behaviour where needed. State management is hard. Disconnect between server and client.

  • Frontend level2: Oh noohs the jQuery is unmanageable. Lets use handlebars templates, a persistent state and render everything on each state change. Rerendering is sluggish for large pages.

  • Frontend level3: Please save us React. State management is finally kind of nice. Everything is a template. Wow building duplicate functionality on the server and the client is annoying. A lot of the code is just about shuffling data between the server and the client. I miss python and all the great stuff in Django.

  • Why can’t I just write my html in python and have frontend events call python functions? Actually I can, enter Hypergen :)

Running the examples

git clone git@github.com:runekaagaard/django-hypergen.git
cd django-hypergen/
virtualenv -p python3.9 venv
source venv/bin/activate
pip install -r requirements.txt
pip install -r examples/requirements.txt
cd examples
python manage.py migrate
python manage.py runserver
# open http://127.0.0.1:8000 in your browser

Developing

Backend

  1. Format all python code with yapf

  2. Run all tests with: pytest –tb=native -x -vvvv test_all.py

Frontend

sudo yarn global add parcel-bundler
# or
sudo npm install -g parcel-bundler
cd hypergen/static/hypergen
parcel watch -o hypergen.min.js -d . hypergen.js

Profiling

rm -f /tmp/hypergen.profile && python -m cProfile -o /tmp/hypergen.profile manage.py runserver 127.0.0.1:8002
echo -e 'sort tottime\nstats' | python3 -m pstats /tmp/hypergen.profile | less
# or
pyprof2calltree -i /tmp/hypergen.profile -k

#
rm -f /tmp/hypergen.profile && python -m cProfile -o /tmp/hypergen.profile manage.py inputs_profile && \
    echo -e 'sort tottime\nstats' | python3 -m pstats /tmp/hypergen.profile | less

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-hypergen-0.9.tar.gz (30.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_hypergen-0.9-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file django-hypergen-0.9.tar.gz.

File metadata

  • Download URL: django-hypergen-0.9.tar.gz
  • Upload date:
  • Size: 30.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for django-hypergen-0.9.tar.gz
Algorithm Hash digest
SHA256 aaaacf890a5afe6fc8164aff5ae45db61398c9dc8522d85a6f9312b41a77fa46
MD5 90348385e3d4ad51fbc74be14d979a24
BLAKE2b-256 8f2be36501049a637d5632bb1b1a1e0ce6effe86af8ad42c050620a2840fe656

See more details on using hashes here.

File details

Details for the file django_hypergen-0.9-py3-none-any.whl.

File metadata

  • Download URL: django_hypergen-0.9-py3-none-any.whl
  • Upload date:
  • Size: 33.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for django_hypergen-0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 47031bd2fb8189e0a08d2d7b492e36bc0ddfbf052babd62ed4d95ce35b17c48f
MD5 5edabd57a42a460f3959c126bb5e8e61
BLAKE2b-256 16d7f8461a924812439542d972cefab0e5c1f0ccd7dee7307d569413fe82859d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page