Skip to main content

A lightweight and highly customizable Python framework for building web applications

Project description

Mango Framework

License

Introduction

Mango is a lightweight Python framework for building web applications. It provides a simple and intuitive way to handle routing, render HTML templates, and serve files. With Mango, you can quickly set up a web server and define routes to handle different HTTP requests. It is made to be accessible and highly modifiable even by beginners to learn and eventually move on to more mature frameworks such as Flask or Bottle. You only need python3 to run Mango and nothing else.

Features

  • Easy routing configuration
  • Rendering HTML templates
  • Serving static files
  • Handling JSON data
  • Handling of basic form data
  • Lightweight and minimal dependencies
  • Suitable for small to medium-sized web applications
  • Human readible code even beginners could modify
  • Integrated basic ORM for DB functions
  • Integrated basic Template engine Shake
  • Handling of file uploads
  • Setting custom 404 error pages
  • Handling static files

Installation

Mango can be easily installed via pip:

pip install mango-framework

Usage

  1. Import the necessary modules and functions from Mango:
from mango import route, run, render, send_json, send_file, get_json, save_file, set_404, set_static_url, enable_static
  1. Define your routes using the @route() decorator:
@route('/')
def index():
    return "Hello, Mango!"
  1. Get JSON data:
@route('/post')
def post(post):
    user = get_json(post)
    return f"Hello, {user['name']}!"
  1. Send JSON data:
@route('/send')
def send():
    return send_json({'name':'john'})
  1. Send a file for the user to download:
@route('/download')
def download():
    return send_file('image.jpeg')

### as attachment

@route('/download')
def download():
    return send_file('image.jpeg', as_attachment=True)
  1. Render the HTML to the user (now supports shake without the class):
@route('/render')
def render():
    return render('index.html')

### New reactive rendering

@route('/render')
def render():
    return render('index.html',{'name':'john'})
  1. Get form data:
@route('/form')
def form(form_data):
    name = get_data(form_data,'name')
    return f"Hello, {name}!"
  1. Get file upload (only takes single file uploads, with no other form data.):
@route('/upload')
def upload(file):
    save_file(file,'article.pdf')
    return "Saved file successfully"
  1. Change the default 404 Page:
set_404("<h1> not here ! </h1>")

## or pass an HTML or any file directly

set_404("404.html")
  1. Send static files to HTML:
<link rel="stylesheet" type="text/css" href="/static/style.css">
  1. Change the default Static URL
set_static_url("/images")

Default URL is /static. the new link MUST start with / !

  1. Enable or disable Static serving
enable_static(True)
  1. Run the Mango server:
run()

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

mango_framework-1.0.7-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file mango_framework-1.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for mango_framework-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e77825e5a24b76cfcd682880ad27ec0e29e2bf91b26cfa8867b0b28476733e3e
MD5 84db6a0657948e09f6e6f87f659d3606
BLAKE2b-256 334817f1e89724a58291d8a7649c806af4e95eebd4a25cab7437e61e3050b674

See more details on using hashes here.

Supported by

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