console app builder
Project description
qr_server
This project is the extension of Flask project (https://pypi.org/project/Flask/), aimed on fast creation of web-apps with minimalistic syntax. The solution provides support for basic HTTP-routing (with file sending), fast DTOs (data transfer objects for formalization and validation of response data), simple jwt-token system, role manager (database-side rights system) and configurable logging. See 'example' directory for a minimal working application built using this library
Usage example:
from qr_server.Server import MethodResult, QRContext
from qr_server.Config import QRYamlConfig
from qr_server.TokenManager import require_token, JwtTokenManager
from qr_server.FlaskServer import FlaskServer
def login(ctx: QRContext):
login = ctx.json_data['login']
password = ctx.json_data['password']
user_id = ctx.repository.check_credentials(login, password)
if user_id is None:
return MethodResult('wrong credentials', 500)
user = ctx.repository.get_user_data(user_id)
if user is None:
return MethodResult('account not found', 500)
jwt_token = ctx.managers['token_manager'].make_token(user_id)
return MethodResult(JwtDTO(jwt_token))
@require_token()
def user_info(ctx: QRContext, user_id):
user = ctx.repository.get_user_data(user_id)
if user is None:
return MethodResult('account not found', 500)
return MethodResult(UserInfoDTO(**user))
class AuthServer(FlaskServer, AuthRepository):
"""DI class"""
if __name__ == "__main__":
config = QRYamlConfig()
config.read_config('config.yaml')
host = config['app']['host']
port = config['app']['port']
token_man = JwtTokenManager()
token_man.load_config(config['jwt'])
server = AuthServer()
server.init_server(config['app'])
if config['app']['logging']:
server.configure_logger(config['app']['logging'])
server.register_manager(token_man)
server.register_method('/login', login, 'POST')
server.register_method('/info', user_info, 'GET')
server.run(host, port)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
qr_server-1.0.10-py3-none-any.whl
(11.3 kB
view hashes)
Close
Hashes for qr_server-1.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1f20bd28cdf7f57fccd6894e6702d15aa46ae2e64677ec63613178bc0fc5adb |
|
MD5 | 861d53d7f85d51f03ea6449b3d2f16ae |
|
BLAKE2b-256 | 1206d3acdf0f5f7cabd3da7c2313ca0ebb748840a030aac0323b5f9253e3f471 |