Skip to main content

Personal Python Framework.

Project description

JdpuPF Python Freamwork ✨

License: MIT PyPI - Version

Installation

pip install JdpuPF

How to use it

Basic usage:

from app import JdpuPF
from middleware import Middleware

app = JdpuPF()

@app.route('/home',allowed_methods=["get"])
def home(request,response):
    if request.method == "GET":
        response.text = "Hello from the Home Page"
    else:
        response.status.code = 405
        response.text = "Method not allowed"


@app.route("/hello/{name}")
def greeting(request, response ,name):
    response.text = f"Hello , {name} :)"
    
@app.route("/books")
class Books:
    def get(self,request, response):
        response.text = "Books page"

    def post(self,request, response):
        response.text = "Endpoint to create a book"

Unit Tests

The recommended way of writing unit tests is with pytest. There are two built in fixtures that you may want to use when writing unit tests with JdpuPF. The first one is app which is an instance of the main API class:

def test_dublicate_routes_throws_exception(app):
    @app.route("/home")
    def home(req,resp):
        resp.text = "Hello from home Page" 
        assert resp.text == "Hello from home Page"    
    with pytest.raises(AssertionError):
        @app.route("/home")
        def home2(req,resp):
            resp.text = "Hello from home2 Page" 

The other one is client that you can use to send HTTP requests to your handlers. It is based on the famous requests and it should feel very familiar:

def test_parameterized_routing(app,test_client):
    @app.route("/hello/{name}")
    def greeting(request, response ,name):
        response.text = f"Hello {name} :)"
        
    assert test_client.get("http://testserver/hello/Lochinbek").text == "Hello Lochinbek :)"
    assert test_client.get('http://testserver/hello/Matthew').text == "Hello Matthew :)"

Thank you for Usage

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

JdpuPF-0.1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

JdpuPF-0.1.1-py2.py3-none-any.whl (2.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file JdpuPF-0.1.1.tar.gz.

File metadata

  • Download URL: JdpuPF-0.1.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for JdpuPF-0.1.1.tar.gz
Algorithm Hash digest
SHA256 35e7570125d5e798f6152f61c4c4c4896c7a2de417b340fbdbf7e827da0fea2e
MD5 6b303b888479c6d22577402a5b2884b9
BLAKE2b-256 27f2f7789fd706eb6241a0bfea86a0c0685c47544115c3bfa148ee1408e3e08d

See more details on using hashes here.

File details

Details for the file JdpuPF-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: JdpuPF-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 2.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for JdpuPF-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c072805b15221a9f6b9971ba32f6b357174c18cb167d65db9a4f1c420c47c0e9
MD5 efc04f2e4f3120a594c9fcd88404af5f
BLAKE2b-256 b4a1e94d354d39b4041f4ac652b31773bfa5f1d931655ec970a1eaeb2301aa8d

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