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 Lynx that manages a group that puts the federation first.

Lynx Super Federation Management Group Lynx was created to manage your groups on telegram and focuses on the Lynx Federation. I made this to root out

Unknown 2 Nov 01, 2022
Multi View Stereo on Internet Images

Evaluating MVS in a CPC Scenario This repository contains the set of artficats used for the ENGN8601/8602 research project. The thesis emphasizes on t

Namas Bhandari 1 Nov 10, 2021
This repo contains scripts that add functionality to xbar.

xbar-custom-plugins This repo contains scripts that add functionality to xbar. Usage You have to add scripts to xbar plugin folder. If you don't find

osman uygar 1 Jan 10, 2022
Telegram bot to search quotes from brainyquote.com

Brainy Quote Bot @BrainQuoteBot A star ⭐ from you means a lot to us! Telegram bot to search quotes from brainyquote.com Usage Deploy to Heroku Tap on

21 Nov 24, 2022
Sigma coding youtube - This is a collection of all the code that can be found on my YouTube channel Sigma Coding.

Sigma Coding Tutorials & Resources YouTube • Facebook Support Sigma Coding Patreon • GitHub Sponsor • Shop Amazon Table of Contents Overview Topics Re

Alex Reed 927 Jan 08, 2023
take home quiz

guess the correlation data inspection a pretty normal distribution train/val/test split splitting amount .dataset: 150000 instances ├─8

HR Wu 1 Nov 04, 2021
An app to help people apply for admissions on schools/hostels

Admission-helper About An app to help people apply for admissions on schools/hostels This app is a rewrite of Admission-helper-beta-v5.8.9 and I impor

Advik 3 Apr 24, 2022
Procscan is a quick and dirty python script used to look for potentially dangerous api call patterns in a Procmon PML file.

PROCSCAN Procscan is a quick and dirty python script used to look for potentially dangerous api call patterns in a Procmon PML file. Installation git

Daniel Santos 9 Sep 02, 2022
Simple programming language built on Python.

Serial Another programming language. Built on Python. Building and running program In order to run the program on serial, unfortunately you still need

Aleksey Demchenkov 1 Dec 09, 2021
A simple and efficient computing package for Genshin Impact gacha analysis

GGanalysisLite计算包 这个版本的计算包追求计算速度,而GGanalysis包有着更多计算功能。 GGanalysisLite包通过卷积计算分布列,通过FFT和快速幂加速卷积计算。 测试玩家得到的排名值rank的数学意义是:与抽了同样数量五星的其他玩家相比,测试玩家花费的抽数大于等于比例

一棵平衡树 34 Nov 26, 2022
This bot uploads telegram files to MixDrop.co,File.io.

What is about this bot ? This bot uploads telegram files to MixDrop.co, File.io. Usage: Send any file, and the bot will upload it to MixDrop.co, File.

Abhijith NT 3 Feb 26, 2022
Coffeematcher is a python library to randomly match participants for coffee meetings.

coffeematcher coffeematcher is a python library to randomly match participants for coffee meetings. Installation Clone the repository: git clone https

Thomas Wesselink 3 May 06, 2022
Load dependent libraries dynamically.

dypend dypend Load dependent libraries dynamically. A few days ago, I encountered many users feedback in an open source project. The Problem is they c

Louis 5 Mar 02, 2022
Py-Parser est un parser de code python en python encore en plien dévlopement.

PY - PARSER Py-Parser est un parser de code python en python encore en plien dévlopement. Une fois achevé, il servira a de nombreux projets comme glad

pf4 3 Feb 21, 2022
Python for downloading model data (HRRR, RAP, GFS, NBM, etc.) from NOMADS, NOAA's Big Data Program partners (Amazon, Google, Microsoft), and the University of Utah Pando Archive System.

Python for downloading model data (HRRR, RAP, GFS, NBM, etc.) from NOMADS, NOAA's Big Data Program partners (Amazon, Google, Microsoft), and the University of Utah Pando Archive System.

Brian Blaylock 194 Jan 02, 2023
Project Faros is a reference implimentation of Red Hat OpenShift 4 on small footprint, bare-metal clusters.

Project Faros Project Faros is a reference implimentation of Red Hat OpenShift 4 on small footprint, bare-metal clusters. The project includes referen

project: Faros 9 Jul 18, 2022
Sodium is a general purpose programming language which is instruction-oriented (a new programming concept that we are developing and devising) [Still developing...]

Sodium Programming Language Sodium is a general purpose programming language which is instruction-oriented (a new programming concept that we are deve

Instruction Oriented Programming 22 Jan 11, 2022
Traffic flow test platform, especially for reinforcement learning

Traffic Flow Test Platform Traffic flow test platform, especially for reinforcement learning, named TFTP. A traffic signal control framework that can

4 Nov 07, 2022
This project intends to take the user's CEP (brazilian adress code) and return the local in which the CEP is placed.

This project aims to simply return the CEP's (the brazilian resident adress code) User of the application. The project uses a request and passes on to

Daniel Soares Saldanha 4 Nov 17, 2021
My collection of mini-projects in various languages

Mini-Projects My collection of mini-projects in various languages About: This repository consists of a number of small projects. Most of these "mini-p

Siddhant Attavar 1 Jul 11, 2022