Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BSD 3-Clause License

Copyright (c) 2022, Mattias Lindvall
Copyright (c) 2025, Njorda AB
Based on work Copyright (c) 2022, Mattias Lindvall
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
30 changes: 1 addition & 29 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,4 @@ Install package from PyPI.

.. code-block:: text

pip install Flask-API-Framework


Links
-----

- Documentation_
- PyPI_
- Source_

.. _Documentation: https://flask-api-framework.readthedocs.io/
.. _PyPI: https://pypi.org/project/Flask-API-Framework/
.. _Source: https://github.com/thnee/flask-api-framework


.. |GitHub tests| image:: https://github.com/thnee/flask-api-framework/actions/workflows/tests.yml/badge.svg
:target: https://github.com/thnee/flask-api-framework/actions

.. |Documentation Status| image:: https://readthedocs.org/projects/flask-api-framework/badge/?version=latest
:target: https://flask-api-framework.readthedocs.io/en/latest/

.. |PyPI version| image:: https://img.shields.io/pypi/v/Flask-API-Framework?color=1283c4&label=version
:target: https://pypi.org/project/Flask-API-Framework/

.. |PyPI pyversions| image:: https://img.shields.io/pypi/pyversions/Flask-API-Framework.svg
:target: https://pypi.org/project/Flask-API-Framework/

.. |PyPI license| image:: https://img.shields.io/pypi/l/Flask-API-Framework.svg
:target: https://pypi.org/project/Flask-API-Framework/
pip install "git+https://github.com/deristrat/flask-api-framework.git@main"
14 changes: 7 additions & 7 deletions examples/complete_db/blueprints/api_v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AuthorsIndex(af.List, af.Create):
Same body schema for List and Create.
"""

body_schema = AuthorSchema()
body_schema = AuthorSchema

def get_instances(self):
return Author.query.all()
Expand All @@ -29,8 +29,8 @@ class AuthorsBooksList(af.List):
List all books for a specific author defined by a view arg.
"""

kwargs_schema = AuthorsBooksListKwargsSchema()
body_schema = BookListSchema()
kwargs_schema = AuthorsBooksListKwargsSchema
body_schema = BookListSchema

def get_instances(self):
q = Book.query
Expand All @@ -45,8 +45,8 @@ class BooksIndex(af.List, af.Create):
Different body schemas for List and Create.
"""

list_body_schema = BookListSchema()
create_body_schema = BookCreateSchema()
list_body_schema = BookListSchema
create_body_schema = BookCreateSchema

def get_instances(self):
return Book.query.all()
Expand All @@ -58,5 +58,5 @@ class BookDetail(af.Read, af.Update, af.Delete):
Same body schema for Read, Update, Delete.
"""

kwargs_schema = BookDetailKwargsSchema()
body_schema = BookDetailBodySchema()
kwargs_schema = BookDetailKwargsSchema
body_schema = BookDetailBodySchema
5 changes: 3 additions & 2 deletions examples/minimal_db/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Book(db.Model):
title = db.Column(db.String(100))


db.create_all()
with app.app_context():
db.create_all()


class BookSchema(ma.SQLAlchemyAutoSchema):
Expand All @@ -28,7 +29,7 @@ class Meta:


class Books(af.Create, af.List):
body_schema = BookSchema()
body_schema = BookSchema

def get_instances(self):
return Book.query.all()
Expand Down
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ addopts = '''
--quiet
tests/
'''
filterwarnings = [
"ignore:SQLALCHEMY_TRACK_MODIFICATIONS:flask_sqlalchemy.FSADeprecationWarning",
]
filterwarnings = []

[tool.coverage.report]
fail_under = 70
Expand All @@ -17,7 +15,7 @@ skip_covered = true

[tool.black]
line-length = 88
target-version = ["py37", "py38", "py39", "py310"]
target-version = ["py37", "py38", "py39", "py310", "py311"]
include = '\.pyi?$'
exclude = '''
/(
Expand All @@ -33,7 +31,7 @@ exclude = '''
[tool.isort]
profile = "black"
line_length = 88
py_version = "310"
py_version = "311"
lines_after_imports = 2
skip = [
".git",
Expand Down
31 changes: 14 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,34 @@

setuptools.setup(
name="Flask-API-Framework",
version="0.0.3",
version="0.0.4",
keywords="flask api framework",
description="Flask API Framework",
long_description="Please see the project links.",
project_urls={
"Documentation": "https://flask-api-framework.readthedocs.io/",
"Source": "https://github.com/thnee/flask-api-framework",
"Source": "https://github.com/deristrat/flask-api-framework",
},
license="BSD-3-Clause",
author="Mattias Lindvall",
author_email="mattias.lindvall@gmail.com",
package_dir={"": "src"},
packages=["flask_api_framework"],
python_requires=">=3.7",
install_requires=[
"flask >= 2.0.0",
"marshmallow >= 3.14.0",
"marshmallow ~= 3.18.0",
],
extras_require={
"test": [
"flask-sqlalchemy ~= 2.5.1",
"flask-sqlalchemy ~= 3.0.5",
"marshmallow-sqlalchemy ~= 0.28.0",
"flask-marshmallow ~= 0.14.0",
"pytest ~= 7.1.2",
"pytest-cov ~= 3.0.0",
"flake8 ~= 4.0.1",
"flake8-print ~= 5.0.0",
"flake8-bugbear ~= 22.4.25",
"black ~= 22.3.0",
"isort ~= 5.10.1",
"invoke ~= 1.7.1",
"tox ~= 3.25.0",
"flask-marshmallow ~= 0.15.0",
"pytest ~= 8.4.1",
"pytest-cov ~= 6.2.1",
"flake8 ~= 7.3.0",
"flake8-bugbear ~= 24.12.12",
"black ~= 23.12.1",
"isort ~= 6.0.1",
"invoke ~= 2.2.0",
"tox ~= 4.5.2",
],
"build": [
"wheel ~= 0.37.1",
Expand All @@ -55,6 +51,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development",
"Intended Audience :: Developers",
Expand Down
12 changes: 7 additions & 5 deletions src/flask_api_framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def dispatch_request(self, *args, **kwargs):
raise ApiError(status_code=400, source="body") from e

def load_kwargs_schema(self):
self.loaded_kwargs = self.kwargs_schema.load(data=flask.request.view_args)
self.loaded_kwargs = self.kwargs_schema().load(data=flask.request.view_args)

def load_args_schema(self):
self.loaded_args = self.args_schema.load(data=flask.request.args)
self.loaded_args = self.args_schema().load(data=flask.request.args)

def handle_kwargs(self, schema):
try:
Expand Down Expand Up @@ -111,7 +111,7 @@ def noop_data_wrapper(x):
data_wrapper = noop_data_wrapper
if schema is not None:
return (
flask.jsonify(data_wrapper(schema.dump(data, many=many))),
flask.jsonify(data_wrapper(schema().dump(data, many=many))),
status_code,
)
elif schema is None and data is not None:
Expand Down Expand Up @@ -195,7 +195,9 @@ def handle_post(self, *args, **kwargs):
return self.get_create_response()

def load_create_request_body_schema(self):
self.loaded_body = self.create_request_body_schema.load(data=flask.request.json)
self.loaded_body = self.create_request_body_schema().load(
data=flask.request.json
)

def create(self):
if is_sa_mapped(self.loaded_body):
Expand Down Expand Up @@ -249,7 +251,7 @@ def load_update_request_body_schema(self, partial):
)
if self.get_schema_load_instance(self.update_request_body_schema):
kwargs["instance"] = self.instance
self.loaded_body = self.update_request_body_schema.load(**kwargs)
self.loaded_body = self.update_request_body_schema().load(**kwargs)

def get_schema_load_instance(self, schema):
try:
Expand Down