A framework that let's you compose websites in Python with ease!

Related tags

Miscellaneous Perry
Overview

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:

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

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

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

Hello World!

Sample Text which has attributes for bootstrap cards

Good bye!

Running on Perry v0.9 with Debug Mode on!

">
<body>
     
   <div id="" class="">
      <h1 id=""> Hello World! h1>
       
      <div style="width: 18rem;" id="" class="card, ">
         <div class="card-body">
            <img src="Image URL" id="style=''">
             
            <p id="class='card-text'"> Sample Text which has attributes for bootstrap cards p>
             
         div>
      div>
       
      <h1 id=""> Good bye! h1>
       
   div>  <p id=""> Running on Perry v0.9 with Debug Mode on! p>   body>

Custom Element Bundles and Styling

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

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!

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.

# 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.

# Serve our pages as a composite collection
serve <= Composite(Homepage, About, OtherPage, debug = True)
You might also like...
A one place destination to check whatever is trending on the top social and news websites at present.
A one place destination to check whatever is trending on the top social and news websites at present.

UpTrend A one place destination to check whatever is trending on the top social and news websites at present. Explore the docs » View Demo · Report Bu

A light library to build tiny websites
A light library to build tiny websites

A light library to build tiny websites

This is a vscode extension with a Virtual Assistant that you can play with when you are bored or you need help..

VS Code Virtual Assistant This is a vscode extension with a Virtual Assistant that you can play with when you are bored or you need help. Its currentl

You can easily send campaigns, e-marketing have actually account using cash will thank you for using our tools, and you can support our Vodafone Cash +201090788026

*** Welcome User Sorry I Mean Hello Brother ✓ Devolper and Design : Mokhtar Abdelkreem ========================================== You Can Follow Us O

Minos-python - A framework which helps you create reactive microservices in Python

minos-python Summary [TODO] Packages minos-microservice-aggregate minos-microser

OnTime is a small python that you set a time and on that time, app will send you notification and also play an alarm.

OnTime Always be OnTime! What is OnTime? OnTime is a small python that you set a time and on that time, app will send you notification and also play a

switching computer? changing your setup? You need to automate the download of your current setup? This is the right tool for you :incoming_envelope:

🔮 setup_shift(SS.py) switching computer? changing your setup? You need to automate the download of your current setup? This is the right tool for you

A plugin for poetry that allows you to execute scripts defined in your pyproject.toml, just like you can in npm or pipenv

poetry-exec-plugin A plugin for poetry that allows you to execute scripts defined in your pyproject.toml, just like you can in npm or pipenv Installat

Do you need a screensaver for CircuitPython? Of course you do

circuitpython_screensaver Do you need a screensaver for CircuitPython? Of course you do Demo video of dvdlogo screensaver: screensaver_dvdlogo.mp4 Dem

Comments
  • Support for other web frameworks

    Support for other web frameworks

    Hey, I love the concept and implementation of this package, but I'm not fond of Flask. Would it be possible to remove flask as a dependency and instead abstract out the routing system so it can be plugged into any framework? Specifically I'd love to use this with FastAPI.

    opened by tclasen 6
Owner
Linkus
Back-end Dev. Forma is the best. Check out @RocKing1001 for his cool projects!
Linkus
An extension for Arma 3 that lets you write extensions in Python 3

An Arma 3 extension that lets you to write python extensions for Arma 3. And it's really simple and straightforward to use!

Lukasz Taczuk 48 Dec 18, 2022
A site that went kinda viral that lets you put Bernie Sanders in places

Bernie In Places An app that accidentally went viral! Read the story in WIRED here Install First, create a python virtual environment, and install all

null 310 Aug 22, 2022
uMap lets you create maps with OpenStreetMap layers in a minute and embed them in your site.

uMap project About uMap lets you create maps with OpenStreetMap layers in a minute and embed them in your site. Because we think that the more OSM wil

null 771 Dec 29, 2022
An addin for Autodesk Fusion 360 that lets you view your design in a Looking Glass Portrait 3D display

An addin for Autodesk Fusion 360 that lets you view your design in a Looking Glass Portrait 3D display

Brian Peiris 12 Nov 2, 2022
A program that lets you use your tablet's tilting to emulate an actual joystick on a Linux computer.

Tablet Tilt Joystick A program that lets you use your tablet's tilting to emulate an actual joystick on a Linux computer. It's called tablet tilt joys

null 1 Feb 7, 2022
An example using debezium and mysql with docker-compose

debezium-mysql An example using debezium and mysql with docker-compose The docker compose starts the Zookeeper, Kafka, Mysql and Debezium Connect. Aft

Horácio Dias Baptista Neto 4 May 21, 2022
A script that will warn you, by opening a new browser tab, when there are new content in your favourite websites.

web check A script that will warn you, by opening a new browser tab, when there are new content in your favourite websites. What it does The script wi

Jaime Álvarez 52 Mar 15, 2022
A frontend to ease the use of pulseaudio's routing capabilities, mimicking voicemeeter's workflow

Pulsemeeter A frontend to ease the use of pulseaudio's routing capabilities, mimicking voicemeeter's workflow Features Create virtual inputs and outpu

Gabriel Carneiro 164 Jan 4, 2023
PORTSCANNING-IN-PYTHON - A python threaded portscanner to scan websites and ipaddresses

PORTSCANNING-IN-PYTHON This is a python threaded portscanner to scan websites an

null 1 Feb 16, 2022
lets learn Python language with basic examples. highly recommended for beginners who just start coding.

Lets Learn Python ?? Learn python from basic programs. learn python from scratch. 1.Online python compiler: https://www.onlinegdb.com/online_python_co

Subhranshu Choudhury 1 Jan 18, 2022