Coder Social home page Coder Social logo

srikarksv / pure-python-server Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 0.0 116 KB

A blogging platform written in pure python (no web frameworks used) for developer to share their coding knowledge

Home Page: https://pyproject.onrender.com

Python 50.06% HTML 16.88% CSS 31.28% Shell 0.19% JavaScript 1.60%
python pure-python webapp blog no-framework wsgi-application markdown

pure-python-server's Introduction

Pure Python web application - PyProject

A blogging platform written in pure python (no web frameworks used) for developer to share their coding knowledge

How was this web app made?

The web app is based on WSGI and will work perfectly with any WSGI complaint web servers.

Here's a short summary of a WSGI application:

  • WSGI application are callable python objects (functions or classes with a call method that are passed two arguments: a WSGI environment as first argument and a function that starts the response.
  • the application has to start a response using the function provided and return an iterable where each yielded item means writing and flushing.
  • you can add middlewares to your application by wrapping it.

Most Python web frameworks are WSGI compatible, and use a WSGI complaint web server to call them when a request happens return its response to client.

I took some liberties to design the architecture of the project similar to that of a Flask app, and used to some essential libraries for templating, DB storage, conversion of markdown to html and sanitizing of user input.

There was a lot of research invloved as there is scarce information on this topic, I also had to implement code to manage exceptionx instead of crashing and I had to study source code of Python web frameworks, and other libraries to understand how they implemented certain things.

You can find the core code which is the backbone of the app in the folders pyproject/lib, pyproject/errors.

How to run this project

  1. Clone the project
git clone https://github.com/SrikarKSV/pure-python-server.git
  1. Install all the dependencies
pip install -r requirements.txt
  1. Fill the environment variables in a .env file, you can find the example in .env.example

  2. Use gunicorn server to start the application

gunicorn -w 4 main:app
  1. If you don't want make an instance of database, don't mention DATABASE_URI in .env file and the app will create a sqlite db with the table automatically

NOTE โš : If your computer has an error when running gunicorn, you can directly run the python file main.py and it will spin up a WSGI server from python standard library (But it's really slow)

Libraries used in the app

  1. Jinja2
  2. Python-Markdown
  3. SQLAlchemy
  4. bleach
  5. python-dotenv (For development)

The goals of the project:

  • Understand how python web servers works under the hood
  • Connect the small pieces that frameworks takes care of
  • Study the source code of these frameworks to imitate their functionality

NOT the goals of the project:

  • To create the entire functionality of a python web framework
  • To create every functionality from scratch
  • To not use a single external package

Todos:

  • Create a routing system
  • Use Jinja templating language to render html
  • Serve static files
  • Parse both GET and POST requests form
  • A page which shows all the articles
  • A form page to add new articles
  • Use markdown for article content
  • Update and delete articles
  • Style with CSS
  • Add meta tags

pure-python-server's People

Contributors

srikarksv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.