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 werkzeug module. It allows you to create web applications quickly with simple, decorator-based routing.

Features

  • 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 werkzeug.wrappers import Response

from nebula import Nebula 
from nebula.utils import jsonify, init_static_serving
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"

init_static_serving(app, "statics")

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

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

    return Response(app.load_template("test.html"), 200, content_type="text/html")

@app.route("/greet/<name>")
def greet(request, name):
    return Response(f"Hi, {name}!", 200)

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

@app.error_handler(405)
def method_not_allowed(request):
    return Response("Cant do that :[", 405)

@app.error_handler(404)
def not_found(request):
    return Response("Cant find that :(", 404)

@app.route("/internal-error")
def error(request):
    return Response(f"Error!", 500)

@app.route("/api", methods=["POST"])
def api(request):
    return jsonify({"a": 1, "b": 2, "c": 3}[request.get_json().get("item", "a")])

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.

Contributions <3

amogus-gggy - refactoring Nebula 0.2.0. Huge thank you!

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-1.0.0.tar.gz (7.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-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nebula_core-1.0.0.tar.gz
  • Upload date:
  • Size: 7.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-1.0.0.tar.gz
Algorithm Hash digest
SHA256 73eeb9f81db653721ab4909f9deada1182652bb87548796f0d7545c1ca98d9a6
MD5 2e27216e06dee62fc3d9593ddfef2d96
BLAKE2b-256 b7d4a46cd2f33d49c6165e40ca127e6cebfa067a7d8d05f52eb2b4a5e41e4eb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nebula_core-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ff4080110bb0e325872b36fa8895cdb762467f8b3a6e89e934b5bd570815ba7
MD5 cbc27196e6c774e20d19f156fe5e221b
BLAKE2b-256 d60ee499b75f67d2a0e1f3baa476f55717b730533ef4575c8df8be18566d90f1

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