Package: hypymedia
🚀HypymediaHypymediais a Python package that significantly simplifies the process of creating dynamic HTML content programmatically. Featuring a rich library of functions, each corresponding to a specific HTML tag, it empowers users to craft HTML elements with dynamic content and attributes seamlessly.🛠 InstallationInstalling theHypymediapackage is as easy as running a single command:pipinstallhypymedia💡 UsageHypymediaboasts a user-friendly and intuitive interface. Simply import the desired functions, representing HTML tags, and you are ready to design HTML content dynamically.The attributes for tags can be declared through dictionaries, and the content can be customized using additional arguments.🌟 Basic Usagefromhypymediaimportdiv_,p_# Creating a div element with a class attribute containing a p elementhtml_content=div_({'class':'example'},p_('Hello, World!'))Output:<divclass="example"><p>Hello, World!</p></div>🌟 Using AttributesAdding attributes to your HTML tags is straightforward, simply pass a dictionary with the elements you need.fromhypymediaimporta_# Crafting a link with href and title attributeslink=a_({'href':'https://www.example.com','title':'Example'},'Click here')Output:<ahref="https://www.example.com"title="Example">Click here</a>where you have an attribute that doesn't have a value (e.g.,disabled), you can passNoneas the value:fromhypymediaimportbutton_button=(button_({"disabled":None},"Click here"))Output:<buttondisabled>Click here</button>🌟 Handling Self-closing TagsWithHypymedia, you can effortlessly create self-closing tags such as<img>and<br>:fromhypymediaimportimg_,br_# Creating an img element with src and alt attributesimage=img_({'src':'image.jpg','alt':'An example image'})Output:<imgsrc="image.jpg"alt="An example image"/>🎨 ExamplesDive into the potential ofHypymediawith these illustrative examples:Unordered Listfromhypymediaimportul_,li_# Define the list itemsitems=["Item 1","Item 2","Item 3"]# Utilize a list comprehension to develop the list itemslist_items=[li_(item)foriteminitems]# Create the unordered listunordered_list=ul_(*list_items)Output:<ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>Using Python Functions to Build a Table with a List and a List ComprehensionConstructing a table with lists and list comprehensions is a breeze withHypymedia:fromhypymediaimporttable_,tr_,th_,td_# Define the data set for the tabledata=[["Name","Age","City"],["John Doe",30,"New York"],["Jane Doe",28,"Los Angeles"],["Jim Doe",32,"Chicago"],]# Utilize a list comprehension to develop the table rowsrows=[tr_(*[td_(item)foriteminrow])forrowindata]# Create the table by unpacking...table=table_(*rows)Output:<table><tr><td>Name</td><td>Age</td><td>City</td></tr><tr><td>John Doe</td><td>30</td><td>New York</td></tr><tr><td>Jane Doe</td><td>28</td><td>Los Angeles</td></tr><tr><td>Jim Doe</td><td>32</td><td>Chicago</td></tr></table>Building a Simple WebpageHere's how you can assemble a simple webpage utilizingHypymedia:fromhypymediaimporthtml_,head_,title_,body_,h1_,p_,div_,a_,img_# Define the webpage's titletitle=title_("My Simple Webpage")# Construct the webpage's headerheader=h1_("Welcome to My Simple Webpage")# Create a paragraph for the webpageparagraph=p_("This is a simple webpage crafted with `Hypymedia`.")# Design a link for the webpagelink=a_({'href':'https://www.example.com'},'Visit Example.com')# Develop an image for the webpageimage=img_({'src':'image.jpg','alt':'An example image'})# Combine all elements to form the webpage's bodybody=body_(header,paragraph,link,image)# Merge the title and body to craft the complete HTML documenthtml_document=html_(head_(title),body)Output:<html><head><title>My Simple Webpage</title></head><body><h1>Welcome to My Simple Webpage</h1><p>This is a simple webpage crafted with `Hypymedia`.</p><ahref="https://www.example.com">Visit Example.com</a><imgsrc="image.jpg"alt="An example image"/></body></html>Hypymediaand HTMXFor web libraries like HTMX, utilizing theHypymedialibrary to generate and return partial HTML content offers numerous advantages. Firstly, it promotes network and server efficiency by only transmitting and processing the necessary data, which invariably enhances the user experience through faster load times and more responsive interactions.Moreover, developers gain granular control over content updates, which allows for a more interactive and dynamic web application design. This not only simplifies the codebase but also facilitates easier integration into existing applications without the need for a complete overhaul.Furthermore, this approach maintains the benefits of SEO optimization, unlike heavy single-page applications that rely predominantly on client-side rendering, potentially enhancing the visibility of the web content in search engine rankings. Overall, adopting partial content returns withHypymediacan accelerate development cycles, foster a seamless user experience, and cultivate a more streamlined and efficient web application environment.Hypymediaover Jinja?In the ever-evolving landscape of web development,Hypymediaemerges as a potent alternative to the well-established Jinja templating engine, particularly for developers vested in Python.Hypymediafacilitates a Pythonic approach to HTML content generation, allowing developers to leverage Python's syntax and structures seamlessly, thereby potentially reducing the learning curve and boilerplate code often associated with Jinja. Moreover, it integrates effortlessly with modern frontend technologies like HTMX and FastAPI, offering a streamlined pathway to creating dynamic, interactive web applications.Simple FastAPI and HTMX ExamplefromfastapiimportFastAPI,HTMLResponsefromhypymediaimporthtml_,head_,body_,div_,p_,a_,img_app=FastAPI()defindex_view():head_view=head_(script_({"src":"https://unpkg.com/htmx.org@1.9.5","integrity":"sha384-xcuj3WpfgjlKF+FXhSQFQ0ZNr39ln+hwjN3npfM9VBnUskLolQAcN80McRIVOPuO","crossorigin":"anonymous"}))body_view=body_(div_(p_("Welcome to our website!"),a_({"href":"/image","hx-get":"/image"},"Click here to see an image."),))returnhtml_(head_view,body_view)@app.get("/",response_class=HTMLResponse)defread_root():returnindex_view()@app.get("/image",response_class=HTMLResponse)defread_image():returnimg_({"src":"logo.png","alt":"logo"})📜 LicenseThis project is licensed under the terms of the MIT License.