Skip to content

Commit f6c3ffc

Browse files
authored
Feat/litestar (#9905)
* feat: add support for litestar * feat: add support for litestar * feat: refactor app structure and update dependencies * feat: update app structure and replace ujson5 with orjson * feat: add comprehensive .gitignore for Python and IDE files * feat: update benchmark configuration for Granian support * feat: update display names in benchmark configuration and modify Dockerfile installation * feat: update response handling to return Response objects for JSON endpoints * feat: update response handling to return Response objects for JSON endpoints * fix: copy files in Dockerfiles * fix: copy files in Dockerfiles * fix: remove usage of restricting to http2 * fix: resposne types * fix: resposne types * fix: remove socketify with pypy
1 parent 7a4a952 commit f6c3ffc

26 files changed

+1342
-0
lines changed

frameworks/Python/litestar/.gitignore

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
### Python template
2+
# Byte-compiled / optimized / DLL files
3+
__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
cover/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# poetry
99+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100+
# This is especially recommended for binary packages to ensure reproducibility, and is more
101+
# commonly ignored for libraries.
102+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103+
#poetry.lock
104+
105+
# pdm
106+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107+
#pdm.lock
108+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109+
# in version control.
110+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
111+
.pdm.toml
112+
.pdm-python
113+
.pdm-build/
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.venv
128+
env/
129+
venv/
130+
ENV/
131+
env.bak/
132+
venv.bak/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# PyCharm
159+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161+
# and can be added to the global gitignore or merged into this file. For a more nuclear
162+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163+
#.idea/
164+
165+
### PyCharm+all template
166+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
167+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
168+
169+
# User-specific stuff
170+
.idea/**/workspace.xml
171+
.idea/**/tasks.xml
172+
.idea/**/usage.statistics.xml
173+
.idea/**/dictionaries
174+
.idea/**/shelf
175+
176+
# AWS User-specific
177+
.idea/**/aws.xml
178+
179+
# Generated files
180+
.idea/**/contentModel.xml
181+
182+
# Sensitive or high-churn files
183+
.idea/**/dataSources/
184+
.idea/**/dataSources.ids
185+
.idea/**/dataSources.local.xml
186+
.idea/**/sqlDataSources.xml
187+
.idea/**/dynamic.xml
188+
.idea/**/uiDesigner.xml
189+
.idea/**/dbnavigator.xml
190+
191+
# Gradle
192+
.idea/**/gradle.xml
193+
.idea/**/libraries
194+
195+
# Gradle and Maven with auto-import
196+
# When using Gradle or Maven with auto-import, you should exclude module files,
197+
# since they will be recreated, and may cause churn. Uncomment if using
198+
# auto-import.
199+
# .idea/artifacts
200+
# .idea/compiler.xml
201+
# .idea/jarRepositories.xml
202+
# .idea/modules.xml
203+
# .idea/*.iml
204+
# .idea/modules
205+
# *.iml
206+
# *.ipr
207+
208+
# CMake
209+
cmake-build-*/
210+
211+
# Mongo Explorer plugin
212+
.idea/**/mongoSettings.xml
213+
214+
# File-based project format
215+
*.iws
216+
217+
# IntelliJ
218+
out/
219+
220+
# mpeltonen/sbt-idea plugin
221+
.idea_modules/
222+
223+
# JIRA plugin
224+
atlassian-ide-plugin.xml
225+
226+
# Cursive Clojure plugin
227+
.idea/replstate.xml
228+
229+
# SonarLint plugin
230+
.idea/sonarlint/
231+
232+
# Crashlytics plugin (for Android Studio and IntelliJ)
233+
com_crashlytics_export_strings.xml
234+
crashlytics.properties
235+
crashlytics-build.properties
236+
fabric.properties
237+
238+
# Editor-based Rest Client
239+
.idea/httpRequests
240+
241+
# Android studio 3.1+ serialized cache file
242+
.idea/caches/build_file_checksums.ser
243+
244+
.ruff_cache/

frameworks/Python/litestar/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Litestar Benchmarking Test
2+
3+
This is the Litestar portion of a [benchmarking tests suite](../../)
4+
comparing a variety of web development platforms.
5+
6+
The information below is specific to Litestar. For further guidance,
7+
review the [documentation](https://github.com/TechEmpower/FrameworkBenchmarks/wiki).
8+
Also note that there is additional information provided in
9+
the [Python README](../).
10+
11+
## Description
12+
13+
[**Litestar**](https://github.com/litestar-org/litestar) is a modern, fast (high-performance), web framework for building APIs with Python 3.6+.
14+
15+
The key features are:
16+
17+
* **Fast**: Very high performance, on par with **NodeJS** and **Go**.
18+
19+
* **Fast to code**: Increase the speed to develop features by about 200% to 300% *.
20+
* **Less bugs**: Reduce about 40% of human (developer) induced errors. *
21+
* **Intuitive**: Great editor support. <abbr title="also known as auto-complete, autocompletion, IntelliSense">Completion</abbr> everywhere. Less time debugging.
22+
* **Easy**: Designed to be easy to use and learn. Less time reading docs.
23+
* **Short**: Minimize code duplication. Multiple features from each parameter declaration. Less bugs.
24+
* **Robust**: Get production-ready code. With automatic interactive documentation.
25+
* **Standards-based**: Based on (and fully compatible with) the open standards for APIs: <a href="https://github.com/OAI/OpenAPI-Specification" target="_blank">OpenAPI</a> and <a href="http://json-schema.org/" target="_blank">JSON Schema</a>.
26+
27+
<small>* estimation based on tests on an internal development team, building production applications.</small>
28+
29+
## Test Paths & Sources
30+
31+
All of the test implementations are located within a single file ([app.py](app.py)).
32+
33+
34+
## Resources
35+
36+
* [Litestar source code on GitHub](https://github.com/litestar-org/litestar)
37+
* [Litestar website - documentation](https://litestar.dev)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import multiprocessing
3+
import logging
4+
5+
import orjson
6+
from litestar import Litestar, get, MediaType, Response
7+
from socketify import ASGI
8+
9+
10+
@get("/json")
11+
async def json_serialization() -> Response:
12+
return Response(content=orjson.dumps({"message": "Hello, world!"}), media_type=MediaType.JSON)
13+
14+
15+
@get("/plaintext", media_type=MediaType.TEXT)
16+
async def plaintext() -> bytes:
17+
return b"Hello, world!"
18+
19+
20+
app = Litestar(
21+
route_handlers=[
22+
json_serialization,
23+
plaintext,
24+
]
25+
)
26+
27+
_is_travis = os.environ.get("TRAVIS") == "true"
28+
29+
workers = int(multiprocessing.cpu_count())
30+
if _is_travis:
31+
workers = 2
32+
33+
34+
def run_app():
35+
ASGI(app).listen(8080, lambda config: logging.info(f"Listening on port http://localhost:{config.port} now\n")).run()
36+
37+
38+
def create_fork():
39+
n = os.fork()
40+
# n greater than 0 means parent process
41+
if not n > 0:
42+
run_app()
43+
44+
45+
# fork limiting the cpu count - 1
46+
for i in range(1, workers):
47+
create_fork()
48+
49+
run_app() # run app on the main process too :)

0 commit comments

Comments
 (0)