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
Build Xmas cards with user inputs

Automatically build Xmas cards with user inputs

Anand 9 Jan 25, 2022
A script where you execute a script that generates a base project for your gdextension

GDExtension Project Creator this is a script (currently only for linux) where you execute a script that generates a base project for your gdextension,

Unknown 11 Nov 17, 2022
Linux Security and Monitoring Scripts

Linux Security and Monitoring Scripts These are a collection of security and monitoring scripts you can use to monitor your Linux installation for sec

Andre Pawlowski 65 Aug 27, 2022
Create VSCode Extensions with python

About Create vscode extensions with python. Installation Stable version: pip install vscode-ext Why use this? Why should you use this for building VSc

Swas.py 134 Jan 07, 2023
Grouping nucleotide coordinate ranges.

NuclRanger Grouping nucleotide coordinate ranges. A quick pre-processing step for "bedtools getfasta":- https://bedtools.readthedocs.io/en/latest/cont

Sujanavan Tiruvayipati 1 Oct 04, 2022
🎉 🎉 PyComp - Java Code compiler written in python.

🎉 🎉 PyComp Java Code compiler written in python. This is yet another compiler meant for babcock students project which was created using pure python

Alumona Benaiah 5 Nov 30, 2022
Beancount: Double-Entry Accounting from Text Files.

beancount: Double-Entry Accounting from Text Files Contents Description Documentation Download & Installation Versions Filing Bugs Copyright and Licen

2.3k Dec 28, 2022
Personal Assistant Tessa

Personal Assistant Tessa Introducing our all new personal assistant Tessa..... An intelligent virtual assistant (IVA) or intelligent personal assistan

Anusha Joseph 4 Mar 08, 2022
A curses based mpd client with basic functionality and album art.

Miniplayer A curses based mpd client with basic functionality and album art. After installation, the player can be opened from the terminal with minip

Tristan Ferrua 102 Dec 24, 2022
A Python library to simulate a Zoom H6 recorder remote control

H6 A Python library to emulate a Zoom H6 recorder remote control Introduction This library allows you to control your Zoom H6 recorder from your compu

Matias Godoy 68 Nov 02, 2022
An open-source systems and controls toolbox for Python3

harold A control systems package for Python=3.6. Introduction This package is written with the ambition of providing a full-fledged control systems s

Ilhan Polat 157 Dec 05, 2022
Checking-For-Fibonacci-Syquence-In-Python - Checking For Fibonacci Syquence In Python

Checking-For-Fibonacci-Syquence-In-Python The Fibonacci sequence is a set of num

John Michael Oliba 1 Feb 14, 2022
Scripts used in the RayStation medical radiation dosimetry treatment planning system

Med Phys Scripts These are scripts that I, the medical physics assistant at Cookeville Regional Medical Center, wrote for use in our radiation therapy

Kaley White 2 Oct 19, 2022
This is the Code Institute student template for Gitpod.

Welcome AnaG0307, This is the Code Institute student template for Gitpod. We have preinstalled all of the tools you need to get started. It's perfectl

0 Feb 02, 2022
Repositório do Projeto de Jogo da Resília Educação.

Jogo da Segurança das Indústrias Acme Descrição Este jogo faz parte do projeto de entrega do primeiro módulo da Resilia Educação, referente ao curso d

Márcio Estevam da Silva 2 Apr 28, 2022
Path of Exile Vendor Recipe Tracker (Chaos/Regal orb)

Path of Exile Vendor Trade Tracker Are you tired of manually keeping track of collected and missing items for farming Chaos or Regal Orbs in PoE? Me t

1 Nov 09, 2021
Easytile blender - Simple Blender 2.83 addon for tiling meshes easily

easytile_blender Dead simple, barebones Blender (2.83) addon for placing meshes as tiles. Installation In Blender, go to Edit Preferences Add-ons

Sam Gibson 6 Jul 19, 2022
The program converts Swiss notes into American notes

Informatik-Programmieren Einleitung: Das Programm rechnet Schweizer Noten in das Amerikanische Noten um. Der Benutzer kann seine Note eingeben und der

2 Dec 16, 2021
An Android app that runs Elm in a webview. And a Python script to build the app or install it on the device.

Requirements You need to have installed: the Android SDK Elm Python git Starting a project Clone this repo and cd into it: $ git clone https://github.

Benjamin Le Forestier 11 Mar 17, 2022