Skip to main content

Nebula is a lightweight Python backend framework with middleware and routing, built on top of the standard http.server module. It allows you to create web applications quickly with simple, decorator-based routing.

Project description

Nebula

PyPI Stars Contributors

Nebula is a lightweight Python backend framework with middleware and routing, built on top of the standard http.server module. It allows you to create web applications quickly with simple, decorator-based routing.

Features

  • Lightweight: Built on Python's standard library with no external dependencies.
  • Decorator-based Routing: Define your routes with simple and intuitive decorators.
  • Template Loading: Easily load and serve HTML templates from a designated directory.
  • Statics Loading: Easily load and serve files from designated directory.
  • Middleware Support: before_request and after_request hooks for flexible request handling.
  • Easy to Use: Get a server up and running in just a few lines of code.

Installation

Install Nebula from PyPI:

pip install nebula-core

or clone and install from GitHub.

git clone https://github.com/VxidDev/nebula.git
cd nebula
pip install .

Usage

Here's a basic example of creating a simple web server with Nebula.

main.py:

from nebula import Nebula , Response , jsonify
from pathlib import Path 

app = Nebula("localhost", 8000, False)
app.templates_dir = Path(__file__).resolve().parent / "templates"
app.statics_dir = Path(__file__).resolve().parent / "statics"

@app.before_request
def func(request):
    print(f"received request on {request.route.path} with method {request.method}...")

@app.after_request
def func(request):
    print(f"successfully handled request on {request.route.path} with method {request.method}...")

@app.internal_error_handler
def internal_error():
    return Response('<h1 style="font-size: 100px;">something doesnt work.</h1>', 500)

@app.route("/" , methods=["GET" , "POST"])
def main():
    if app.request.method == "POST":    
        data = app.request.data.get_json()

        return jsonify({"greet": f"Hi, {data.get('name', 'default')}!"})

    return Response(app.load_template("test.html"), 200)

@app.route("/fruits")
def jsonTest():
    return jsonify({
        "fruits": {
            "apples": 6,
            "pears": 10,
            "mangos": 9
        } 
    })

app.run()

templates/index.html:

<!DOCTYPE html>
<html>
<head>
    <title>Hello from Nebula!</title>
</head>
<body>
    <h1>Welcome to Nebula</h1>
    <p>This is a page served by the Nebula web server.</p>
</body>
</html>

Run your app:

python main.py

Open your browser and navigate to http://localhost:8000 to see your page.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

nebula_core-0.3.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

nebula_core-0.3.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file nebula_core-0.3.0.tar.gz.

File metadata

  • Download URL: nebula_core-0.3.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for nebula_core-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6d40b37ac20ae54133b7a587f011b297280d5e23d953a1c0bfb309a636ad907c
MD5 d2d218393ca82374507e1b0e0405d6de
BLAKE2b-256 401cbbd9d9f778e3da99f6b703c5ed04683f1f64b6112c43130e21eaef7286e4

See more details on using hashes here.

File details

Details for the file nebula_core-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: nebula_core-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for nebula_core-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95e94a397bd76c63d357f35dd4cc2878a18d946ae710a9d8e6c9471b245bfedb
MD5 936b707d1b9a9eb7a8f2e6afbfc54298
BLAKE2b-256 ac8de007f8c00c0b399228c7ca472acf7d31b22e625219ae78b9e56167c0ddcd

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