Base for flask server
Project description
base for flask server by Mixel Te
dependencies
Python 3.12
alembic == 1.16.4
flask == 3.1.1
flask_jwt_extended == 4.7.1
PyMySQL == 1.1.1
sqlalchemy == 2.0.29
sqlalchemy_serializer == 1.4.22
werkzeug == 3.1.3
usage
scripts: bafser
init project: bafser init_project
run gunicorn -w 4 --threads 2 --worker-class gthread -b 0.0.0.0:80 main:app
or manually
copy bafser_config.example.py to project root as bafser_config.py
init alimbic bafser alembic init
create files:
.gitignore
.venv
*__pycache__*
/logs
/db
/images
/fonts
secret_key_jwt.txt
# data/_operations.py
from bafser import OperationsBase
class Operations(OperationsBase):
oper_id = ("oper_id", "Operation description")
oper_id2 = ("oper_id2", "Operation description")
...
# data/_roles.py
from bafser import RolesBase
from data._operations import Operations
class Roles(RolesBase):
# admin = 1 is already set for admin role
role_name = 2
role_name2 = 3
...
Roles.ROLES = {
# Roles.admin: {"name": "Admin", "operations": []} = 1 is auto created with all Operations
Roles.role_name: {
"name": "Role name",
"operations": [
Operations.oper_id,
Operations.oper_id2,
]
},
Roles.role_name2: {
"name": "Role name 2",
"operations": [
Operations.oper_id,
]
},
}
# data/_tables.py
from bafser import TablesBase
class Tables(TablesBase):
TableName = "TableName"
AnotherTableName = "AnotherTableName"
# data/user.py
from bafser import UserBase
class User(UserBase):
def __repr__(self):
return f"<{self.__class__.__name__}> [{self.id}] {self.login}"
# data/some_table.py
from bafser import SqlAlchemyBase, ObjMixin
from data._tables import Tables
class SomeTable(SqlAlchemyBase, ObjMixin):
__tablename__ = Tables.SomeTable
...
IdMixinaddsidcolumnObjMixinaddsidanddeletedcolumnsSingletonMixinaddsidcolumn
Mixins add get methods also
# main.py
import sys
from bafser import AppConfig, create_app
from scripts.init_dev_values import init_dev_values
app, run = create_app(__name__, AppConfig(
MESSAGE_TO_FRONTEND="",
DEV_MODE="dev" in sys.argv,
DELAY_MODE="delay" in sys.argv,
)
.add_data_folder("FONTS_FOLDER", "fonts")
.add_secret_key("API_SECRET_KEY", "secret_key_api.txt")
)
run(__name__ == "__main__", None, init_dev_values)
modifying User and Image
User:
from typing import Any, override
from sqlalchemy.orm import Session, Mapped, mapped_column
from bafser import UserBase, UserKwargs
from data._roles import Roles
class User(UserBase):
newColumn: Mapped[str]
@classmethod
@override
def new(cls, creator: UserBase, login: str, password: str, name: str, roles: list[int], newColumn: str, *, db_sess: Session | None = None):
return super().new(creator, login, password, name, roles, db_sess=db_sess, newColumn=newColumn)
@classmethod
@override
def _new(cls, db_sess: Session, user_kwargs: UserKwargs, *, newColumn: str, **kwargs: Any):
user = User(**user_kwargs, newColumn=newColumn)
changes = [("newColumn", newColumn)]
return user, changes
@classmethod
@override
def create_admin(cls, db_sess: Session):
fake_creator = User.get_fake_system()
return User.new(fake_creator, "admin", "admin", "Admin", [Roles.admin], "newColumnValue", db_sess=db_sess)
Image:
from typing import TypedDict, override
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column
from bafser import Image as ImageBase, ImageKwargs, get_json_values
from test.data.user import User
class ImageJson(TypedDict):
data: str
name: str
newColumnData: str
class Img(ImageBase):
newColumn: Mapped[str]
@classmethod
@override
def new(cls, creator: User, json: ImageJson): # type: ignore
return super().new(creator, json)
@classmethod
@override
def _new(cls, creator: User, json: ImageJson, image_kwargs: ImageKwargs): # type: ignore
newColumnData, values_error = get_json_values(json, ("newColumnData", str))
if values_error:
return None, None, values_error
img = Img(**image_kwargs, newColumn=newColumnData)
changes = [("newColumn", newColumn)]
return img, changes, None
csv header for requests log
reqid;ip;uid;asctime;method;url;message;code;json
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bafser-2.8.3.tar.gz.
File metadata
- Download URL: bafser-2.8.3.tar.gz
- Upload date:
- Size: 62.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e05a9ab9f66cd6ec593736e0fe8b65dd327a38fb43001da9b9d895643a1194c
|
|
| MD5 |
3762b7cf9aa0159ea7bf125941092146
|
|
| BLAKE2b-256 |
4240dfcd2b789bfce22ab5827fee8a86d3a16d161dbc8f203d2facbf9039fd0d
|
Provenance
The following attestation bundles were made for bafser-2.8.3.tar.gz:
Publisher:
main.yml on MixelTe/bafser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bafser-2.8.3.tar.gz -
Subject digest:
4e05a9ab9f66cd6ec593736e0fe8b65dd327a38fb43001da9b9d895643a1194c - Sigstore transparency entry: 983525393
- Sigstore integration time:
-
Permalink:
MixelTe/bafser@56b760654be1b08619e24d50da146232cf2d6599 -
Branch / Tag:
refs/tags/v2.8.3 - Owner: https://github.com/MixelTe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@56b760654be1b08619e24d50da146232cf2d6599 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bafser-2.8.3-py3-none-any.whl.
File metadata
- Download URL: bafser-2.8.3-py3-none-any.whl
- Upload date:
- Size: 76.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb3aeff692de0013ffc6feca3cdb6dda9808b98d64e4070c35b8c5e348488cac
|
|
| MD5 |
f6481f80380def361ce6f8a39b6cdd71
|
|
| BLAKE2b-256 |
697603c06e70408976ca5c6f00ec48273c7db878d66de3ca53ed8d9837d6bd7c
|
Provenance
The following attestation bundles were made for bafser-2.8.3-py3-none-any.whl:
Publisher:
main.yml on MixelTe/bafser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bafser-2.8.3-py3-none-any.whl -
Subject digest:
fb3aeff692de0013ffc6feca3cdb6dda9808b98d64e4070c35b8c5e348488cac - Sigstore transparency entry: 983525407
- Sigstore integration time:
-
Permalink:
MixelTe/bafser@56b760654be1b08619e24d50da146232cf2d6599 -
Branch / Tag:
refs/tags/v2.8.3 - Owner: https://github.com/MixelTe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@56b760654be1b08619e24d50da146232cf2d6599 -
Trigger Event:
push
-
Statement type: