You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

208 lines
6.1 KiB

  1. Metadata-Version: 2.1
  2. Name: starlette
  3. Version: 0.17.1
  4. Summary: The little ASGI library that shines.
  5. Home-page: https://github.com/encode/starlette
  6. Author: Tom Christie
  7. Author-email: tom@tomchristie.com
  8. License: BSD
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 3 - Alpha
  11. Classifier: Environment :: Web Environment
  12. Classifier: Intended Audience :: Developers
  13. Classifier: License :: OSI Approved :: BSD License
  14. Classifier: Operating System :: OS Independent
  15. Classifier: Topic :: Internet :: WWW/HTTP
  16. Classifier: Programming Language :: Python :: 3
  17. Classifier: Programming Language :: Python :: 3.6
  18. Classifier: Programming Language :: Python :: 3.7
  19. Classifier: Programming Language :: Python :: 3.8
  20. Classifier: Programming Language :: Python :: 3.9
  21. Classifier: Programming Language :: Python :: 3.10
  22. Requires-Python: >=3.6
  23. Description-Content-Type: text/markdown
  24. Requires-Dist: anyio (<4,>=3.0.0)
  25. Requires-Dist: contextlib2 (>=21.6.0) ; python_version < "3.7"
  26. Requires-Dist: typing-extensions ; python_version < "3.8"
  27. Provides-Extra: full
  28. Requires-Dist: itsdangerous ; extra == 'full'
  29. Requires-Dist: jinja2 ; extra == 'full'
  30. Requires-Dist: python-multipart ; extra == 'full'
  31. Requires-Dist: pyyaml ; extra == 'full'
  32. Requires-Dist: requests ; extra == 'full'
  33. <p align="center">
  34. <a href="https://www.starlette.io/"><img width="420px" src="https://raw.githubusercontent.com/encode/starlette/master/docs/img/starlette.png" alt='starlette'></a>
  35. </p>
  36. <p align="center">
  37. <em>✨ The little ASGI framework that shines. ✨</em>
  38. </p>
  39. <p align="center">
  40. <a href="https://github.com/encode/starlette/actions">
  41. <img src="https://github.com/encode/starlette/workflows/Test%20Suite/badge.svg" alt="Build Status">
  42. </a>
  43. <a href="https://pypi.org/project/starlette/">
  44. <img src="https://badge.fury.io/py/starlette.svg" alt="Package version">
  45. </a>
  46. </p>
  47. ---
  48. **Documentation**: [https://www.starlette.io/](https://www.starlette.io/)
  49. ---
  50. # Starlette
  51. Starlette is a lightweight [ASGI](https://asgi.readthedocs.io/en/latest/) framework/toolkit,
  52. which is ideal for building high performance async services.
  53. It is production-ready, and gives you the following:
  54. * Seriously impressive performance.
  55. * WebSocket support.
  56. * In-process background tasks.
  57. * Startup and shutdown events.
  58. * Test client built on `requests`.
  59. * CORS, GZip, Static Files, Streaming responses.
  60. * Session and Cookie support.
  61. * 100% test coverage.
  62. * 100% type annotated codebase.
  63. * Few hard dependencies.
  64. * Compatible with `asyncio` and `trio` backends.
  65. ## Requirements
  66. Python 3.6+
  67. ## Installation
  68. ```shell
  69. $ pip3 install starlette
  70. ```
  71. You'll also want to install an ASGI server, such as [uvicorn](http://www.uvicorn.org/), [daphne](https://github.com/django/daphne/), or [hypercorn](https://pgjones.gitlab.io/hypercorn/).
  72. ```shell
  73. $ pip3 install uvicorn
  74. ```
  75. ## Example
  76. **example.py**:
  77. ```python
  78. from starlette.applications import Starlette
  79. from starlette.responses import JSONResponse
  80. from starlette.routing import Route
  81. async def homepage(request):
  82. return JSONResponse({'hello': 'world'})
  83. routes = [
  84. Route("/", endpoint=homepage)
  85. ]
  86. app = Starlette(debug=True, routes=routes)
  87. ```
  88. Then run the application using Uvicorn:
  89. ```shell
  90. $ uvicorn example:app
  91. ```
  92. For a more complete example, see [encode/starlette-example](https://github.com/encode/starlette-example).
  93. ## Dependencies
  94. Starlette only requires `anyio`, and the following are optional:
  95. * [`requests`][requests] - Required if you want to use the `TestClient`.
  96. * [`jinja2`][jinja2] - Required if you want to use `Jinja2Templates`.
  97. * [`python-multipart`][python-multipart] - Required if you want to support form parsing, with `request.form()`.
  98. * [`itsdangerous`][itsdangerous] - Required for `SessionMiddleware` support.
  99. * [`pyyaml`][pyyaml] - Required for `SchemaGenerator` support.
  100. You can install all of these with `pip3 install starlette[full]`.
  101. ## Framework or Toolkit
  102. Starlette is designed to be used either as a complete framework, or as
  103. an ASGI toolkit. You can use any of its components independently.
  104. ```python
  105. from starlette.responses import PlainTextResponse
  106. async def app(scope, receive, send):
  107. assert scope['type'] == 'http'
  108. response = PlainTextResponse('Hello, world!')
  109. await response(scope, receive, send)
  110. ```
  111. Run the `app` application in `example.py`:
  112. ```shell
  113. $ uvicorn example:app
  114. INFO: Started server process [11509]
  115. INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
  116. ```
  117. Run uvicorn with `--reload` to enable auto-reloading on code changes.
  118. ## Modularity
  119. The modularity that Starlette is designed on promotes building re-usable
  120. components that can be shared between any ASGI framework. This should enable
  121. an ecosystem of shared middleware and mountable applications.
  122. The clean API separation also means it's easier to understand each component
  123. in isolation.
  124. ## Performance
  125. Independent TechEmpower benchmarks show Starlette applications running under Uvicorn
  126. as [one of the fastest Python frameworks available](https://www.techempower.com/benchmarks/#section=data-r17&hw=ph&test=fortune&l=zijzen-1). *(\*)*
  127. For high throughput loads you should:
  128. * Run using gunicorn using the `uvicorn` worker class.
  129. * Use one or two workers per-CPU core. (You might need to experiment with this.)
  130. * Disable access logging.
  131. Eg.
  132. ```shell
  133. gunicorn -w 4 -k uvicorn.workers.UvicornWorker --log-level warning example:app
  134. ```
  135. Several of the ASGI servers also have pure Python implementations available,
  136. so you can also run under `PyPy` if your application code has parts that are
  137. CPU constrained.
  138. Either programatically:
  139. ```python
  140. uvicorn.run(..., http='h11', loop='asyncio')
  141. ```
  142. Or using Gunicorn:
  143. ```shell
  144. gunicorn -k uvicorn.workers.UvicornH11Worker ...
  145. ```
  146. <p align="center">&mdash; ⭐️ &mdash;</p>
  147. <p align="center"><i>Starlette is <a href="https://github.com/encode/starlette/blob/master/LICENSE.md">BSD licensed</a> code. Designed & built in Brighton, England.</i></p>
  148. [requests]: http://docs.python-requests.org/en/master/
  149. [jinja2]: http://jinja.pocoo.org/
  150. [python-multipart]: https://andrew-d.github.io/python-multipart/
  151. [itsdangerous]: https://pythonhosted.org/itsdangerous/
  152. [sqlalchemy]: https://www.sqlalchemy.org
  153. [pyyaml]: https://pyyaml.org/wiki/PyYAMLDocumentation