Package: ofjustpy
OfjustpyOfjustpy: A Full-Stack Web Development Framework in PythonFeatures:Single language: Ofjustpy allows you to build full-featured web pages using only the Python programming language. You don't need to learn and manage multiple languages like Jinja2 templating, JavaScript, HTML, and CSS. The entire functionality of a webpage can be expressed using pure Python.Emphasis on API Design:  Much emphasis has been put on API design and programmatic constructs in order
to be able to build complex responsive webpages and websites with codebase that easy to read and maintain.Scalable and efficient: Ofjustpy enables programmers to write scalable and efficient webpage code. It maintains only a single copy of static components, regardless of the number of connections opened. Data copying per connection and per event is minized. Even for mutable components, only a single copy of the component's static portion is maintained.  Additionally, communication is efficient as it transmits only the changes (diff) to the UI to the frontend.Composibility:  Ofjustpy allows users to easily build reusable components and incorporate them into their codebase. Seehtmlcomponents.pyandofjustpy-componentsfor  simple to complex components build using Ofjustpy framework.Tailwind CSS Support: Ofjustpy provides first-class and native support for Tailwind CSS constructs, enabling complex manipulation (add, remove, update classes) of the frontend UI through pure Python expressions.Async Processing: Like its predecessor Justpy, Ofjustpy utilizes an asynchronous webserver stack that includes Starlette, ASGI, asyncio, and async/await. This architecture enables Ofjustpy to efficiently handle concurrent connections, even on single-core hardware or virtual environments, without the need for OS-level multi-threading.Technology Stack:
The tech stack of ofjustpy consists of Svelte (as the frontend UI engine),
websockets (for communication between browser and server), Starlette (the async webserver),
amd Tailwind (for layout and design).GallerySeeexamplesfor a collection of
basic tutorial examples of webpages build using ofjustpy.SeeBasic capabilities demofor
webpage showing basic html componentsSeeAdvanced capabilities demofor webpage illustrating advanced components (hierarchy navigator,  pagination) in action.Webpage programming using OfjustpyThe basic paradigm for building out webpages in Ofjustpy is straighforward:Create components and containersDescribe their layout and appearance using tailwind constructsFor components that will respond to events on UI, describe handlers (actions) for those
eventsIf you are new to web development, then it would be helpful to go through thejustpy docsand itsexampleson which Ofjustpy is based on.
Also, pay careful attention to known corner cases and suggested workarounds mentioned inGotchasto keep Ofjutpy engine happyThe demo example illustrates the three paradigms for building out webpages:importofjustpyasojfrompy_tailwind_utilsimport*labels=[oj.Mutable.Label(text="mytext1",key="mylabel1"),oj.Mutable.Label(text="mytext2",key="mylabel2"),oj.Mutable.Label(text="mytext3",key="mylabel3"),oj.Mutable.Label(text="mytext4",key="mylabel4"),]mydeck=oj.Mutable.StackD(key="mydeck",childs=labels,height_anchor_key="mylabel1",twsty_tags=[W/"1/2"])idx=1defon_btn_click(dbref,msg,target_of):globalidxmydeck_shell=target_of(mydeck)mydeck_shell.bring_to_front(labels[idx].id)idx=(idx+1)%4passmybtn=oj.AC.Button(key="mybtn",text="abtn",pcp=[W/32,H/32,bg/rose/6],on_click=on_btn_click)wp_endpoint=oj.create_endpoint(key="static-components",childs=[mydeck,mybtn])oj.add_jproute("/",wp_endpoint)Components and their types in OfjustpyOfjustpy, boradly, defines  2 kinds of components: static vs mutable.
Static components are further classified into Passive and Active,
while mutable components come in three variety: HCCMutable, HCCStatic, Mutable.Passive ComponentsAs name suggests, these do not respond to UI events and also do not undergo
any changes. Ofjustpy maintains only a single copy of such components (see (seeexamples/static_webpages)
Examples of passive  components:oj.PC.Labeloj.PC.Poj.PC.Imgetc. SeeSHC_types.pyfor list of all passive components.Active ComponentsActive components handle events but like passive do not mutate.
Active components require an additional key/id argument (seeexamples/input_components).
Examples of active  components:oj.AC.Buttonoj.AC.TextInputoj.AC.CheckboxInputoj.AC.Selectoj.AC.Aand so on. SeeSHC_types.pyfor list of all active componentsMutable componentsMutable components can handle events and also mutate, i.e., change
appearances. Seeexamples/mutable_webpagesfor usage.
Examples of mutable components include:oj.Mutable.Buttonoj.Mutable.Labeloj.Mutable.Container
and so on. SeeMHC_types.pyfor list of all mutable components.HCCMutable ComponentsThese are div  components
that contain mutable childrens.
The div itself is not mutable (seeexamples/mutable_webpages/example_004.py).
HCCMutable components offer minor space optimization
over Mutable divs.
Examples of HCCMutable components:oj.HCCMutable.Divoj.HCCMutable.StackVoj.HCCMutable.StackWoj.HCCMutable.Subsection
SeeMHC_types.pyfor list of all HCCMutable components.HCCStatic ComponentsThese are div components
that itself are mutable but
they contain static (passive or active) components.
Examples of HCCStatic components:oj.HCCStatic.Divoj.HCCStatic.StackVSeeMHC_types.pyfor list of all HCCStatic components.
jjTailwind-derived higher-order componentsIn addition to standard HTML components (like, Div, Span, Button, etc.),
Ofjustpy offers advanced components that offer complex functionality. These
are build using Tailwind CSS constructs, Svelte, and Python.Containers to juxtapose child components
StackH, StackV, StackG, StackW : Stack components horizontally, vertically, grid, and wrap around. See examplesexamples/static_webpages/example_001.py,examples/static_webpages/example_002.pyfor StackV,examples/static_webpages/example_004.pyfor StackG,examples/static_webpages/example_002.pyfor StackW.StackD:
Deck the items on top of each other. See examplesexamples/mutable_webpages/example_005.py,examples/mutable_webpages/example_008.pySlider
A component with discreet value buttons to select a value.
See examplesexamples/mutable_webpages/example_002.py,examples/mutable_webpages/example_003.py,examples/mutable_webpages/example_006.py.ColorSelector
Component create select  drop down option for all tailwind preset color values.
See exampleexamples/mutable_webpages/example_007.pySee ofjustpy-components github repo for collection of advanced components.The Ofjustpy paradigms: app module, TwStyCtx, MountCtx, PageBuilderCtxApp moduleOfjustpy requires that starlette app be defined in its own file lets say
"theapp.py". Then set theOJ_APP_MODULEto set the location of thetheapp.pyrelative to directory from where the webserver is being launched.exportOJ_APP_MODULE="../the_app"A sample example oftheapp.pylooks as follows:fromasgi_signing_middlewareimportSerializedSignedCookieMiddlewareimportofjustpyasojcsrf_middleware=Middleware(CSRFMiddleware,secret=csrf_secret,field_name=csrf_cookie_name)signed_cookie_middleware=Middleware(SerializedSignedCookieMiddleware,secret=b'a very, very secret thing',state_attribute_name='messages',cookie_name='my_cookie',cookie_ttl=60*5,)auth_middleware=Middleware(AuthenticationMiddleware,backend=BasicAuthBackend(),on_error=lambda_,exc:PlainTextResponse("error during authentication",status_code=401))app=oj.load_app([auth_middleware,signed_cookie_middleware,csrf_middleware])User defined default sty module and TwSty contextThe default UI style of a component is determined by its type. For each component type (e.g., Button, Span), a style is defined in the snowsty.py module, which resides within the src/ofjustpy directory.
You can customize the default style by registering a style file
with Ofjustpy.  To load your custom style, set the OJSTY environment variable accordingly.
Please note that the default style for a component can be overridden using thetwsty_tagsdirective. You can also modify the style programmatically throu TwStyCtx context expression.
Ofjustpy provides two style definitionssnowstyandun. Theunstyle does not
add any styling to the components.An example illustrate style switching:withoj.TwStyCtx("un"):oj.Button(...,twsty_tags=[])# Draw a with un default stylingoj.Button(...,twsty_tags=[])# use dnowsty as default stylingCustomizing Default Styling in OfjustpyIn Ofjustpy, the default UI style for a component is determined by its type. Each component type, such as Button or Span, has a predefined style located in thesnowsty.pymodule within thesrc/ofjustpydirectory.To personalize the default styling, you can register a custom style file with Ofjustpy. To make use of your custom style, simply set theOJSTYenvironment variable accordingly.Please bear in mind that you have the flexibility to override the default style for a component using thetwsty_tagsdirective.In addition to settingOJSTY, you can programmatically modify the style using theTwStyCtxcontext expression.Ofjustpy offers two predefined style definitions:snowstyandun. Theunstyle, in particular, refrains from adding any additional styling to the components.Here's an example to illustrate style switching:withoj.TwStyCtx("un"):oj.Button(...,twsty_tags=[])# Draws with the 'un' default stylingoj.Button(...,twsty_tags=[])# Uses 'snowsty' as the default stylingBy following these guidelines, you can easily tailor the default styles in Ofjustpy to suit your project's aesthetic preferences.MountContextThe MountContext construct simplifies the process of mounting all the routes defined in a module. Consider the following example:withoj.MountCtx("examples"):withoj.MountCtx("static_webpages"):static_webpage_module=importlib.import_module("examples.static_webpages",)In the above example, all the routes
defined within the examples.static_webpages will be mounted underexamples/static_webpagespath.
MountCtx enable a plug-and-play approach for adding modules and defining routes.
This means you can import the module into multiple web app codes without needing to modify the module code for each app. This flexibility simplifies the process of extending and reusing modules across different applications.PageBuilder ContextThe PageBuilderCtx context is used to modify or post-process webpage endpoints defined within a module. Let's consider the following example:defpage_builder(edir):"""We need edir to find the example directory within which the example is located."""defpage_builder_inner(key,childs,**kwargs):title=kwargs.get('title')nav_buttons=//definealistofnavigationbuttonsreturnoj.Mutable.WebPage(key=key,childs=[oj.HCCMutable.StackV(childs=[oj.HCCMutable.Div(childs=childs),oj.PC.Hr(twsty_tags=[bg/green/1]),nav_buttons],twsty_tags=[space/y/8])],**kwargs)returnpage_builder_innerwithoj.PageBuilderCtx(page_builder("mutable_webpages")):withoj.MountCtx("input_components"):input_components_module=importlib.import_module("examples.input_components",)In the above example, theoj.PageBuilderCtxcontext is used to post-process all endpoints defined within theexamples.input_componentsmodule. Specifically, it allows for the addition of navigation buttons at the bottom of each page generated by the endpoints in this module. This structured approach simplifies the task of modifying and enhancing the behavior of web pages associated with theinput_componentsmodule by applying a consistent post-processing step to all of them.