Skip to main content

Perry

Perry <= A framework that let’s you compose websites in Python with ease!

Perry works similar to Qt and Flutter, allowing you to create component collections. Say you want to create a div with some text and an image. To do that you’d first need to create the page:

.. code:: python

from Perry import component, pageView, serve, Composite

Let’s break it down: - Component - A given element that can be added anywhere on the page - pageView - Creates a page with a route for us, we can load styles, JS and other things into it by using the ‘styles’ argument - Serve - A Flask based micro-server for Perry - Composite - The most important part! This tells our components to build themselves recursively as well as creating the skeleton, route and debugging info.

Now let’s create the page

.. code:: python

Homepage = component(pageView, _Inherit = True)

a pageView is also a component, but inherits different functionality

Assign page contents

Homepage <= { 'title': 'Home', # Title of the page 'path':'', # Route on the webserver, no need to include the starting / 'styles': [bootstrap], # Styles and other components, here we load bootstrap which is included in Extras 'DOM': pageView.DOM, # DOM, not yet implemented but worth using in case you want to upgrade to a newer verion of Perry later 'components': HomepageContents # A ComponentSource with our elements }

This page will just show up as an error as we haven’t yet created our component source! This can be done through importing ComponentSource

.. code:: python

HomepageContents = ComponentSource( DIV( Label('Hello World!', 'h1'), Card( Image('Image URL'), CardText('Sample Text which has attributes for bootstrap cards', 'p')
), Label('Good bye!', 'h1') ) )

You’ll get something like this. The trailing comment is used for debugging

.. code:: html

Hello World!

Sample Text which has attributes for bootstrap cards

Good bye!

Running on Perry v0.9 with Debug Mode on!

Custom Element Bundles and Styling

Want to bundle together multiple elements and create a universal one? That’s easy to do!

.. code:: python

OurCoolNewElement = DIV( Label('Hello, I have custom stuff!', 'h1', id = 'CoolTitle'), cclass = 'NewElement' )

Let's give it some style

ourCustomStyle = style() ourCustomStyle <= { 'author':'HUSKI3', 'source':'Local-made ;)' 'ctype':'css', 'css' : ''' .NewElement { color: white; background: black; } '''}

And now add it to the components

HomepageContents = ComponentSource( DIV( Label('Hello World!', 'h1'), OurCoolNewElement , # <--- here Label('Good bye!', 'h1') ) )

You’ll need to load the style when defining the homepage contents!

.. code:: python

Homepage <= { ..., 'styles': [some, styles, ourCustomStyle], ... }

Adding JS Support

At the moment JS doesn’t have direct support through built in components, but you can use JQueryEngine and JQueryEngineStrapper from Extras.

.. code:: python

First we create the component with JQuery, give it a pageView to wrap around (WIP)

js = JQueryEngine(pageView, cid = 'coolscript')

Now you load in the script, it can either be a string or a read from file

js <= ( open('PerryApp/coolscript.js','r').read() )

To load it in, you need to add JQueryEngineStrapper to the styles of the page and add the js component to the components

HomepageContents.add( js )

Serving pages with Flask

In Perry you always serve pages as a Composite collection, this way they are built and then loaded on Flask on the specified routes.

.. code:: python

Serve our pages as a composite collection

serve <= Composite(Homepage, About, OtherPage, debug = True)

Serving pages with FastAPI

.. code:: python

from fastapi import FastAPI, Response

app = FastAPI() pages = Composite(Homepage, About, OtherPage, debug = True)

You can check all page info by printing the Composite component

print(pages)

You can also get page info by querying it's route,

NOTE: The routes do not contain the initial '/'

print(pages.get(''))

@app.get("/") def read_root(): return Response(content=pages.get('').run(), media_type="text/html")

Metadata

Release files for Perry 0.1.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for Perry 0.1.13
File Interpreter ABI Platform Actions
Perry-0.1.13-py3.10.egg Legacy Egg format - - Details for Perry-0.1.13-py3.10.egg

Release files / Perry-0.1.13-py3.10.egg

Download URL Perry-0.1.13-py3.10.egg
Size 32.9 kB
Tags Egg
SHA-256 checksum
How to use checksums
6d2d652a37cd45408d69e0603051be8115133bfda1e5a7fc812f169ba7de7f4b
BLAKE2b-256 checksum
How to use checksums
4d865f4f301093045c2506eecdc2b3a222f75ebaa3335e1141cf2e7dfccdaeb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/4.13.0 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

Security for Perry 0.1.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page