pboot 3.2.0__tar.gz → 4.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pboot-4.0.0/CHANGES.rst +31 -0
- {pboot-3.2.0/examples/tutorial → pboot-4.0.0}/LICENSE.txt +26 -2
- pboot-4.0.0/PKG-INFO +213 -0
- pboot-4.0.0/README.md +158 -0
- pboot-4.0.0/docs/_static/pboot-logo.svg +18 -0
- pboot-4.0.0/docs/migration-from-flask.md +159 -0
- pboot-4.0.0/examples/api/app.py +57 -0
- pboot-4.0.0/examples/basic/app.py +28 -0
- pboot-4.0.0/examples/templates/app.py +38 -0
- pboot-4.0.0/examples/templates/templates/index.html +23 -0
- pboot-4.0.0/pyproject.toml +169 -0
- {pboot-3.2.0 → pboot-4.0.0}/src/pboot/__init__.py +37 -1
- pboot-4.0.0/src/pboot/__main__.py +3 -0
- pboot-4.0.0/src/pboot/_body_limit.py +101 -0
- pboot-4.0.0/src/pboot/_compat/__init__.py +40 -0
- pboot-4.0.0/src/pboot/_compat/shared.py +222 -0
- pboot-4.0.0/src/pboot/_compat/v2.py +522 -0
- pboot-4.0.0/src/pboot/_datastructures.py +90 -0
- pboot-4.0.0/src/pboot/_form_limits.py +27 -0
- pboot-4.0.0/src/pboot/_import.py +30 -0
- pboot-4.0.0/src/pboot/_local.py +118 -0
- pboot-4.0.0/src/pboot/app.py +11 -0
- pboot-4.0.0/src/pboot/applications.py +5137 -0
- pboot-4.0.0/src/pboot/background.py +67 -0
- pboot-4.0.0/src/pboot/blueprints.py +428 -0
- pboot-4.0.0/src/pboot/cli.py +536 -0
- pboot-4.0.0/src/pboot/compat.py +1056 -0
- pboot-4.0.0/src/pboot/concurrency.py +99 -0
- pboot-4.0.0/src/pboot/config.py +244 -0
- pboot-4.0.0/src/pboot/ctx.py +318 -0
- pboot-4.0.0/src/pboot/datastructures.py +186 -0
- {pboot-3.2.0 → pboot-4.0.0}/src/pboot/debughelpers.py +58 -70
- pboot-4.0.0/src/pboot/dependencies/models.py +245 -0
- pboot-4.0.0/src/pboot/dependencies/utils.py +1513 -0
- pboot-4.0.0/src/pboot/encoders.py +366 -0
- pboot-4.0.0/src/pboot/exception_handlers.py +34 -0
- pboot-4.0.0/src/pboot/exceptions.py +256 -0
- pboot-4.0.0/src/pboot/globals.py +85 -0
- pboot-4.0.0/src/pboot/helpers.py +332 -0
- pboot-4.0.0/src/pboot/json/__init__.py +81 -0
- pboot-4.0.0/src/pboot/json/provider.py +186 -0
- {pboot-3.2.0 → pboot-4.0.0}/src/pboot/json/tag.py +4 -4
- pboot-4.0.0/src/pboot/logger.py +3 -0
- pboot-4.0.0/src/pboot/logging.py +79 -0
- pboot-4.0.0/src/pboot/middleware/__init__.py +1 -0
- pboot-4.0.0/src/pboot/middleware/asyncexitstack.py +18 -0
- pboot-4.0.0/src/pboot/middleware/cors.py +1 -0
- pboot-4.0.0/src/pboot/middleware/gzip.py +1 -0
- pboot-4.0.0/src/pboot/middleware/httpsredirect.py +3 -0
- pboot-4.0.0/src/pboot/middleware/trustedhost.py +3 -0
- pboot-4.0.0/src/pboot/middleware/wsgi.py +3 -0
- pboot-4.0.0/src/pboot/openapi/constants.py +3 -0
- pboot-4.0.0/src/pboot/openapi/docs.py +389 -0
- pboot-4.0.0/src/pboot/openapi/models.py +435 -0
- pboot-4.0.0/src/pboot/openapi/utils.py +671 -0
- pboot-4.0.0/src/pboot/param_functions.py +2605 -0
- pboot-4.0.0/src/pboot/params.py +822 -0
- pboot-4.0.0/src/pboot/requests.py +2 -0
- pboot-4.0.0/src/pboot/responses.py +98 -0
- pboot-4.0.0/src/pboot/routing.py +6963 -0
- pboot-4.0.0/src/pboot/sansio/__init__.py +6 -0
- pboot-4.0.0/src/pboot/sansio/app.py +11 -0
- pboot-4.0.0/src/pboot/sansio/blueprints.py +7 -0
- pboot-4.0.0/src/pboot/sansio/scaffold.py +12 -0
- pboot-4.0.0/src/pboot/security/__init__.py +15 -0
- pboot-4.0.0/src/pboot/security/api_key.py +320 -0
- pboot-4.0.0/src/pboot/security/base.py +6 -0
- pboot-4.0.0/src/pboot/security/http.py +423 -0
- pboot-4.0.0/src/pboot/security/oauth2.py +693 -0
- pboot-4.0.0/src/pboot/security/open_id_connect_url.py +94 -0
- pboot-4.0.0/src/pboot/security/utils.py +7 -0
- pboot-4.0.0/src/pboot/sessions.py +295 -0
- {pboot-3.2.0 → pboot-4.0.0}/src/pboot/signals.py +19 -0
- pboot-4.0.0/src/pboot/sse.py +241 -0
- pboot-4.0.0/src/pboot/staticfiles.py +1 -0
- pboot-4.0.0/src/pboot/telemetry/__init__.py +3 -0
- pboot-4.0.0/src/pboot/telemetry/_api.py +280 -0
- pboot-4.0.0/src/pboot/telemetry/_asgi.py +457 -0
- pboot-4.0.0/src/pboot/telemetry/_runtime.py +238 -0
- pboot-4.0.0/src/pboot/templating.py +168 -0
- pboot-4.0.0/src/pboot/testclient.py +1 -0
- pboot-4.0.0/src/pboot/testing.py +197 -0
- pboot-4.0.0/src/pboot/types.py +12 -0
- {pboot-3.2.0 → pboot-4.0.0}/src/pboot/typing.py +34 -16
- pboot-4.0.0/src/pboot/utils.py +136 -0
- pboot-4.0.0/src/pboot/views.py +142 -0
- pboot-4.0.0/src/pboot/websockets.py +3 -0
- pboot-4.0.0/src/pboot/wrappers.py +144 -0
- pboot-4.0.0/tests/conftest.py +93 -0
- pboot-4.0.0/tests/templates/hello.html +3 -0
- pboot-4.0.0/tests/test_appctx.py +76 -0
- pboot-4.0.0/tests/test_basic.py +407 -0
- pboot-4.0.0/tests/test_blueprints.py +209 -0
- pboot-4.0.0/tests/test_cli.py +109 -0
- pboot-4.0.0/tests/test_compat_api.py +185 -0
- pboot-4.0.0/tests/test_config.py +136 -0
- pboot-4.0.0/tests/test_error_handlers.py +93 -0
- pboot-4.0.0/tests/test_fastapi.py +173 -0
- pboot-4.0.0/tests/test_helpers.py +170 -0
- pboot-4.0.0/tests/test_json.py +93 -0
- pboot-4.0.0/tests/test_reqctx.py +150 -0
- pboot-4.0.0/tests/test_session.py +98 -0
- pboot-4.0.0/tests/test_signals.py +118 -0
- pboot-4.0.0/tests/test_templating.py +125 -0
- pboot-4.0.0/tests/test_testing.py +111 -0
- pboot-4.0.0/tests/test_views.py +83 -0
- pboot-3.2.0/CHANGES.rst +0 -1667
- pboot-3.2.0/LICENSE.txt +0 -28
- pboot-3.2.0/PKG-INFO +0 -194
- pboot-3.2.0/README.md +0 -158
- pboot-3.2.0/docs/Makefile +0 -20
- pboot-3.2.0/docs/PUBLISHING.md +0 -80
- pboot-3.2.0/docs/_static/debugger.png +0 -0
- pboot-3.2.0/docs/_static/pboot-icon.svg +0 -15
- pboot-3.2.0/docs/_static/pboot-logo.png +0 -0
- pboot-3.2.0/docs/_static/pboot-logo.svg +0 -27
- pboot-3.2.0/docs/_static/pboot-name.svg +0 -23
- pboot-3.2.0/docs/_static/pycharm-run-config.png +0 -0
- pboot-3.2.0/docs/api.rst +0 -708
- pboot-3.2.0/docs/appcontext.rst +0 -187
- pboot-3.2.0/docs/async-await.rst +0 -119
- pboot-3.2.0/docs/blueprints.rst +0 -315
- pboot-3.2.0/docs/changes.rst +0 -4
- pboot-3.2.0/docs/cli.rst +0 -556
- pboot-3.2.0/docs/conf.py +0 -101
- pboot-3.2.0/docs/config.rst +0 -839
- pboot-3.2.0/docs/contributing.rst +0 -8
- pboot-3.2.0/docs/debugging.rst +0 -99
- pboot-3.2.0/docs/deploying/apache-httpd.rst +0 -66
- pboot-3.2.0/docs/deploying/asgi.rst +0 -27
- pboot-3.2.0/docs/deploying/eventlet.rst +0 -8
- pboot-3.2.0/docs/deploying/gevent.rst +0 -76
- pboot-3.2.0/docs/deploying/gunicorn.rst +0 -116
- pboot-3.2.0/docs/deploying/index.rst +0 -78
- pboot-3.2.0/docs/deploying/mod_wsgi.rst +0 -94
- pboot-3.2.0/docs/deploying/nginx.rst +0 -69
- pboot-3.2.0/docs/deploying/proxy_fix.rst +0 -33
- pboot-3.2.0/docs/deploying/uwsgi.rst +0 -143
- pboot-3.2.0/docs/deploying/waitress.rst +0 -75
- pboot-3.2.0/docs/design.rst +0 -229
- pboot-3.2.0/docs/errorhandling.rst +0 -523
- pboot-3.2.0/docs/extensiondev.rst +0 -305
- pboot-3.2.0/docs/extensions.rst +0 -48
- pboot-3.2.0/docs/gevent.rst +0 -125
- pboot-3.2.0/docs/index.rst +0 -89
- pboot-3.2.0/docs/installation.rst +0 -143
- pboot-3.2.0/docs/license.rst +0 -5
- pboot-3.2.0/docs/lifecycle.rst +0 -171
- pboot-3.2.0/docs/logging.rst +0 -183
- pboot-3.2.0/docs/make.bat +0 -35
- pboot-3.2.0/docs/patterns/appdispatch.rst +0 -189
- pboot-3.2.0/docs/patterns/appfactories.rst +0 -118
- pboot-3.2.0/docs/patterns/caching.rst +0 -16
- pboot-3.2.0/docs/patterns/celery.rst +0 -242
- pboot-3.2.0/docs/patterns/deferredcallbacks.rst +0 -44
- pboot-3.2.0/docs/patterns/favicon.rst +0 -56
- pboot-3.2.0/docs/patterns/fileuploads.rst +0 -182
- pboot-3.2.0/docs/patterns/flashing.rst +0 -148
- pboot-3.2.0/docs/patterns/index.rst +0 -40
- pboot-3.2.0/docs/patterns/javascript.rst +0 -261
- pboot-3.2.0/docs/patterns/jquery.rst +0 -6
- pboot-3.2.0/docs/patterns/lazyloading.rst +0 -109
- pboot-3.2.0/docs/patterns/methodoverrides.rst +0 -42
- pboot-3.2.0/docs/patterns/mongoengine.rst +0 -102
- pboot-3.2.0/docs/patterns/packages.rst +0 -133
- pboot-3.2.0/docs/patterns/requestchecksum.rst +0 -55
- pboot-3.2.0/docs/patterns/singlepageapplications.rst +0 -24
- pboot-3.2.0/docs/patterns/sqlalchemy.rst +0 -213
- pboot-3.2.0/docs/patterns/sqlite3.rst +0 -147
- pboot-3.2.0/docs/patterns/streaming.rst +0 -100
- pboot-3.2.0/docs/patterns/subclassing.rst +0 -17
- pboot-3.2.0/docs/patterns/templateinheritance.rst +0 -68
- pboot-3.2.0/docs/patterns/urlprocessors.rst +0 -126
- pboot-3.2.0/docs/patterns/viewdecorators.rst +0 -171
- pboot-3.2.0/docs/patterns/wtforms.rst +0 -126
- pboot-3.2.0/docs/quickstart.rst +0 -858
- pboot-3.2.0/docs/reqcontext.rst +0 -6
- pboot-3.2.0/docs/server.rst +0 -115
- pboot-3.2.0/docs/shell.rst +0 -81
- pboot-3.2.0/docs/signals.rst +0 -166
- pboot-3.2.0/docs/templating.rst +0 -261
- pboot-3.2.0/docs/testing.rst +0 -318
- pboot-3.2.0/docs/tutorial/blog.rst +0 -336
- pboot-3.2.0/docs/tutorial/database.rst +0 -219
- pboot-3.2.0/docs/tutorial/deploy.rst +0 -111
- pboot-3.2.0/docs/tutorial/factory.rst +0 -159
- pboot-3.2.0/docs/tutorial/index.rst +0 -64
- pboot-3.2.0/docs/tutorial/install.rst +0 -89
- pboot-3.2.0/docs/tutorial/layout.rst +0 -105
- pboot-3.2.0/docs/tutorial/next.rst +0 -38
- pboot-3.2.0/docs/tutorial/pbootr_edit.png +0 -0
- pboot-3.2.0/docs/tutorial/pbootr_index.png +0 -0
- pboot-3.2.0/docs/tutorial/pbootr_login.png +0 -0
- pboot-3.2.0/docs/tutorial/static.rst +0 -72
- pboot-3.2.0/docs/tutorial/templates.rst +0 -187
- pboot-3.2.0/docs/tutorial/tests.rst +0 -559
- pboot-3.2.0/docs/tutorial/views.rst +0 -305
- pboot-3.2.0/docs/views.rst +0 -324
- pboot-3.2.0/docs/web-security.rst +0 -316
- pboot-3.2.0/examples/celery/README.md +0 -27
- pboot-3.2.0/examples/celery/make_celery.py +0 -4
- pboot-3.2.0/examples/celery/pyproject.toml +0 -22
- pboot-3.2.0/examples/celery/requirements.txt +0 -58
- pboot-3.2.0/examples/celery/src/task_app/__init__.py +0 -39
- pboot-3.2.0/examples/celery/src/task_app/tasks.py +0 -23
- pboot-3.2.0/examples/celery/src/task_app/templates/index.html +0 -108
- pboot-3.2.0/examples/celery/src/task_app/views.py +0 -38
- pboot-3.2.0/examples/javascript/.gitignore +0 -14
- pboot-3.2.0/examples/javascript/LICENSE.txt +0 -28
- pboot-3.2.0/examples/javascript/README.rst +0 -48
- pboot-3.2.0/examples/javascript/js_example/__init__.py +0 -5
- pboot-3.2.0/examples/javascript/js_example/templates/base.html +0 -33
- pboot-3.2.0/examples/javascript/js_example/templates/fetch.html +0 -33
- pboot-3.2.0/examples/javascript/js_example/templates/jquery.html +0 -27
- pboot-3.2.0/examples/javascript/js_example/templates/xhr.html +0 -29
- pboot-3.2.0/examples/javascript/js_example/views.py +0 -18
- pboot-3.2.0/examples/javascript/pyproject.toml +0 -38
- pboot-3.2.0/examples/javascript/tests/conftest.py +0 -15
- pboot-3.2.0/examples/javascript/tests/test_js_example.py +0 -27
- pboot-3.2.0/examples/tutorial/.gitignore +0 -14
- pboot-3.2.0/examples/tutorial/README.rst +0 -68
- pboot-3.2.0/examples/tutorial/pbootr/__init__.py +0 -48
- pboot-3.2.0/examples/tutorial/pbootr/auth.py +0 -116
- pboot-3.2.0/examples/tutorial/pbootr/blog.py +0 -125
- pboot-3.2.0/examples/tutorial/pbootr/db.py +0 -56
- pboot-3.2.0/examples/tutorial/pbootr/schema.sql +0 -20
- pboot-3.2.0/examples/tutorial/pbootr/static/style.css +0 -134
- pboot-3.2.0/examples/tutorial/pbootr/templates/auth/login.html +0 -15
- pboot-3.2.0/examples/tutorial/pbootr/templates/auth/register.html +0 -15
- pboot-3.2.0/examples/tutorial/pbootr/templates/base.html +0 -24
- pboot-3.2.0/examples/tutorial/pbootr/templates/blog/create.html +0 -15
- pboot-3.2.0/examples/tutorial/pbootr/templates/blog/index.html +0 -28
- pboot-3.2.0/examples/tutorial/pbootr/templates/blog/update.html +0 -19
- pboot-3.2.0/examples/tutorial/pyproject.toml +0 -45
- pboot-3.2.0/examples/tutorial/tests/conftest.py +0 -62
- pboot-3.2.0/examples/tutorial/tests/data.sql +0 -8
- pboot-3.2.0/examples/tutorial/tests/test_auth.py +0 -69
- pboot-3.2.0/examples/tutorial/tests/test_blog.py +0 -83
- pboot-3.2.0/examples/tutorial/tests/test_db.py +0 -29
- pboot-3.2.0/examples/tutorial/tests/test_factory.py +0 -12
- pboot-3.2.0/pyproject.toml +0 -272
- pboot-3.2.0/src/pboot/__main__.py +0 -3
- pboot-3.2.0/src/pboot/app.py +0 -1686
- pboot-3.2.0/src/pboot/blueprints.py +0 -128
- pboot-3.2.0/src/pboot/cli.py +0 -1126
- pboot-3.2.0/src/pboot/config.py +0 -367
- pboot-3.2.0/src/pboot/ctx.py +0 -540
- pboot-3.2.0/src/pboot/globals.py +0 -77
- pboot-3.2.0/src/pboot/helpers.py +0 -679
- pboot-3.2.0/src/pboot/json/__init__.py +0 -170
- pboot-3.2.0/src/pboot/json/provider.py +0 -215
- pboot-3.2.0/src/pboot/logging.py +0 -79
- pboot-3.2.0/src/pboot/sansio/README.md +0 -6
- pboot-3.2.0/src/pboot/sansio/app.py +0 -1014
- pboot-3.2.0/src/pboot/sansio/blueprints.py +0 -692
- pboot-3.2.0/src/pboot/sansio/scaffold.py +0 -800
- pboot-3.2.0/src/pboot/sessions.py +0 -385
- pboot-3.2.0/src/pboot/templating.py +0 -212
- pboot-3.2.0/src/pboot/testing.py +0 -298
- pboot-3.2.0/src/pboot/views.py +0 -191
- pboot-3.2.0/src/pboot/wrappers.py +0 -255
- pboot-3.2.0/tests/conftest.py +0 -112
- pboot-3.2.0/tests/static/config.json +0 -4
- pboot-3.2.0/tests/static/config.toml +0 -2
- pboot-3.2.0/tests/static/index.html +0 -1
- pboot-3.2.0/tests/templates/_macro.html +0 -1
- pboot-3.2.0/tests/templates/context_template.html +0 -1
- pboot-3.2.0/tests/templates/escaping_template.html +0 -6
- pboot-3.2.0/tests/templates/mail.txt +0 -1
- pboot-3.2.0/tests/templates/nested/nested.txt +0 -1
- pboot-3.2.0/tests/templates/non_escaping_template.txt +0 -8
- pboot-3.2.0/tests/templates/simple_template.html +0 -1
- pboot-3.2.0/tests/templates/template_filter.html +0 -1
- pboot-3.2.0/tests/templates/template_test.html +0 -3
- pboot-3.2.0/tests/test_appctx.py +0 -259
- pboot-3.2.0/tests/test_apps/.env +0 -4
- pboot-3.2.0/tests/test_apps/.pbootenv +0 -3
- pboot-3.2.0/tests/test_apps/blueprintapp/__init__.py +0 -9
- pboot-3.2.0/tests/test_apps/blueprintapp/apps/admin/__init__.py +0 -20
- pboot-3.2.0/tests/test_apps/blueprintapp/apps/admin/static/css/test.css +0 -1
- pboot-3.2.0/tests/test_apps/blueprintapp/apps/admin/static/test.txt +0 -1
- pboot-3.2.0/tests/test_apps/blueprintapp/apps/admin/templates/admin/index.html +0 -1
- pboot-3.2.0/tests/test_apps/blueprintapp/apps/frontend/__init__.py +0 -14
- pboot-3.2.0/tests/test_apps/blueprintapp/apps/frontend/templates/frontend/index.html +0 -1
- pboot-3.2.0/tests/test_apps/cliapp/app.py +0 -3
- pboot-3.2.0/tests/test_apps/cliapp/factory.py +0 -13
- pboot-3.2.0/tests/test_apps/cliapp/importerrorapp.py +0 -5
- pboot-3.2.0/tests/test_apps/cliapp/inner1/__init__.py +0 -3
- pboot-3.2.0/tests/test_apps/cliapp/inner1/inner2/__init__.py +0 -0
- pboot-3.2.0/tests/test_apps/cliapp/inner1/inner2/pboot.py +0 -3
- pboot-3.2.0/tests/test_apps/cliapp/message.txt +0 -1
- pboot-3.2.0/tests/test_apps/cliapp/multiapp.py +0 -4
- pboot-3.2.0/tests/test_apps/helloworld/hello.py +0 -8
- pboot-3.2.0/tests/test_apps/helloworld/wsgi.py +0 -1
- pboot-3.2.0/tests/test_apps/subdomaintestmodule/__init__.py +0 -3
- pboot-3.2.0/tests/test_apps/subdomaintestmodule/static/hello.txt +0 -1
- pboot-3.2.0/tests/test_async.py +0 -145
- pboot-3.2.0/tests/test_basic.py +0 -1974
- pboot-3.2.0/tests/test_blueprints.py +0 -1115
- pboot-3.2.0/tests/test_cli.py +0 -703
- pboot-3.2.0/tests/test_config.py +0 -250
- pboot-3.2.0/tests/test_converters.py +0 -42
- pboot-3.2.0/tests/test_helpers.py +0 -377
- pboot-3.2.0/tests/test_instance_config.py +0 -111
- pboot-3.2.0/tests/test_json.py +0 -346
- pboot-3.2.0/tests/test_json_tag.py +0 -86
- pboot-3.2.0/tests/test_logging.py +0 -98
- pboot-3.2.0/tests/test_regression.py +0 -30
- pboot-3.2.0/tests/test_reqctx.py +0 -249
- pboot-3.2.0/tests/test_request.py +0 -70
- pboot-3.2.0/tests/test_session_interface.py +0 -28
- pboot-3.2.0/tests/test_signals.py +0 -181
- pboot-3.2.0/tests/test_subclassing.py +0 -21
- pboot-3.2.0/tests/test_templating.py +0 -532
- pboot-3.2.0/tests/test_testing.py +0 -398
- pboot-3.2.0/tests/test_user_error_handler.py +0 -295
- pboot-3.2.0/tests/test_views.py +0 -271
- pboot-3.2.0/tests/type_check/typing_app_decorators.py +0 -32
- pboot-3.2.0/tests/type_check/typing_error_handler.py +0 -33
- pboot-3.2.0/tests/type_check/typing_route.py +0 -112
- pboot-3.2.0/uv.lock +0 -1644
- {pboot-3.2.0/tests/test_apps/blueprintapp/apps → pboot-4.0.0/src/pboot/dependencies}/__init__.py +0 -0
- {pboot-3.2.0/tests/test_apps/cliapp → pboot-4.0.0/src/pboot/openapi}/__init__.py +0 -0
- {pboot-3.2.0 → pboot-4.0.0}/src/pboot/py.typed +0 -0
pboot-4.0.0/CHANGES.rst
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Version 4.0.0
|
|
2
|
+
-------------
|
|
3
|
+
|
|
4
|
+
Released 2026-12-02
|
|
5
|
+
|
|
6
|
+
- The framework core is rebuilt on FastAPI, Starlette and Pydantic.
|
|
7
|
+
The WSGI layer, Werkzeug dependency and Flask compatibility shim of
|
|
8
|
+
Pboot 3.x are replaced by an ASGI stack.
|
|
9
|
+
|
|
10
|
+
- The application class keeps the Flask style API, and adds the FastAPI
|
|
11
|
+
features: type driven validation, dependency injection, automatic
|
|
12
|
+
OpenAPI schema and interactive documentation.
|
|
13
|
+
|
|
14
|
+
- Two routing styles can be mixed in one application. Paths that use the
|
|
15
|
+
Flask syntax, such as ``/users/<int:user_id>``, are registered as
|
|
16
|
+
Flask style routes. Paths that use the FastAPI syntax, such as
|
|
17
|
+
``/users/{user_id}``, are registered as API routes.
|
|
18
|
+
|
|
19
|
+
- The request body is read asynchronously. ``await request.form()``,
|
|
20
|
+
``await request.json()`` and ``await request.values()`` replace the
|
|
21
|
+
synchronous attributes of Pboot 3.x.
|
|
22
|
+
|
|
23
|
+
- The development server is uvicorn. ``pboot run`` accepts ``--host``,
|
|
24
|
+
``--port``, ``--reload``, ``--workers`` and ``--root-path``.
|
|
25
|
+
|
|
26
|
+
- The test client is backed by Starlette's ``TestClient`` and keeps the
|
|
27
|
+
Flask style ``data``, ``status_code``, ``headers`` and ``json()``
|
|
28
|
+
attributes.
|
|
29
|
+
|
|
30
|
+
- Werkzeug is no longer a dependency. The few helpers that were used
|
|
31
|
+
from it live in ``pboot._datastructures`` now.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
Copyright 2010 Pallets
|
|
2
|
+
Copyright 2018 Sebastián Ramírez
|
|
3
|
+
Copyright 2026 pboot-org
|
|
2
4
|
|
|
3
5
|
Redistribution and use in source and binary forms, with or without
|
|
4
6
|
modification, are permitted provided that the following conditions are
|
|
@@ -17,8 +19,8 @@ met:
|
|
|
17
19
|
|
|
18
20
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
19
21
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
20
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
21
|
-
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
22
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
23
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
22
24
|
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
23
25
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
24
26
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
@@ -26,3 +28,25 @@ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
26
28
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
27
29
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
28
30
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
|
|
32
|
+
------------------------------------------------------------------------
|
|
33
|
+
Pboot 4.0 及之后的代码源自 FastAPI(MIT License, Copyright 2018
|
|
34
|
+
Sebastián Ramírez),FastAPI 部分按 MIT 协议分发:
|
|
35
|
+
|
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
37
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
38
|
+
in the Software without restriction, including without limitation the rights
|
|
39
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
40
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
41
|
+
furnished to do so, subject to the following conditions:
|
|
42
|
+
|
|
43
|
+
The above copyright notice and this permission notice shall be included in all
|
|
44
|
+
copies or substantial portions of the Software.
|
|
45
|
+
|
|
46
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
47
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
48
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
49
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
50
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
51
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
52
|
+
SOFTWARE.
|
pboot-4.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pboot
|
|
3
|
+
Version: 4.0.0
|
|
4
|
+
Summary: A Pydantic/FastAPI-based framework for building complex web applications.
|
|
5
|
+
Keywords: web,framework,asgi,fastapi,flask,pydantic,starlette
|
|
6
|
+
Maintainer: pboot-org
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-Expression: BSD-3-Clause
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Environment :: Web Environment
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
16
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
17
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
18
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Session
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
20
|
+
Classifier: Framework :: AsyncIO
|
|
21
|
+
Classifier: Framework :: AnyIO
|
|
22
|
+
Classifier: Framework :: FastAPI
|
|
23
|
+
Classifier: Framework :: Flask
|
|
24
|
+
Classifier: Framework :: Pydantic
|
|
25
|
+
Classifier: Framework :: Pydantic :: 2
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
License-File: LICENSE.txt
|
|
28
|
+
Requires-Dist: starlette>=1.6.0
|
|
29
|
+
Requires-Dist: anyio>=4.1.0
|
|
30
|
+
Requires-Dist: pydantic>=2.9.0
|
|
31
|
+
Requires-Dist: typing-extensions>=4.8.0
|
|
32
|
+
Requires-Dist: typing-inspection>=0.4.2
|
|
33
|
+
Requires-Dist: annotated-doc>=0.0.2
|
|
34
|
+
Requires-Dist: opentelemetry-api>=1.44.0
|
|
35
|
+
Requires-Dist: jinja2>=3.1.2
|
|
36
|
+
Requires-Dist: itsdangerous>=2.2.0
|
|
37
|
+
Requires-Dist: click>=8.1.3
|
|
38
|
+
Requires-Dist: blinker>=1.9.0
|
|
39
|
+
Requires-Dist: httpx2>=2.0.0
|
|
40
|
+
Requires-Dist: python-dotenv ; extra == "dotenv"
|
|
41
|
+
Requires-Dist: uvicorn[standard]>=0.30 ; extra == "standard"
|
|
42
|
+
Requires-Dist: httpx>=0.23.0,<1.0.0 ; extra == "standard"
|
|
43
|
+
Requires-Dist: httpx2>=2.0.0 ; extra == "standard"
|
|
44
|
+
Requires-Dist: python-multipart>=0.0.18 ; extra == "standard"
|
|
45
|
+
Requires-Dist: email-validator>=2.0.0 ; extra == "standard"
|
|
46
|
+
Project-URL: Changes, https://gitee.com/pboot-org/pboot/blob/main/CHANGES.rst
|
|
47
|
+
Project-URL: Chat, https://gitee.com/pboot-org/pboot/issues
|
|
48
|
+
Project-URL: Documentation, https://gitee.com/pboot-org/pboot
|
|
49
|
+
Project-URL: Donate, https://gitee.com/pboot-org/pboot
|
|
50
|
+
Project-URL: Homepage, https://gitee.com/pboot-org/pboot
|
|
51
|
+
Project-URL: Source, https://gitee.com/pboot-org/pboot/
|
|
52
|
+
Provides-Extra: dotenv
|
|
53
|
+
Provides-Extra: standard
|
|
54
|
+
|
|
55
|
+
<div align="center">
|
|
56
|
+
<img src="docs/_static/pboot-logo.svg" alt="Pboot" height="140">
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
# Pboot
|
|
60
|
+
|
|
61
|
+
**Pboot** 是一个基于 [FastAPI] / [Starlette] / [Pydantic] 的现代 ASGI Web 应用框架,
|
|
62
|
+
在保留 Flask 风格易用 API 的同时,获得异步运行时、类型驱动校验与自动 OpenAPI 文档。
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from pboot import Pboot
|
|
66
|
+
|
|
67
|
+
app = Pboot(__name__)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@app.get("/")
|
|
71
|
+
async def hello():
|
|
72
|
+
return "Hello, Pboot!"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```console
|
|
76
|
+
$ pboot run
|
|
77
|
+
* Running on http://127.0.0.1:8000/ (Press CTRL+C to quit)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 特性
|
|
81
|
+
|
|
82
|
+
- **异步原生**:基于 ASGI,`async def` 视图函数,配套 `uvicorn` 运行
|
|
83
|
+
- **类型驱动**:请求参数与响应体由 Pydantic 校验,自动生成 OpenAPI / Swagger
|
|
84
|
+
- **依赖注入**:`Depends()` / `Security()` 组合式依赖
|
|
85
|
+
- **Flask 风格兼容**:应用上下文、请求上下文、`g`、`session`、蓝图、模板、信号、CLI、测试客户端
|
|
86
|
+
- **完备**:内置路由、模板、会话、蓝图、信号、测试客户端与 CLI
|
|
87
|
+
|
|
88
|
+
## 安装
|
|
89
|
+
|
|
90
|
+
```console
|
|
91
|
+
$ pip install -U pboot
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
开发安装(含 uvicorn、httpx):
|
|
95
|
+
|
|
96
|
+
```console
|
|
97
|
+
$ pip install -U "pboot[standard]"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 核心概念
|
|
101
|
+
|
|
102
|
+
### 应用与路由
|
|
103
|
+
|
|
104
|
+
FastAPI 风格(类型驱动 + 自动文档):
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from pboot import Pboot
|
|
108
|
+
from pboot.params import Query
|
|
109
|
+
|
|
110
|
+
app = Pboot(__name__)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@app.get("/users/{user_id}")
|
|
114
|
+
async def show_user(user_id: int, q: str | None = Query(None)):
|
|
115
|
+
return {"user_id": user_id, "q": q}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Flask 风格(路径参数直接作为函数参数):
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
@app.route("/users/<int:user_id>")
|
|
122
|
+
async def show_user(user_id: int):
|
|
123
|
+
return f"User {user_id}"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 蓝图
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from pboot import Blueprint
|
|
130
|
+
|
|
131
|
+
bp = Blueprint("api", __name__, url_prefix="/api")
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@bp.get("/ping")
|
|
135
|
+
async def ping():
|
|
136
|
+
return {"msg": "pong"}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@bp.route("/hello/<name>")
|
|
140
|
+
async def hello(name):
|
|
141
|
+
return f"Hello {name}"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 模板
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from pboot import render_template
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@app.get("/hello/{name}")
|
|
151
|
+
async def hello(name: str):
|
|
152
|
+
return render_template("hello.html", name=name)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 配置
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
app.config["SECRET_KEY"] = "your-secret"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## 命令行
|
|
162
|
+
|
|
163
|
+
```console
|
|
164
|
+
$ pboot --help
|
|
165
|
+
$ pboot run --port 8080
|
|
166
|
+
$ pboot routes
|
|
167
|
+
$ pboot shell
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 测试
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from pboot import Pboot
|
|
174
|
+
|
|
175
|
+
app = Pboot(__name__)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@app.get("/")
|
|
179
|
+
async def index():
|
|
180
|
+
return "ok"
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def test_index():
|
|
184
|
+
client = app.test_client()
|
|
185
|
+
resp = client.get("/")
|
|
186
|
+
assert resp.status_code == 200
|
|
187
|
+
assert resp.data == b"ok"
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 环境变量
|
|
191
|
+
|
|
192
|
+
| 变量 | 说明 |
|
|
193
|
+
| --- | --- |
|
|
194
|
+
| `PBOOT_APP` | 指定要加载的应用或工厂函数(等价于 `--app`) |
|
|
195
|
+
| `PBOOT_DEBUG` | 开启调试模式 |
|
|
196
|
+
| `PBOOT_SKIP_DOTENV` | 跳过 `.pbootenv` / `.env` 加载 |
|
|
197
|
+
|
|
198
|
+
> 端口与主机请用 `--port` / `--host` 命令行参数指定。
|
|
199
|
+
> 从 Flask 迁移请查阅 [迁移指导](docs/migration-from-flask.md)。
|
|
200
|
+
|
|
201
|
+
## 参与贡献
|
|
202
|
+
|
|
203
|
+
问题反馈、功能建议与代码贡献都欢迎通过
|
|
204
|
+
[pboot-org/pboot](https://gitee.com/pboot-org/pboot/issues) 提交。
|
|
205
|
+
|
|
206
|
+
## 许可证
|
|
207
|
+
|
|
208
|
+
BSD-3-Clause,详见 [LICENSE.txt](LICENSE.txt)。核心框架代码派生自 FastAPI(MIT)。
|
|
209
|
+
|
|
210
|
+
[FastAPI]: https://fastapi.tiangolo.com/
|
|
211
|
+
[Starlette]: https://www.starlette.io/
|
|
212
|
+
[Pydantic]: https://docs.pydantic.dev/
|
|
213
|
+
|
pboot-4.0.0/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="docs/_static/pboot-logo.svg" alt="Pboot" height="140">
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
# Pboot
|
|
6
|
+
|
|
7
|
+
**Pboot** 是一个基于 [FastAPI] / [Starlette] / [Pydantic] 的现代 ASGI Web 应用框架,
|
|
8
|
+
在保留 Flask 风格易用 API 的同时,获得异步运行时、类型驱动校验与自动 OpenAPI 文档。
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
from pboot import Pboot
|
|
12
|
+
|
|
13
|
+
app = Pboot(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.get("/")
|
|
17
|
+
async def hello():
|
|
18
|
+
return "Hello, Pboot!"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
$ pboot run
|
|
23
|
+
* Running on http://127.0.0.1:8000/ (Press CTRL+C to quit)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 特性
|
|
27
|
+
|
|
28
|
+
- **异步原生**:基于 ASGI,`async def` 视图函数,配套 `uvicorn` 运行
|
|
29
|
+
- **类型驱动**:请求参数与响应体由 Pydantic 校验,自动生成 OpenAPI / Swagger
|
|
30
|
+
- **依赖注入**:`Depends()` / `Security()` 组合式依赖
|
|
31
|
+
- **Flask 风格兼容**:应用上下文、请求上下文、`g`、`session`、蓝图、模板、信号、CLI、测试客户端
|
|
32
|
+
- **完备**:内置路由、模板、会话、蓝图、信号、测试客户端与 CLI
|
|
33
|
+
|
|
34
|
+
## 安装
|
|
35
|
+
|
|
36
|
+
```console
|
|
37
|
+
$ pip install -U pboot
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
开发安装(含 uvicorn、httpx):
|
|
41
|
+
|
|
42
|
+
```console
|
|
43
|
+
$ pip install -U "pboot[standard]"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 核心概念
|
|
47
|
+
|
|
48
|
+
### 应用与路由
|
|
49
|
+
|
|
50
|
+
FastAPI 风格(类型驱动 + 自动文档):
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from pboot import Pboot
|
|
54
|
+
from pboot.params import Query
|
|
55
|
+
|
|
56
|
+
app = Pboot(__name__)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@app.get("/users/{user_id}")
|
|
60
|
+
async def show_user(user_id: int, q: str | None = Query(None)):
|
|
61
|
+
return {"user_id": user_id, "q": q}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Flask 风格(路径参数直接作为函数参数):
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
@app.route("/users/<int:user_id>")
|
|
68
|
+
async def show_user(user_id: int):
|
|
69
|
+
return f"User {user_id}"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 蓝图
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from pboot import Blueprint
|
|
76
|
+
|
|
77
|
+
bp = Blueprint("api", __name__, url_prefix="/api")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@bp.get("/ping")
|
|
81
|
+
async def ping():
|
|
82
|
+
return {"msg": "pong"}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@bp.route("/hello/<name>")
|
|
86
|
+
async def hello(name):
|
|
87
|
+
return f"Hello {name}"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 模板
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from pboot import render_template
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@app.get("/hello/{name}")
|
|
97
|
+
async def hello(name: str):
|
|
98
|
+
return render_template("hello.html", name=name)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 配置
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
app.config["SECRET_KEY"] = "your-secret"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 命令行
|
|
108
|
+
|
|
109
|
+
```console
|
|
110
|
+
$ pboot --help
|
|
111
|
+
$ pboot run --port 8080
|
|
112
|
+
$ pboot routes
|
|
113
|
+
$ pboot shell
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## 测试
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from pboot import Pboot
|
|
120
|
+
|
|
121
|
+
app = Pboot(__name__)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@app.get("/")
|
|
125
|
+
async def index():
|
|
126
|
+
return "ok"
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_index():
|
|
130
|
+
client = app.test_client()
|
|
131
|
+
resp = client.get("/")
|
|
132
|
+
assert resp.status_code == 200
|
|
133
|
+
assert resp.data == b"ok"
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## 环境变量
|
|
137
|
+
|
|
138
|
+
| 变量 | 说明 |
|
|
139
|
+
| --- | --- |
|
|
140
|
+
| `PBOOT_APP` | 指定要加载的应用或工厂函数(等价于 `--app`) |
|
|
141
|
+
| `PBOOT_DEBUG` | 开启调试模式 |
|
|
142
|
+
| `PBOOT_SKIP_DOTENV` | 跳过 `.pbootenv` / `.env` 加载 |
|
|
143
|
+
|
|
144
|
+
> 端口与主机请用 `--port` / `--host` 命令行参数指定。
|
|
145
|
+
> 从 Flask 迁移请查阅 [迁移指导](docs/migration-from-flask.md)。
|
|
146
|
+
|
|
147
|
+
## 参与贡献
|
|
148
|
+
|
|
149
|
+
问题反馈、功能建议与代码贡献都欢迎通过
|
|
150
|
+
[pboot-org/pboot](https://gitee.com/pboot-org/pboot/issues) 提交。
|
|
151
|
+
|
|
152
|
+
## 许可证
|
|
153
|
+
|
|
154
|
+
BSD-3-Clause,详见 [LICENSE.txt](LICENSE.txt)。核心框架代码派生自 FastAPI(MIT)。
|
|
155
|
+
|
|
156
|
+
[FastAPI]: https://fastapi.tiangolo.com/
|
|
157
|
+
[Starlette]: https://www.starlette.io/
|
|
158
|
+
[Pydantic]: https://docs.pydantic.dev/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 200" width="320" height="200" role="img" aria-label="Pboot">
|
|
2
|
+
<title>Pboot</title>
|
|
3
|
+
<defs>
|
|
4
|
+
<linearGradient id="pboot-bg" x1="0" y1="0" x2="1" y2="1">
|
|
5
|
+
<stop offset="0%" stop-color="#f97316"/>
|
|
6
|
+
<stop offset="100%" stop-color="#ea580c"/>
|
|
7
|
+
</linearGradient>
|
|
8
|
+
</defs>
|
|
9
|
+
<rect width="320" height="200" rx="18" fill="url(#pboot-bg)"/>
|
|
10
|
+
<g fill="none" stroke="#fff7ed" stroke-width="9" stroke-linecap="round" stroke-linejoin="round">
|
|
11
|
+
<path d="M96 142V58h38a26 26 0 0 1 0 52h-38"/>
|
|
12
|
+
<path d="M162 142V58h22a30 30 0 0 1 0 60h-22"/>
|
|
13
|
+
<path d="M186 118l30 24"/>
|
|
14
|
+
</g>
|
|
15
|
+
<circle cx="228" cy="70" r="9" fill="#fff7ed"/>
|
|
16
|
+
<text x="160" y="178" font-family="Helvetica, Arial, sans-serif" font-size="20"
|
|
17
|
+
font-weight="600" fill="#fff7ed" text-anchor="middle">Pboot</text>
|
|
18
|
+
</svg>
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# 从 Flask / Pboot 3.x 迁移到 Pboot 4.x
|
|
2
|
+
|
|
3
|
+
Pboot 4.0 将框架内核从 Flask(WSGI)整体替换为 FastAPI(ASGI),
|
|
4
|
+
同时保留了 Pboot 3.x 的 Flask 风格 API。本文档说明两代 API 的差异与迁移方式。
|
|
5
|
+
|
|
6
|
+
## 核心变化
|
|
7
|
+
|
|
8
|
+
| 方面 | Pboot 3.x | Pboot 4.x |
|
|
9
|
+
| --- | --- | --- |
|
|
10
|
+
| 内核 | Flask / Werkzeug(WSGI) | FastAPI / Starlette(ASGI) |
|
|
11
|
+
| 视图函数 | 同步为主 | `async def` 优先,同步函数同样可用 |
|
|
12
|
+
| 路径参数 | `<int:user_id>` | `<int:user_id>`(Flask 风格)或 `{user_id}`(FastAPI 风格) |
|
|
13
|
+
| 请求体读取 | `request.form`、`request.json` 同步属性 | `await request.form()`、`await request.json()` |
|
|
14
|
+
| 响应内容类型 | 字符串返回 `text/html` | `app.get` 返回 JSON;`app.route` 返回 HTML |
|
|
15
|
+
| 类型校验 | 无 | Pydantic 模型自动校验,自动生成 OpenAPI |
|
|
16
|
+
| 依赖注入 | 无 | `Depends()` |
|
|
17
|
+
| 服务器 | Werkzeug 开发服务器 | uvicorn |
|
|
18
|
+
|
|
19
|
+
## 应用创建
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
# 3.x
|
|
23
|
+
from pboot import Pboot
|
|
24
|
+
|
|
25
|
+
app = Pboot(__name__)
|
|
26
|
+
|
|
27
|
+
# 4.x —— 写法不变
|
|
28
|
+
from pboot import Pboot
|
|
29
|
+
|
|
30
|
+
app = Pboot(__name__)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`Pboot` 现在同时接受 Flask 风格的构造参数与 FastAPI 的关键字参数:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
app = Pboot(__name__, debug=True, title="我的 API", version="1.0.0")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 路由:两套风格并存
|
|
40
|
+
|
|
41
|
+
### FastAPI 风格(推荐用于 API)
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from pboot import Query
|
|
45
|
+
|
|
46
|
+
@app.get("/users/{user_id}")
|
|
47
|
+
async def show_user(user_id: int, q: str | None = Query(None)):
|
|
48
|
+
return {"user_id": user_id, "q": q}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
* 路径参数用 `{}`,类型由注解决定
|
|
52
|
+
* 返回值自动序列化为 JSON
|
|
53
|
+
* 自动进入 OpenAPI 文档
|
|
54
|
+
|
|
55
|
+
### Flask 风格(适合页面与模板)
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
@app.route("/users/<int:user_id>")
|
|
59
|
+
async def show_user(user_id):
|
|
60
|
+
return f"User {user_id}"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
* 路径参数用 `<>`,直接作为函数关键字参数
|
|
64
|
+
* 返回字符串即为 `text/html`,返回 `dict` 即为 JSON
|
|
65
|
+
* 返回 `(body, status)`、`(body, status, headers)` 可自定义状态码与响应头
|
|
66
|
+
|
|
67
|
+
> 判定规则很直白:路径里出现 `<>` 就按 Flask 风格注册,否则按 FastAPI 风格注册。
|
|
68
|
+
> 同一个应用里两种风格可以混用。
|
|
69
|
+
|
|
70
|
+
## 上下文与会话
|
|
71
|
+
|
|
72
|
+
上下文的语义没有变化:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from pboot import g, request, session, current_app
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
区别在于请求体是异步读取的:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
@app.post("/submit")
|
|
82
|
+
async def submit():
|
|
83
|
+
data = await request.json() # 3.x: request.json
|
|
84
|
+
form = await request.form() # 3.x: request.form
|
|
85
|
+
return {"ok": True}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
会话仍然是签名 Cookie,`session["user"] = "x"` 的写法完全一致。
|
|
89
|
+
|
|
90
|
+
## 蓝图
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from pboot import Blueprint
|
|
94
|
+
|
|
95
|
+
bp = Blueprint("api", __name__, url_prefix="/api")
|
|
96
|
+
|
|
97
|
+
@bp.get("/ping")
|
|
98
|
+
async def ping():
|
|
99
|
+
return {"msg": "pong"}
|
|
100
|
+
|
|
101
|
+
app.register_blueprint(bp)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
蓝图支持嵌套(`parent.register_blueprint(child)`)、`before_request` /
|
|
105
|
+
`after_request` / `context_processor` / `errorhandler` 等钩子。
|
|
106
|
+
|
|
107
|
+
## 模板
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from pboot import render_template
|
|
111
|
+
|
|
112
|
+
@app.route("/hello/<name>")
|
|
113
|
+
async def hello(name):
|
|
114
|
+
return render_template("hello.html", name=name)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Jinja 环境、模板过滤器、模板全局变量、`context_processor` 的用法保持不变。
|
|
118
|
+
|
|
119
|
+
## 错误处理
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
@app.errorhandler(404)
|
|
123
|
+
async def not_found(exc):
|
|
124
|
+
return {"error": "not found"}, 404
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`abort(404)`、`abort(400, "错误信息")` 同样可用。
|
|
128
|
+
|
|
129
|
+
## 测试
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
def test_index():
|
|
133
|
+
client = app.test_client()
|
|
134
|
+
resp = client.get("/")
|
|
135
|
+
assert resp.status_code == 200
|
|
136
|
+
assert resp.data == b"ok"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
测试客户端保留了 Flask 风格的 `.data`、`.status_code`、`.headers`、`.json()`,
|
|
140
|
+
底层由 Starlette 的 `TestClient`(httpx)实现。
|
|
141
|
+
|
|
142
|
+
## 命令行
|
|
143
|
+
|
|
144
|
+
```console
|
|
145
|
+
$ pboot --app myapp run --port 8000
|
|
146
|
+
$ pboot --app myapp routes
|
|
147
|
+
$ pboot --app myapp shell
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`run` 命令使用 uvicorn 启动 ASGI 服务,需要安装 `pboot[standard]`。
|
|
151
|
+
|
|
152
|
+
## 需要注意的差异清单
|
|
153
|
+
|
|
154
|
+
1. **请求体异步读取**:`await request.form()` / `await request.json()`。
|
|
155
|
+
2. **`request.values` 是方法**:`await request.values()`。
|
|
156
|
+
3. **静态目录**:默认挂载在 `/static`,需要 `static` 目录存在于应用根目录。
|
|
157
|
+
4. **同步视图函数仍可用**,但会在线程池中执行,不要在里面做阻塞的异步操作。
|
|
158
|
+
5. **中间件**:使用 FastAPI/Starlette 的 `app.middleware("http")` 写法。
|
|
159
|
+
6. **`app.root_path`** 保持 ASGI 语义(挂载路径),应用所在目录请用 `app.app_root_path`。
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""FastAPI 风格示例:类型校验、依赖注入与 Pydantic 模型。
|
|
2
|
+
|
|
3
|
+
运行:
|
|
4
|
+
|
|
5
|
+
pboot --app app run
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Annotated
|
|
9
|
+
|
|
10
|
+
from pydantic import BaseModel, Field
|
|
11
|
+
|
|
12
|
+
from pboot import Depends, Pboot, Query
|
|
13
|
+
|
|
14
|
+
app = Pboot(title="示例 API", version="1.0.0")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Item(BaseModel):
|
|
18
|
+
name: str = Field(max_length=50)
|
|
19
|
+
price: float = Field(gt=0)
|
|
20
|
+
tags: list[str] = []
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ItemIn(Item):
|
|
24
|
+
description: str | None = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
items: dict[int, Item] = {}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_item_id(q: Annotated[int | None, Query(description="可选的物品编号")] = None) -> int:
|
|
31
|
+
"""一个简单的依赖,用来演示依赖注入。"""
|
|
32
|
+
return q or 1
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@app.post("/items", status_code=201)
|
|
36
|
+
async def create_item(item: ItemIn) -> Item:
|
|
37
|
+
"""创建物品,返回值会按 Item 模型校验。"""
|
|
38
|
+
item_id = len(items) + 1
|
|
39
|
+
stored = Item(**item.model_dump(exclude={"description"}))
|
|
40
|
+
items[item_id] = stored
|
|
41
|
+
return stored
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@app.get("/items/{item_id}")
|
|
45
|
+
async def read_item(item_id: int) -> Item:
|
|
46
|
+
"""按编号读取物品。"""
|
|
47
|
+
if item_id not in items:
|
|
48
|
+
from pboot import HTTPException
|
|
49
|
+
|
|
50
|
+
raise HTTPException(status_code=404, detail="Item not found")
|
|
51
|
+
return items[item_id]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@app.get("/items")
|
|
55
|
+
async def list_items(item_id: Annotated[int, Depends(get_item_id)]) -> list[Item]:
|
|
56
|
+
"""列出物品,item_id 来自依赖注入。"""
|
|
57
|
+
return list(items.values())
|