mojolicious 0.0.1__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.
Files changed (131) hide show
  1. mojolicious-0.0.1/.gitignore +7 -0
  2. mojolicious-0.0.1/CHANGELOG.md +9 -0
  3. mojolicious-0.0.1/LICENSE +20 -0
  4. mojolicious-0.0.1/PKG-INFO +156 -0
  5. mojolicious-0.0.1/README.md +115 -0
  6. mojolicious-0.0.1/docs/Cheatsheet.md +215 -0
  7. mojolicious-0.0.1/docs/Contributing.md +163 -0
  8. mojolicious-0.0.1/docs/Cookbook.md +459 -0
  9. mojolicious-0.0.1/docs/FAQ.md +54 -0
  10. mojolicious-0.0.1/docs/Growing.md +663 -0
  11. mojolicious-0.0.1/docs/Introduction.md +863 -0
  12. mojolicious-0.0.1/docs/README.md +21 -0
  13. mojolicious-0.0.1/docs/Rendering.md +656 -0
  14. mojolicious-0.0.1/docs/Routing.md +521 -0
  15. mojolicious-0.0.1/docs/Testing.md +240 -0
  16. mojolicious-0.0.1/docs/User-Agent.md +222 -0
  17. mojolicious-0.0.1/docs/api.md +153 -0
  18. mojolicious-0.0.1/docs/changelog.md +2 -0
  19. mojolicious-0.0.1/docs/conf.py +44 -0
  20. mojolicious-0.0.1/docs/images/logo.png +0 -0
  21. mojolicious-0.0.1/docs/index.md +63 -0
  22. mojolicious-0.0.1/examples/hello.py +52 -0
  23. mojolicious-0.0.1/pyproject.toml +100 -0
  24. mojolicious-0.0.1/src/mojolicious/__init__.py +34 -0
  25. mojolicious-0.0.1/src/mojolicious/__main__.py +233 -0
  26. mojolicious-0.0.1/src/mojolicious/app.py +353 -0
  27. mojolicious-0.0.1/src/mojolicious/asgi.py +236 -0
  28. mojolicious-0.0.1/src/mojolicious/body.py +251 -0
  29. mojolicious-0.0.1/src/mojolicious/cache.py +24 -0
  30. mojolicious-0.0.1/src/mojolicious/cli/__init__.py +118 -0
  31. mojolicious-0.0.1/src/mojolicious/cli/eval.py +36 -0
  32. mojolicious-0.0.1/src/mojolicious/cli/get.py +102 -0
  33. mojolicious-0.0.1/src/mojolicious/cli/repl.py +16 -0
  34. mojolicious-0.0.1/src/mojolicious/cli/routes.py +37 -0
  35. mojolicious-0.0.1/src/mojolicious/cli/server.py +187 -0
  36. mojolicious-0.0.1/src/mojolicious/cli/version.py +25 -0
  37. mojolicious-0.0.1/src/mojolicious/context.py +445 -0
  38. mojolicious-0.0.1/src/mojolicious/cookie.py +57 -0
  39. mojolicious-0.0.1/src/mojolicious/dom/__init__.py +420 -0
  40. mojolicious-0.0.1/src/mojolicious/dom/css.py +452 -0
  41. mojolicious-0.0.1/src/mojolicious/dom/nodes.py +205 -0
  42. mojolicious-0.0.1/src/mojolicious/dom/parser.py +329 -0
  43. mojolicious-0.0.1/src/mojolicious/events.py +29 -0
  44. mojolicious-0.0.1/src/mojolicious/headers.py +102 -0
  45. mojolicious-0.0.1/src/mojolicious/hooks.py +69 -0
  46. mojolicious-0.0.1/src/mojolicious/logger.py +63 -0
  47. mojolicious-0.0.1/src/mojolicious/mime.py +45 -0
  48. mojolicious-0.0.1/src/mojolicious/params.py +82 -0
  49. mojolicious-0.0.1/src/mojolicious/plugins/__init__.py +6 -0
  50. mojolicious-0.0.1/src/mojolicious/plugins/conditions.py +42 -0
  51. mojolicious-0.0.1/src/mojolicious/plugins/config.py +72 -0
  52. mojolicious-0.0.1/src/mojolicious/plugins/helpers.py +340 -0
  53. mojolicious-0.0.1/src/mojolicious/plugins/jinja.py +100 -0
  54. mojolicious-0.0.1/src/mojolicious/plugins/mount.py +65 -0
  55. mojolicious-0.0.1/src/mojolicious/plugins/tags.py +270 -0
  56. mojolicious-0.0.1/src/mojolicious/py.typed +0 -0
  57. mojolicious-0.0.1/src/mojolicious/pytest_plugin.py +6 -0
  58. mojolicious-0.0.1/src/mojolicious/renderer.py +218 -0
  59. mojolicious-0.0.1/src/mojolicious/request.py +102 -0
  60. mojolicious-0.0.1/src/mojolicious/resources/certs/development.crt +27 -0
  61. mojolicious-0.0.1/src/mojolicious/resources/certs/development.key +52 -0
  62. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/bootstrap/bootstrap.bundle.min.js +7 -0
  63. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/bootstrap/bootstrap.min.css +7 -0
  64. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/failraptor.png +0 -0
  65. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/favicon.ico +0 -0
  66. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/highlight.js/highlight-mojo-dark.css +56 -0
  67. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/highlight.js/highlight.pack.js +758 -0
  68. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/logo.png +0 -0
  69. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/mojo.css +197 -0
  70. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/no-raptor.png +0 -0
  71. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/not-found.png +0 -0
  72. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/pinstripe-dark.png +0 -0
  73. mojolicious-0.0.1/src/mojolicious/resources/public/mojo/pinstripe-light.png +0 -0
  74. mojolicious-0.0.1/src/mojolicious/resources/views/mojo/debug.html.jinja +138 -0
  75. mojolicious-0.0.1/src/mojolicious/resources/views/mojo/exception.html.jinja +30 -0
  76. mojolicious-0.0.1/src/mojolicious/resources/views/mojo/not_found.html.jinja +43 -0
  77. mojolicious-0.0.1/src/mojolicious/response.py +103 -0
  78. mojolicious-0.0.1/src/mojolicious/router/__init__.py +7 -0
  79. mojolicious-0.0.1/src/mojolicious/router/pattern.py +189 -0
  80. mojolicious-0.0.1/src/mojolicious/router/route.py +198 -0
  81. mojolicious-0.0.1/src/mojolicious/router/router.py +201 -0
  82. mojolicious-0.0.1/src/mojolicious/session.py +147 -0
  83. mojolicious-0.0.1/src/mojolicious/sse.py +56 -0
  84. mojolicious-0.0.1/src/mojolicious/static.py +152 -0
  85. mojolicious-0.0.1/src/mojolicious/user_agent/__init__.py +344 -0
  86. mojolicious-0.0.1/src/mojolicious/user_agent/response.py +93 -0
  87. mojolicious-0.0.1/src/mojolicious/user_agent/test.py +608 -0
  88. mojolicious-0.0.1/src/mojolicious/util.py +78 -0
  89. mojolicious-0.0.1/src/mojolicious/validator.py +310 -0
  90. mojolicious-0.0.1/src/mojolicious/version.py +1 -0
  91. mojolicious-0.0.1/src/mojolicious/websocket.py +97 -0
  92. mojolicious-0.0.1/tests/support/certs/README.md +21 -0
  93. mojolicious-0.0.1/tests/support/certs/ca.crt +19 -0
  94. mojolicious-0.0.1/tests/support/certs/ca.key +28 -0
  95. mojolicious-0.0.1/tests/support/certs/client.crt +18 -0
  96. mojolicious-0.0.1/tests/support/certs/client.key +28 -0
  97. mojolicious-0.0.1/tests/support/certs/server.crt +20 -0
  98. mojolicious-0.0.1/tests/support/certs/server.key +28 -0
  99. mojolicious-0.0.1/tests/support/full_app/controllers/__init__.py +0 -0
  100. mojolicious-0.0.1/tests/support/full_app/controllers/example.py +11 -0
  101. mojolicious-0.0.1/tests/support/full_app/public/assets/app.ab12cd.js +1 -0
  102. mojolicious-0.0.1/tests/support/full_app/public/assets/app.development.js +1 -0
  103. mojolicious-0.0.1/tests/support/full_app/public/hello.txt +1 -0
  104. mojolicious-0.0.1/tests/support/full_app/views/example/auto.html.jinja +1 -0
  105. mojolicious-0.0.1/tests/support/full_app/views/example/data.html.jinja +1 -0
  106. mojolicious-0.0.1/tests/support/full_app/views/example/data.json.jinja +1 -0
  107. mojolicious-0.0.1/tests/support/full_app/views/example/variants.html+phone.jinja +1 -0
  108. mojolicious-0.0.1/tests/support/full_app/views/example/variants.html.jinja +1 -0
  109. mojolicious-0.0.1/tests/support/full_app/views/example/welcome.html.jinja +5 -0
  110. mojolicious-0.0.1/tests/support/full_app/views/form.html.jinja +1 -0
  111. mojolicious-0.0.1/tests/support/full_app/views/layouts/default.html.jinja +5 -0
  112. mojolicious-0.0.1/tests/support/full_app/views/partials/menu.html.jinja +1 -0
  113. mojolicious-0.0.1/tests/test_app.py +498 -0
  114. mojolicious-0.0.1/tests/test_asgi.py +111 -0
  115. mojolicious-0.0.1/tests/test_cli.py +197 -0
  116. mojolicious-0.0.1/tests/test_context.py +43 -0
  117. mojolicious-0.0.1/tests/test_docs.py +236 -0
  118. mojolicious-0.0.1/tests/test_dom.py +490 -0
  119. mojolicious-0.0.1/tests/test_helpers.py +191 -0
  120. mojolicious-0.0.1/tests/test_http.py +223 -0
  121. mojolicious-0.0.1/tests/test_pattern.py +217 -0
  122. mojolicious-0.0.1/tests/test_plugins.py +141 -0
  123. mojolicious-0.0.1/tests/test_realtime.py +162 -0
  124. mojolicious-0.0.1/tests/test_rendering.py +221 -0
  125. mojolicious-0.0.1/tests/test_router.py +92 -0
  126. mojolicious-0.0.1/tests/test_server.py +214 -0
  127. mojolicious-0.0.1/tests/test_sessions.py +110 -0
  128. mojolicious-0.0.1/tests/test_static.py +98 -0
  129. mojolicious-0.0.1/tests/test_user_agent.py +209 -0
  130. mojolicious-0.0.1/tests/test_util.py +51 -0
  131. mojolicious-0.0.1/tests/test_validator.py +78 -0
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ docs/_build/
6
+ .coverage*
7
+ coverage.xml
@@ -0,0 +1,9 @@
1
+
2
+ # Changelog
3
+
4
+ ## v0.0.1 (2026-12-05)
5
+
6
+ ### Features
7
+
8
+ * First release, an idiomatic Python port of the [Mojolicious](https://mojolicious.org) real-time web framework, built
9
+ on ASGI and the design of [mojo.js](https://mojojs.org).
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2026 Sebastian Riedel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.5
2
+ Name: mojolicious
3
+ Version: 0.0.1
4
+ Summary: Real-time web framework
5
+ Project-URL: Homepage, https://mojolicious.github.io/mojo.py/
6
+ Project-URL: Documentation, https://mojolicious.github.io/mojo.py/
7
+ Project-URL: Repository, https://github.com/mojolicious/mojo.py
8
+ Project-URL: Issues, https://github.com/mojolicious/mojo.py/issues
9
+ Project-URL: Changelog, https://github.com/mojolicious/mojo.py/blob/main/CHANGELOG.md
10
+ Author-email: Sebastian Riedel <kraih@mojolicious.org>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: asgi,framework,mojo,mojolicious,real-time,web,websocket
14
+ Classifier: Development Status :: 2 - Pre-Alpha
15
+ Classifier: Environment :: Web Environment
16
+ Classifier: Framework :: AsyncIO
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Programming Language :: Python :: 3.15
25
+ Classifier: Topic :: Internet :: WWW/HTTP
26
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
27
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
28
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.12
31
+ Requires-Dist: httpx2[ws]>=2.14
32
+ Requires-Dist: jinja2>=3.1
33
+ Requires-Dist: jsonschema>=4.20
34
+ Requires-Dist: markupsafe>=2.1
35
+ Requires-Dist: python-multipart>=0.0.20
36
+ Requires-Dist: pyyaml>=6.0
37
+ Requires-Dist: uvicorn[standard]>=0.35
38
+ Provides-Extra: encrypted
39
+ Requires-Dist: cryptography>=42; extra == 'encrypted'
40
+ Description-Content-Type: text/markdown
41
+
42
+ <p align="center">
43
+ <a href="https://mojolicious.github.io/mojo.py/">
44
+ <img src="https://github.com/mojolicious/mojo.py/blob/main/docs/images/logo.png?raw=true" style="margin: 0 auto;">
45
+ </a>
46
+ </p>
47
+
48
+ [![](https://github.com/mojolicious/mojo.py/workflows/test/badge.svg)](https://github.com/mojolicious/mojo.py/actions)
49
+ [![Coverage Status](https://coveralls.io/repos/github/mojolicious/mojo.py/badge.svg?branch=main)](https://coveralls.io/github/mojolicious/mojo.py?branch=main)
50
+ [![PyPI](https://img.shields.io/pypi/v/mojolicious.svg)](https://pypi.org/project/mojolicious/)
51
+ [![Documentation](https://img.shields.io/badge/docs-mojolicious.github.io-blue)](https://mojolicious.github.io/mojo.py/)
52
+
53
+ > **Warning:** Mojolicious is currently **highly experimental**, APIs can still change without warning until the 1.0
54
+ > release. Please don't use it in production yet.
55
+
56
+ The [Mojolicious](https://mojolicious.org) real-time web framework for Python. Meticulously designed for hypermedia-driven
57
+ backend web services, built on [ASGI](https://asgi.readthedocs.io) and all the latest Python features. It is
58
+ installed from PyPI as `mojolicious`, and developed in the [mojo.py](https://github.com/mojolicious/mojo.py)
59
+ repository.
60
+
61
+ If you want to stay up to date on the [latest developments](https://github.com/mojolicious/mojo.py/blob/main/CHANGELOG.md)
62
+ join us on [IRC](https://web.libera.chat/#mojo).
63
+
64
+ ## Features
65
+
66
+ * A **real-time web framework**, allowing you to easily grow single file prototypes into well-structured MVC web
67
+ applications.
68
+ * Powerful out of the box with RESTful routes, WebSockets, Server-Sent Events, plugins, commands, logging,
69
+ [Jinja2](https://jinja.palletsprojects.com) templates, content negotiation, session management, form and JSON
70
+ validation, testing framework, static file server, first class Unicode support and much more for you to discover.
71
+ * A powerful **web development toolkit**, that you can use for all kinds of applications, independently of the web
72
+ framework.
73
+ * HTTP and WebSocket client with support for HTTPS/WSS, cookies, redirects, urlencoded/multi-part forms, file
74
+ uploads, JSON/YAML, HTML/XML, proxies and UNIX domain sockets.
75
+ * HTML/XML parser with CSS selector support.
76
+ * Plays nice with the ecosystem: every application is an ASGI application, and any ASGI application can be mounted
77
+ into yours.
78
+ * Fully typed, with very clean `async`/`await` based APIs.
79
+ * Only mature and widely used dependencies, hidden behind Mojolicious APIs wherever possible, for long term support and
80
+ **backwards compatibility** once 1.0 has been released.
81
+
82
+ ## Installation
83
+
84
+ All you need is Python 3.12 (or newer).
85
+
86
+ ```
87
+ $ pip install mojolicious
88
+ ```
89
+
90
+ ## Getting Started
91
+
92
+ These four lines are a whole web application.
93
+
94
+ ```python
95
+ from mojolicious import App
96
+
97
+ app = App()
98
+
99
+ app.get('/', lambda ctx: ctx.render(text='I ♥ Mojo!'))
100
+
101
+ app.start()
102
+ ```
103
+
104
+ Use the built-in command system to start your web server.
105
+
106
+ ```
107
+ $ python app.py server
108
+ Web application available at http://127.0.0.1:3000/
109
+ ```
110
+
111
+ Test it with any HTTP client you prefer.
112
+
113
+ ```
114
+ $ curl http://127.0.0.1:3000/
115
+ I ♥ Mojo!
116
+ ```
117
+
118
+ ## Duct Tape for the Web
119
+
120
+ Use all the latest Python and HTML features in convenient single file prototypes like this one, and grow them easily
121
+ into well-structured **Model-View-Controller** web applications.
122
+
123
+ ```python
124
+ from mojolicious import App
125
+
126
+ app = App()
127
+
128
+
129
+ @app.get('/')
130
+ async def index(ctx):
131
+ await ctx.render(inline=TEMPLATE)
132
+
133
+
134
+ @app.websocket('/title')
135
+ async def title(ctx):
136
+ ws = await ctx.accept()
137
+ async for url in ws:
138
+ res = await ctx.ua.get(url)
139
+ html = await res.html()
140
+ await ws.send(html.at('title').text())
141
+
142
+
143
+ TEMPLATE = """
144
+ <script>
145
+ const ws = new WebSocket('{{ url_for('title') }}');
146
+ ws.onmessage = event => { document.body.innerHTML += event.data };
147
+ ws.onopen = event => { ws.send('https://mojolicious.org') };
148
+ </script>
149
+ """
150
+
151
+ app.start()
152
+ ```
153
+
154
+ ## Want to know more?
155
+
156
+ Take a look at our excellent [documentation](https://mojolicious.github.io/mojo.py/)!
@@ -0,0 +1,115 @@
1
+ <p align="center">
2
+ <a href="https://mojolicious.github.io/mojo.py/">
3
+ <img src="https://github.com/mojolicious/mojo.py/blob/main/docs/images/logo.png?raw=true" style="margin: 0 auto;">
4
+ </a>
5
+ </p>
6
+
7
+ [![](https://github.com/mojolicious/mojo.py/workflows/test/badge.svg)](https://github.com/mojolicious/mojo.py/actions)
8
+ [![Coverage Status](https://coveralls.io/repos/github/mojolicious/mojo.py/badge.svg?branch=main)](https://coveralls.io/github/mojolicious/mojo.py?branch=main)
9
+ [![PyPI](https://img.shields.io/pypi/v/mojolicious.svg)](https://pypi.org/project/mojolicious/)
10
+ [![Documentation](https://img.shields.io/badge/docs-mojolicious.github.io-blue)](https://mojolicious.github.io/mojo.py/)
11
+
12
+ > **Warning:** Mojolicious is currently **highly experimental**, APIs can still change without warning until the 1.0
13
+ > release. Please don't use it in production yet.
14
+
15
+ The [Mojolicious](https://mojolicious.org) real-time web framework for Python. Meticulously designed for hypermedia-driven
16
+ backend web services, built on [ASGI](https://asgi.readthedocs.io) and all the latest Python features. It is
17
+ installed from PyPI as `mojolicious`, and developed in the [mojo.py](https://github.com/mojolicious/mojo.py)
18
+ repository.
19
+
20
+ If you want to stay up to date on the [latest developments](https://github.com/mojolicious/mojo.py/blob/main/CHANGELOG.md)
21
+ join us on [IRC](https://web.libera.chat/#mojo).
22
+
23
+ ## Features
24
+
25
+ * A **real-time web framework**, allowing you to easily grow single file prototypes into well-structured MVC web
26
+ applications.
27
+ * Powerful out of the box with RESTful routes, WebSockets, Server-Sent Events, plugins, commands, logging,
28
+ [Jinja2](https://jinja.palletsprojects.com) templates, content negotiation, session management, form and JSON
29
+ validation, testing framework, static file server, first class Unicode support and much more for you to discover.
30
+ * A powerful **web development toolkit**, that you can use for all kinds of applications, independently of the web
31
+ framework.
32
+ * HTTP and WebSocket client with support for HTTPS/WSS, cookies, redirects, urlencoded/multi-part forms, file
33
+ uploads, JSON/YAML, HTML/XML, proxies and UNIX domain sockets.
34
+ * HTML/XML parser with CSS selector support.
35
+ * Plays nice with the ecosystem: every application is an ASGI application, and any ASGI application can be mounted
36
+ into yours.
37
+ * Fully typed, with very clean `async`/`await` based APIs.
38
+ * Only mature and widely used dependencies, hidden behind Mojolicious APIs wherever possible, for long term support and
39
+ **backwards compatibility** once 1.0 has been released.
40
+
41
+ ## Installation
42
+
43
+ All you need is Python 3.12 (or newer).
44
+
45
+ ```
46
+ $ pip install mojolicious
47
+ ```
48
+
49
+ ## Getting Started
50
+
51
+ These four lines are a whole web application.
52
+
53
+ ```python
54
+ from mojolicious import App
55
+
56
+ app = App()
57
+
58
+ app.get('/', lambda ctx: ctx.render(text='I ♥ Mojo!'))
59
+
60
+ app.start()
61
+ ```
62
+
63
+ Use the built-in command system to start your web server.
64
+
65
+ ```
66
+ $ python app.py server
67
+ Web application available at http://127.0.0.1:3000/
68
+ ```
69
+
70
+ Test it with any HTTP client you prefer.
71
+
72
+ ```
73
+ $ curl http://127.0.0.1:3000/
74
+ I ♥ Mojo!
75
+ ```
76
+
77
+ ## Duct Tape for the Web
78
+
79
+ Use all the latest Python and HTML features in convenient single file prototypes like this one, and grow them easily
80
+ into well-structured **Model-View-Controller** web applications.
81
+
82
+ ```python
83
+ from mojolicious import App
84
+
85
+ app = App()
86
+
87
+
88
+ @app.get('/')
89
+ async def index(ctx):
90
+ await ctx.render(inline=TEMPLATE)
91
+
92
+
93
+ @app.websocket('/title')
94
+ async def title(ctx):
95
+ ws = await ctx.accept()
96
+ async for url in ws:
97
+ res = await ctx.ua.get(url)
98
+ html = await res.html()
99
+ await ws.send(html.at('title').text())
100
+
101
+
102
+ TEMPLATE = """
103
+ <script>
104
+ const ws = new WebSocket('{{ url_for('title') }}');
105
+ ws.onmessage = event => { document.body.innerHTML += event.data };
106
+ ws.onopen = event => { ws.send('https://mojolicious.org') };
107
+ </script>
108
+ """
109
+
110
+ app.start()
111
+ ```
112
+
113
+ ## Want to know more?
114
+
115
+ Take a look at our excellent [documentation](https://mojolicious.github.io/mojo.py/)!
@@ -0,0 +1,215 @@
1
+
2
+ # Cheatsheet
3
+
4
+ A quick overview of the most important Mojolicious classes, helpers, and hooks.
5
+
6
+ ## Classes
7
+
8
+ ### App
9
+
10
+ ```python
11
+ from mojolicious import App
12
+
13
+ app = App(config=None, detect_import=True, exception_format='html', home=None, mode=None, secrets=None)
14
+
15
+ # Routes (all return routes, which are also decorators)
16
+ app.any(['GET', 'POST'], '/path', placeholder=r'\d+')
17
+ app.get('/path')
18
+ app.post('/path')
19
+ app.put('/path')
20
+ app.patch('/path')
21
+ app.delete('/path')
22
+ app.options('/path')
23
+ app.query('/path')
24
+ app.websocket('/path')
25
+ app.under('/path')
26
+
27
+ # Extensions
28
+ app.helper # or app.helper('nested.name')
29
+ app.hook('dispatch:before')
30
+ app.on_start
31
+ app.on_stop
32
+ app.plugin(plugin, **options)
33
+ app.decorate_context('name', value)
34
+
35
+ # Components
36
+ app.cli
37
+ app.config
38
+ app.defaults
39
+ app.exception_format
40
+ app.home
41
+ app.log
42
+ app.max_request_size
43
+ app.mime
44
+ app.mode
45
+ app.models
46
+ app.mounts
47
+ app.renderer
48
+ app.router
49
+ app.secrets
50
+ app.session
51
+ app.static
52
+ app.ua
53
+ app.validator
54
+
55
+ # Testing and running
56
+ app.new_mock_context(method='GET', path='/', headers=None)
57
+ app.test_ua()
58
+ app.start()
59
+ ```
60
+
61
+ ### Route
62
+
63
+ ```python
64
+ route = app.get('/user/:id', id=r'\d+')
65
+ route.to('controller#action', title='Default')
66
+ route.to(action_function)
67
+ route.name('show_user')
68
+ route.requires('host', r'example\.com')
69
+ route.under('/nested')
70
+ route.get('/child')
71
+ route.remove()
72
+ route.render({'id': 23})
73
+ route.suggested_method()
74
+ ```
75
+
76
+ ### Context
77
+
78
+ <!-- fmt:off -->
79
+ ```python
80
+ ctx.app
81
+ ctx.config
82
+ ctx.content
83
+ ctx.exception_format
84
+ ctx.flash
85
+ ctx.home
86
+ ctx.log
87
+ ctx.models
88
+ ctx.plan
89
+ ctx.req
90
+ ctx.res
91
+ ctx.session
92
+ ctx.stash
93
+ ctx.ua
94
+ ctx.ws
95
+
96
+ ctx.accepts(['html', 'json'])
97
+ ws = await ctx.accept(json=False, protocol=None)
98
+ await ctx.content_for('head', '<meta>')
99
+ await ctx.params(not_empty=False)
100
+ await ctx.redirect_to('route_name', status=302, **values)
101
+ await ctx.render(text=None, json=..., yaml=..., data=None, inline=None, inline_layout=None, view=None, layout=None,
102
+ format=None, variant=None, engine=None, status=None, pretty=False, maybe=False, **stash)
103
+ await ctx.render_to_string('view', **stash)
104
+ await ctx.respond_to(json={'json': {}}, html=action, any={'status': 204})
105
+ await ctx.send_file(path, directory=None, download=None)
106
+ await ctx.validation()
107
+ await ctx.write_sse('Hello', type='message', id=None, comment=None)
108
+ ctx.finish_sse()
109
+ ctx.schema(schema)
110
+ ctx.set_signed_cookie('name', 'value', path='/')
111
+ ctx.signed_cookie('name')
112
+ ctx.url_for('route_name', absolute=False, fragment=None, query=None, **values)
113
+ ctx.url_for_asset('app.js')
114
+ ctx.url_for_file('logo.png')
115
+ ctx.url_with('current', query={'page': 2})
116
+ ```
117
+
118
+ ### Request
119
+
120
+ ```python
121
+ ctx.req.base_path
122
+ ctx.req.base_url
123
+ ctx.req.headers
124
+ ctx.req.ip
125
+ ctx.req.is_secure
126
+ ctx.req.is_websocket
127
+ ctx.req.method
128
+ ctx.req.path
129
+ ctx.req.protocol
130
+ ctx.req.query
131
+ ctx.req.request_id
132
+ ctx.req.url
133
+ ctx.req.userinfo
134
+ ctx.req.max_message_size
135
+
136
+ ctx.req.get('Accept')
137
+ ctx.req.cookies.get('name')
138
+ await ctx.req.buffer()
139
+ await ctx.req.text()
140
+ await ctx.req.json()
141
+ await ctx.req.yaml()
142
+ await ctx.req.html()
143
+ await ctx.req.xml()
144
+ await ctx.req.form()
145
+ await ctx.req.upload('name')
146
+ async for upload in ctx.req.files(): ...
147
+ async for chunk in ctx.req: ...
148
+ ```
149
+ <!-- fmt:on -->
150
+
151
+ ### Response
152
+
153
+ ```python
154
+ ctx.res.status(201)
155
+ ctx.res.type('text/plain')
156
+ ctx.res.set('X-Header', 'value')
157
+ ctx.res.append('Vary', 'Accept')
158
+ ctx.res.length(100)
159
+ ctx.res.set_cookie('name', 'value', path='/', http_only=True, same_site='lax')
160
+ await ctx.res.send('Hello World!')
161
+ ctx.res.headers
162
+ ctx.res.is_sent
163
+ ctx.res.status_code
164
+ ```
165
+
166
+ ## Helpers
167
+
168
+ | Helper | Description |
169
+ |---|---|
170
+ | `csrf_token()` | Masked CSRF token for the current session, also accepted in an `X-CSRF-Token` header |
171
+ | `current_route()` | Name of the current route |
172
+ | `exception(error)` | Render an exception response or close the WebSocket |
173
+ | `html_exception(error)`, `json_exception(error)`, `txt_exception(error)` | Exception responses in a specific format |
174
+ | `html_not_found()`, `json_not_found()`, `txt_not_found()` | Not found responses in a specific format |
175
+ | `include(view, **stash)` | Render a partial view |
176
+ | `inspect(value)` | Pretty print a value |
177
+ | `is_fresh(etag=, last_modified=)` | Conditional GET |
178
+ | `not_found()` | Render a not found response |
179
+ | `proxy_get(url)`, `proxy_post(url)`, `proxy_request(method, url)` | Stream a response from another server |
180
+ | `tag(name, content, **attrs)` | Generate an HTML tag |
181
+ | `signed_cookie(name)`, `set_signed_cookie(name, value)` | Cookies signed with the application secrets |
182
+ | `timing.begin(name)`, `timing.elapsed(name)`, `timing.rps(seconds)`, `timing.server_timing(metric)` | Timers and `Server-Timing` headers |
183
+ | `tags.*` | Tag helpers, see the [Rendering](Rendering.md) guide |
184
+
185
+ ## Hooks
186
+
187
+ | Hook | Arguments | Description |
188
+ |---|---|---|
189
+ | `command:before` | `app, args` | Before a command runs |
190
+ | `command:init` | `app, args` | After commands have been loaded |
191
+ | `server:start` | `app` | A server has been started |
192
+ | `app:start` | `app` | Application startup |
193
+ | `server:stop` | `app` | A server has been stopped |
194
+ | `command:after` | `app, args` | After a command has run |
195
+ | `app:stop` | `app` | Application shutdown |
196
+ | `dispatch:before` | `ctx` | Before static files and router |
197
+ | `static:before` | `ctx, path` | Before a static file is served |
198
+ | `router:before` | `ctx` | Before the router |
199
+ | `render:before` | `ctx, options` | Before content is rendered |
200
+ | `send:before` | `ctx, body` | Before the response is sent |
201
+
202
+ ## Commands
203
+
204
+ | Command | Description |
205
+ |---|---|
206
+ | `server` | Start application with web server |
207
+ | `get` | Perform HTTP request |
208
+ | `routes` | Show available routes |
209
+ | `eval` | Run code against application |
210
+ | `repl` | Start a REPL for application |
211
+ | `version` | Show versions of available modules |
212
+ | `mojolicious create-lite-app` | Create a single file application |
213
+ | `mojolicious create-full-app` | Create a well-structured application |
214
+ | `mojolicious create-plugin` | Create a plugin |
215
+ | `mojolicious get` | Perform HTTP request, and extract data with CSS selectors or JSON Pointers |
@@ -0,0 +1,163 @@
1
+
2
+ # Contributing
3
+
4
+ There are many ways to contribute to Mojolicious, this guide will show you a few of them.
5
+
6
+ ## Reporting Bugs
7
+
8
+ We use the [GitHub issue tracker](https://github.com/mojolicious/mojo.py/issues), so you'll need to create a (free)
9
+ GitHub account to be able to submit issues, comments and pull requests.
10
+
11
+ First of all, make sure you are using the latest version of Mojolicious, it is quite likely that your
12
+ bug has already been fixed. If that doesn't help, take a look at the list of currently open issues, perhaps it has
13
+ already been reported by someone else and you can just add a comment confirming it.
14
+
15
+ If it hasn't been reported yet, try to prepare a test case demonstrating the bug, you are not expected to fix it
16
+ yourself, but you'll have to make sure the developers can replicate your problem. Sending in your whole application
17
+ generally does more harm than good, the `tests` directory of this distribution has many good examples for how to do it
18
+ right. Writing a test is usually the hardest part of fixing a bug, so the better your test case the faster it can be
19
+ fixed. ;)
20
+
21
+ And don't forget to add a descriptive title and text, when you create a new issue. If your issue does not contain
22
+ enough information or is unintelligible, it might get closed pretty quickly. But don't be disheartened, if there's new
23
+ activity it will get reopened just as quickly.
24
+
25
+ ## Reporting Security Issues
26
+
27
+ Please report security issues privately, as described in our [security policy](https://github.com/mojolicious/mojo.py/blob/main/SECURITY.md).
28
+
29
+ ## Resolving Issues
30
+
31
+ There are many ways in which you can help us resolve existing issues on the
32
+ [GitHub issue tracker](https://github.com/mojolicious/mojo.py/issues).
33
+
34
+ Can you replicate the problem on your computer? Add a comment saying that you're seeing the same. Perhaps you can
35
+ provide additional information that will make it easier for others to replicate the problem, maybe even contribute a
36
+ better test case.
37
+
38
+ And for all code contributions we very much appreciate additional testing and code review, just add a comment to show
39
+ your approval or to point out flaws that need to be addressed.
40
+
41
+ ## Contributing Documentation
42
+
43
+ One of the easiest ways to contribute to Mojolicious is through documentation improvements.
44
+
45
+ Pull requests with additions or changes to the documentation included in the Mojolicious distribution
46
+ follow the same rules as code contributions. Please don't send pull requests for overly simplistic changes, such as the
47
+ addition of a comma or semicolon.
48
+
49
+ ## Contributing Code
50
+
51
+ All code contributions should be sent as [GitHub pull requests](https://help.github.com/articles/using-pull-requests).
52
+ But please try to avoid pull requests with very simplistic changes, such as a single typo fix somewhere in the
53
+ documentation or comments.
54
+
55
+ An expressive title and detailed description are invaluable during the review process, which usually ends when members
56
+ of the community have voiced their opinions and the core team reviewed the changes. For a pull request to get merged it
57
+ requires three positive reviews from voting members of the core team.
58
+
59
+ All code changes should emulate the style of the surrounding code, include tests that fail without them, and update
60
+ relevant documentation.
61
+
62
+ While the Mojolicious distribution covers a wide range of features, we are rather conservative when
63
+ it comes to adding new ones. So if your contribution is not a simple bug fix, it is **strongly recommended** that you
64
+ discuss it in advance in the [Forum](https://github.com/mojolicious/mojo.py/discussions), or the official
65
+ [IRC](https://web.libera.chat/#mojo) channel, to avoid unnecessary work and to increase its chances of
66
+ getting accepted.
67
+
68
+ Before you send a pull request, make sure that all checks pass, the CI runs exactly the same ones.
69
+
70
+ ```
71
+ $ uv sync
72
+ $ uv run pytest
73
+ $ uv run ruff check
74
+ $ uv run ruff format --check
75
+ $ uv run pyright
76
+ $ uv run coverage run -m pytest && uv run coverage combine && uv run coverage report
77
+ $ uv run --group docs sphinx-build -W -b html docs docs/_build/html
78
+ ```
79
+
80
+ From 1.0 onward all public APIs are covered by our [compatibility promise](FAQ.md), so changes that might break
81
+ existing applications need a deprecation period. New dependencies are only added when the standard library cannot do
82
+ the job just as well, and they always have to be hidden behind Mojolicious APIs.
83
+
84
+ ## Code of Conduct
85
+
86
+ Like the technical community as a whole, the Mojolicious team and community is made up of a mixture
87
+ of professionals and volunteers from all over the world, working on every aspect of the mission - including mentorship,
88
+ teaching, and connecting people.
89
+
90
+ Diversity is one of our huge strengths, but it can also lead to communication issues and unhappiness. To that end, we
91
+ have a few ground rules that we ask people to adhere to. This code applies equally to founders, mentors and those
92
+ seeking help and guidance.
93
+
94
+ This isn't an exhaustive list of things that you can't do. Rather, take it in the spirit in which it’s intended - a
95
+ guide to make it easier to enrich all of us and the technical communities in which we participate.
96
+
97
+ This code of conduct applies to all spaces managed by the Mojolicious project. This includes IRC,
98
+ GitHub discussions, the issue tracker, and any other forums created by the project team which the community uses for
99
+ communication. In addition, violations of this code outside these spaces may affect a person's ability to participate
100
+ within them.
101
+
102
+ If you believe someone is violating the code of conduct, we ask that you report it by emailing Joel Berger
103
+ (`jberger@mojolicious.org`) or Sebastian Riedel (`kraih@mojolicious.org`).
104
+
105
+ * **Be friendly and patient.**
106
+
107
+ * **Be welcoming.**
108
+
109
+ We strive to be a community that welcomes and supports people of all backgrounds and identities. This includes, but
110
+ is not limited to members of any race, ethnicity, culture, national origin, colour, immigration status, social and
111
+ economic class, educational level, sex, sexual orientation, gender identity and expression, age, size, family status,
112
+ political belief, religion, and mental and physical ability.
113
+
114
+ * **Be considerate.**
115
+
116
+ Your work will be used by other people, and you in turn will depend on the work of others. Any decision you take will
117
+ affect users and colleagues, and you should take those consequences into account when making decisions. Remember that
118
+ we're a world-wide community, so you might not be communicating in someone else's primary language.
119
+
120
+ * **Be respectful.**
121
+
122
+ Not all of us will agree all the time, but disagreement is no excuse for poor behavior and poor manners. We might all
123
+ experience some frustration now and then, but we cannot allow that frustration to turn into a personal attack. It’s
124
+ important to remember that a community where people feel uncomfortable or threatened is not a productive one. Members
125
+ of the Mojolicious community should be respectful when dealing with other members as well as with
126
+ people outside the Mojolicious community.
127
+
128
+ * **Be careful in the words that you choose.**
129
+
130
+ We are a community of professionals, and we conduct ourselves professionally. Be kind to others. Do not insult or put
131
+ down other participants. Harassment and other exclusionary behavior aren't acceptable. This includes, but is not
132
+ limited to:
133
+
134
+ * Violent threats or language directed against another person.
135
+
136
+ * Discriminatory jokes and language.
137
+
138
+ * Posting sexually explicit or violent material.
139
+
140
+ * Posting (or threatening to post) other people's personally identifying information ("doxing").
141
+
142
+ * Personal insults, especially those using racist or sexist terms.
143
+
144
+ * Unwelcome sexual attention.
145
+
146
+ * Advocating for, or encouraging, any of the above behavior.
147
+
148
+ * Repeated harassment of others. In general, if someone asks you to stop, then stop.
149
+
150
+
151
+ * **When we disagree, try to understand why.**
152
+
153
+ Disagreements, both social and technical, happen all the time and Mojolicious is no exception. It is important that we
154
+ resolve disagreements and differing views constructively. Remember that we’re different. The strength of Mojolicious
155
+ comes from its varied community, people from a wide range of backgrounds. Different people have different perspectives
156
+ on issues. Being unable to understand why someone holds a viewpoint doesn’t mean that they’re wrong. Don’t forget that
157
+ it is human to err and blaming each other doesn’t get us anywhere. Instead, focus on helping to resolve issues and
158
+ learning from mistakes.
159
+
160
+ ## Support
161
+
162
+ If you have any questions the documentation might not yet answer, don't hesitate to ask in the
163
+ [Forum](https://github.com/mojolicious/mojo.py/discussions), or on [IRC](https://web.libera.chat/#mojo).