Code Monkey home page Code Monkey logo

episode's Introduction

Episode

A python backend framework with rich features, easy to learn and fast to code.

The Key features are:

  • Fast Router: Has a fast routing system that speeds up request to response time *
  • ORM: Has an inbuilt ORM that supports SQLite, MySQL and MongoDB database *
  • Template Engine: Minimalist integrated template engine for integrating your python code with html *
  • Fast to code: Increase the speed to develop features *
  • Easy: Designed to be easy to use and learn. Less time reading docs.
  • Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.

Example

Create it

  • Create a file main.py with:
from episode.episode import Episode
from episode.httpresponse import HttpResponse
from episode.httpstatus import HTTPStatus
from episode.model import Model, Session, DBMS, DBConnection
from episode.template_engine import render_template

file_path = "student_db.sqlite"
db_conn = DBConnection.dialect(DBMS.SQLITE)
connection = db_conn(database_path=file_path)

class Student(Model):
    first_name: str
    last_name: str
    user_name: str
    age: int


with Session(connection) as session:
    session.drop_create(Student)


if __name__ == "__main__":
    episode = Episode()

    # Expecting a get request only with path parameter 'username'
    @episode.get("/students/{username}")
    def get_student_by_username(request, username: str):
        with Session(connection) as session:
            sql_stmt = session.select(Student).where(Student.user_name == username)
            students = list(session.exec(sql_stmt))
            student = students[0] if students else None

            if student:
                context = {
                    "first_name": student.first_name,
                    "last_name": student.last_name,
                    "age": student.age,
                }

                return render_template("student.html", context=context)
            else:
                return HttpResponse().write(
                    f"Student with username {username} does not exist",
                    status_code=HTTPStatus.NOT_FOUND,
                )

    # Expecting a post request only
    @episode.post("/students/add/")
    def add_student(request, student: Student):
        with Session(connection) as session:
            sql_smt = session.select(Student).where(Student.user_name == student.user_name)
            students = list(session.exec(sql_smt))

            if students:
                return HttpResponse().write(
                    f"User with username {student.user_name} already exist",
                    status_code=HTTPStatus.BAD_REQUEST,
                )

            session.save(student)

        return HttpResponse().write(
            "Data stored successfully", status_code=HTTPStatus.CREATED
        )
    
    episode.start()

Run it

Run the server with:

$ python main.py

INFO:   Serving at http://127.0.0.1:8880  (Press CTRL+C to quit)

Check it

Open your browser at http://127.0.0.1:8880/.

And Test any of the endpoints in the example

episode's People

Contributors

attakay78 avatar abdulmajid18 avatar

Stargazers

 avatar MAXWELL SARPONG avatar  avatar

Watchers

 avatar

episode's Issues

Add CI/CD Pipeline.

Request to add CI/CD Pipeline to run all tests and other pipeline stages.

Add tests

Add functional and integrated tests for all components.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.