API moment - LussovAPI

Overview

LussovAPI

forthebadge forthebadge
forthebadge forthebadge

TL;DR: py API container, pip install -r requirements.txt, example, main configuration

Long version:

Install Dependancies

Download file requirements.txt

requirements.txt

Flask>=2.0.2
Flask_RESTful>=0.3.9
pymongo>=3.12.1
requests>=2.26.0
...

Install pip dependancies by running the following command inside of cmd or a shell based application

cmd / shell

pip install -r requirements.txt

🎉 Congratulations!

Initialization and Setup

Create or use a previously existing file that represents your entry script.
A simple example can be found within the repository at main.py

main.py

from server import Server



def main():
    server = Server(

    )

if __name__ == '__main__':
    main()

There are several configuration options available directly from the initialization of the Server object.
These are passed to the opject as loose type parameters.

name: str = 'Server', 
 # name of the server
host: str = 'localhost', 
 # server hosting ip
port: Optional[Union[int, str]] = 5000,
 # server hosting port
config: Optional[Union[str, dict]] = 'config.json', 
 # server configuration & value store
apidir: Optional[str] = 'apis',
 # the directory in which endpoints exist

Endpoints and Hierarchy

Each endpoint represents its own API directory, similar to how classes contain functions.
For example, both the default Ping and Test endpoints represent the test API endpoint.

How does this apply within our file structure?

.
├── ...
├── apis                    # Alternatively, directory defined in apidir
│   ├── ...                 # ...
│   └── test                # API endpoint test, all endpoints inherit prefix
|   │   ├── ...                 # ...
|   │   └── ping.py                # Contains endpoints Ping and Test
└── ...

Within this example, an API endpoint from ping.py would look as follows:
http://localhost:5000/test/{endpoint}?content={}

Within the file itself, it becomes clear that these endpoints function similar to React routing, requiring functional exporting.
Endpoint: super().__init__(**kwargs) @Endpoint.RequiresArgs() def get(self, args: dict) -> tuple: print(args) return {'response' : 'Pong'}, Endpoint.Codes.OK class Test(Endpoint): def __init__(self, **kwargs) -> Endpoint: super().__init__(**kwargs) def get(self) -> tuple: return {}, Endpoint.Codes.OK """ Router """ def route() -> Optional[set]: return [ Ping, Test ] ">
...

""" 
Endpoints
"""

class Ping(Endpoint):
    def __init__(self, **kwargs) -> Endpoint:
        super().__init__(**kwargs)

    @Endpoint.RequiresArgs()
    def get(self, args: dict) -> tuple:
        print(args)

        return {'response' : 'Pong'}, Endpoint.Codes.OK

class Test(Endpoint):
    def __init__(self, **kwargs) -> Endpoint:
        super().__init__(**kwargs)

    def get(self) -> tuple:

        return {}, Endpoint.Codes.OK

"""
Router
"""

def route() -> Optional[set]:
    return [
        Ping,
        Test
    ]

Methods

Within each endpoint, there are several HTTP methods available for utilizing, such as:
get

def get(self) -> tuple:
  return {}, Endpoint.Codes.OK


post

def post(self) -> tuple:
  return {}, Endpoint.Codes.OK


put

def put(self) -> tuple:
  return {}, Endpoint.Codes.OK


delete

def delete(self) -> tuple:
  return {}, Endpoint.Codes.OK


... and more

A list of all modern HTTP methods and their descriptions can be found here

Decorators

You may also notice that there are several applicable decorators available.
Decorators are not required to maintain the functionality of the application, but are required if you wish to pass arguments to HTTP methods.

default arguments decorator

@Endpoint.RequiresArgs()
# Passes arguments from content to keyword args

Requires keyword content to be present within the query. All values passed to args should be passed through content as a string, per conventions.



That's all, folks

Bottom text
Owner
William Pedersen
18 year old software developer
William Pedersen
A desktop app to check the unlocked courses bases on previously done courses.

Course Picker A desktop app to check the unlocked courses bases on previously done courses. Table of contents About the Project Built with What it doe

Ahmed Symum Swapno 3 Feb 07, 2022
Генератор отчетов на Python с использованием библиотеки docx для работы с word-файлами и запросов к сервису

Генератор отчетов на Python с использованием библиотеки docx для работы с word-файлами и запросов к сервису

Semyon Esaev 2 Jun 24, 2022
Manjaro CN Repository

Manjaro CN Repository Automatically built packages based on archlinuxcn/repo and manjarocn/docker. Install Add manjarocn to /etc/pacman.conf: Please m

Manjaro CN 28 Jun 26, 2022
Convert text with ANSI color codes to HTML or to LaTeX.

Convert text with ANSI color codes to HTML or to LaTeX.

PyContribs 326 Dec 28, 2022
Herramienta para poder automatizar reuniones en Zoom.

Crear Reunión Zoom con Python Herramienta para poder automatizar reuniones en Zoom. Librerías Requeridas Nombre Comando PyAutoGui pip install pyautogu

JkDev 3 Nov 12, 2022
This is some simple code to scrape vistbook's system to get an overview of the different cabins availability.

DNT_cabin_availability_system This is some simple code to scrape visbook's system to get an overview of the different cabins availability. The system

Andreas Lorentzen 1 Sep 25, 2022
A Python utility belt containing simple tools, a stdlib like feel, and extra batteries. Hashing, Caching, Timing, Progress, and more made easy!

Ubelt is a small library of robust, tested, documented, and simple functions that extend the Python standard library. It has a flat API that all behav

Jon Crall 638 Dec 13, 2022
Project issue to website data transformation toolkit

braintransform Project issue to website data transformation toolkit. Introduction The purpose of these scripts is to be able to dynamically generate t

Brainhack 1 Nov 19, 2021
When should you berserk in lichess arena tournament games?

When should you berserk in a lichess arena tournament game? 1+0 arena tournament 3+0 arena tournament Explanation For details on how I arrived at the

18 Aug 03, 2022
Tools for downloading and processing numerical weather predictions

NWP Tools for downloading and processing numerical weather predictions At the moment, this code is focused on downloading historical UKV NWPs produced

Open Climate Fix 6 Nov 24, 2022
A Google sheet which keeps track of the locations that want to visit and a price cutoff

FlightDeals Here's how the program works. First, I have a Google sheet which keeps track of the locations that I want to visit and a price cutoff. It

Lynne Munini 5 Nov 21, 2022
Camera track the tip of a pen to use as a drawing tablet

cablet Camera track the tip of a pen to use as a drawing tablet Setup You will need: Writing utensil with a colored tip (preferably blue or green) Bac

14 Feb 20, 2022
Reactjs web app written entirely in python, using transcrypt compiler.

Reactjs web app written entirely in python, using transcrypt compiler.

Dan Shai 22 Nov 27, 2022
A python program with an Objective-C GUI for building and booting OpenCore on both legacy and modern Macs

A python program with an Objective-C GUI for building and booting OpenCore on both legacy and modern Macs, see our in-depth Guide for more information.

dortania 4.7k Jan 02, 2023
freeCodeCamp Scientific Computing with Python Project for Certification.

Time_Calculator_freeCodeCamp freeCodeCamp Scientific Computing with Python Project for Certification. Write a function named add_time that takes in tw

Rajdeep Mondal 1 Dec 23, 2021
Tools Elit Adalah Sebuah Script Crack Yang Wajib Tap Yes...

Tools Elit Adalah Sebuah Script Crack Yang Wajib Tap Yes...

Risky [ Zero Tow ] 10 Apr 07, 2022
Safely pass trusted data to untrusted environments and back.

ItsDangerous ... so better sign this Various helpers to pass data to untrusted environments and to get it back safe and sound. Data is cryptographical

The Pallets Projects 2.6k Jan 01, 2023
TinyBar - Tiny MacOS menu bar utility to track price dynamics for assets on TinyMan.org

📃 About A simple MacOS menu bar app to display current coins from most popular

Al 8 Dec 23, 2022
Personal Chat Assistance

Python-Programming Personal Chat Assistance {% import "bootstrap/wtf.html" as wtf %} titleEVT/title script src="https://code.jquery.com/jquery-3.

PRASH_SMVIT 2 Nov 14, 2021
Create a program for generator Truth Table

Python-Truth-Table-Ver-1.0 Create a program for generator Truth Table in here you have to install truth-table-generator module for python modules inst

JehanKandy 10 Jul 13, 2022