Skip to main content

Fast light weight web server

Project description

DustAPI - A Fast light weight Python Web Framework

DustAPI is a lightweight web framework written in Python, designed to be simple and easy to use. It provides basic routing and response handling, making it a great starting point for learning about web frameworks or building small web applications.

dustAPI image

Features

  • Simple and intuitive routing
  • Fully homomorphic encryption (i.e dust server interacts with encrypted data without ever decrypting it)
  • Support for all HTTP methods (GET, POST, PUT, DELETE, etc.)
  • WebSocket support
  • Custom response types (JSON, HTML, etc.)
  • Extensible and lightweight
  • Auto generate docs with swagger
  • Support for jwt and session manager

Pending features

Feel free to help by contributing on these features to make dustapi a success.

  • AI/ML model inference and consumption
  • Middleware support (planned)

Installation

To install DustAPI, you can simply use pip:

pip install dustapi

Usage

Here is a simple example of how to create a web application using dustapi:

Create a dustapi project

dustapi createproject

Run dustapi server

dustapi runserver --host 0.0.0.0 --port 8000 --template-folder mytemplates --static-folder mystatic --log-file myapp.log

Example

from dustapi.application import Dust, get_request
from dustapi.responses import JsonResponse, HtmlResponse, Response
import os

app = Dust()

UPLOAD_FOLDER = 'uploads'
if not os.path.exists(UPLOAD_FOLDER):
    os.makedirs(UPLOAD_FOLDER)

def save_uploaded_file(file_data, upload_folder):
    filename = file_data['filename']
    filepath = os.path.join(upload_folder, filename)
    with open(filepath, 'wb') as f:
        f.write(file_data['content'])
    return filename

@app.route('/', methods=['GET'])
async def home():
    return app.render_template('index.html', title="Home", heading="Welcome to dustapi Framework", content="This is the home page.")

@app.route('/hello', methods=['GET'])
async def hello():
    return "Hello, World!"

@app.route('/json', methods=['GET'])
async def json_example():
    data = {"message": "This is a JSON response"}
    return JsonResponse(data)

@app.route('/data', methods=['POST'])
async def post_data():
    return "Data received via POST"

@app.route('/update', methods=['PUT'])
async def update_data():
    return "Data received via PUT"

@app.route('/delete', methods=['DELETE'])
async def delete_data():
    return "Data received via DELETE"

@app.route('/upload', methods=['POST'])
async def upload_file():
    request = get_request()
    if 'file' not in request.form:
        raise ValueError("No file part in the request")
    
    file_data = request.form['file']
    filename = file_data['filename']
    filepath = save_uploaded_file(file_data, UPLOAD_FOLDER)

    return f"File {filename} uploaded successfully"

# Custom error handler for ValueError
@app.errorhandler(ValueError)
def handle_value_error(exc):
    return Response(str(exc), status=400)

# Custom error handler for generic exceptions
@app.errorhandler(Exception)
def handle_generic_exception(exc):
    return Response("An unexpected error occurred.", status=500)

if __name__ == '__main__':
    app.run(host='localhost', port=5000)

Project details


Download files

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

Source Distribution

dustapi-0.0.6.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dustapi-0.0.6-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file dustapi-0.0.6.tar.gz.

File metadata

  • Download URL: dustapi-0.0.6.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for dustapi-0.0.6.tar.gz
Algorithm Hash digest
SHA256 12a28b58a4d2376f0072503454864b1ffe7f98bda0edfdbf9d36f8992f22c47d
MD5 ed805cb563e1b1d63c5b398d4bb319b4
BLAKE2b-256 e990758eafbd26362c4f0ec4baa0e2512da9dc4b0320c999a5aa7d3d3caf0a6b

See more details on using hashes here.

File details

Details for the file dustapi-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: dustapi-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for dustapi-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9a872da3a046b91198a6012f315e781114dc28991882ec3c3d31f2cbfe9b4cd9
MD5 6de8e9bdf008071d730af9b8f9a4abcb
BLAKE2b-256 be2c071bd416722a191bcdde5b20bfb2913d0c1fb8efa235f707ec3c7a627393

See more details on using hashes here.

Supported by

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