Skip to content

Commit 72bfca4

Browse files
authored
Merge pull request #82 from eadwinCode/websocket_documentation
WIP: Socket IO integration and Websocket documentation
2 parents ceda55b + c71cfc4 commit 72bfca4

File tree

138 files changed

+1933
-266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+1933
-266
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<a href="#" target="blank"><img src="docs/img/EllarLogoIconOnly.png" width="200" alt="Ellar Logo" /></a>
2+
<a href="#" target="blank"><img src="docs/img/EllarLogoB.png" width="200" alt="Ellar Logo" /></a>
33
</p>
44

55
<p align="center"> Ellar - Python ASGI web framework for building fast, efficient and scalable RESTAPIs and server-side application. </p>
@@ -16,8 +16,6 @@ Ellar is a lightweight ASGI framework for building efficient and scalable server
1616
It supports both OOP (Object-Oriented Programming) and FP (Functional Programming)
1717

1818
Ellar is based on [Starlette (ASGI toolkit)](https://www.starlette.io/), a lightweight ASGI framework/toolkit well-suited for developing asynchronous web services with Python.
19-
While Ellar provides a high level of abstraction on top of Starlette, it still incorporates some of its features, as well as those of FastAPI.
20-
If you are familiar with these frameworks, you will find it easy to understand and use Ellar.
2119

2220
## **Features Summary**
2321

@@ -87,7 +85,7 @@ ellar create-module car
8785
## **Add Schema**
8886
In `car/schema.py`, lets add some serializer for car input and output data
8987
```python
90-
from ellar.serializer import Serializer
88+
from ellar.core.serializer import Serializer
9189

9290
class CarSerializer(Serializer):
9391
name: str
@@ -228,8 +226,7 @@ class CarModule(ModuleBase):
228226
Ellar is not aware of `CarModule` yet, so we need to add it to the `modules` list of `ApplicationModule` at the `carsite/root_module.py`.
229227
```python
230228
from ellar.common import Module, exception_handler
231-
from ellar.core import IHostContext, ModuleBase
232-
from ellar.core.response import JSONResponse, Response
229+
from ellar.core import IHostContext, ModuleBase, JSONResponse, Response
233230

234231
from ellar.samples.modules import HomeModule
235232
from .apps.car.module import CarModule
@@ -249,7 +246,7 @@ then add the following below.
249246
import os
250247

251248
from ellar.constants import ELLAR_CONFIG_MODULE
252-
from ellar.core.factory import AppFactory
249+
from ellar.core import AppFactory
253250
from ellar.openapi import OpenAPIDocumentModule, OpenAPIDocumentBuilder, SwaggerDocumentGenerator
254251
from .root_module import ApplicationModule
255252

docs/basics/testing.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,16 @@ from project_name.apps.car.schemas import CreateCarSerializer, CarListFilter
322322
from project_name.apps.car.services import CarRepository
323323

324324

325+
class MockCarRepository(CarRepository):
326+
def get_all(self):
327+
return [dict(id=2, model='CLS',name='Mercedes', year=2023)]
328+
329+
325330
class TestCarControllerE2E:
326331
def setup(self):
327332
test_module = Test.create_test_module(
328333
controllers=[CarController,],
329-
providers=[ProviderConfig(CarRepository, use_class=CarRepository)],
334+
providers=[ProviderConfig(CarRepository, use_class=MockCarRepository)],
330335
config_module=dict(
331336
REDIRECT_SLASHES=True
332337
)
@@ -346,8 +351,7 @@ class TestCarControllerE2E:
346351
"year": 2022,
347352
}
348353

349-
@patch.object(CarRepository, 'get_all', return_value=[dict(id=2, model='CLS',name='Mercedes', year=2023)])
350-
def test_get_all_action(self, mock_get_all):
354+
def test_get_all_action(self):
351355
res = self.client.get('/car?offset=0&limit=10')
352356
assert res.status_code == 200
353357
assert res.json() == {

docs/handling-response/response-model.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This response model holds information on the type of response to be returned.
66
```python
77
# project_name/apps/items/controllers.py
88

9-
from ellar.serializer import Serializer
9+
from ellar.core.serializer import Serializer
1010
from ellar.common import Controller, get
1111
from ellar.core import ControllerBase
1212

@@ -30,7 +30,7 @@ During route response computation, the `me` route handler response will evaluate
3030
The resulting route responses will be:
3131

3232
```python
33-
from ellar.serializer import Serializer
33+
from ellar.core.serializer import Serializer
3434
from ellar.core.response.model import JSONResponseModel
3535

3636

@@ -76,7 +76,7 @@ For example:
7676
from ellar.common import Controller, get
7777
from ellar.core import ControllerBase
7878
from starlette.responses import PlainTextResponse
79-
from ellar.serializer import Serializer
79+
from ellar.core.serializer import Serializer
8080

8181

8282
class UserSchema(Serializer):

docs/handling-response/response.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ To use `Serializer` in Ellar, you simply need to create a class that inherits fr
55
Here's an example of how you could define a serializer class for a user model:
66

77
```python
8-
from ellar.serializer import Serializer
8+
from ellar.core.serializer import Serializer
99

1010
class UserSerializer(Serializer):
1111
name: str
@@ -27,7 +27,7 @@ For example:
2727
```python
2828
# project_name/apps/items/controllers.py
2929

30-
from ellar.serializer import Serializer
30+
from ellar.core.serializer import Serializer
3131
from ellar.common import Controller, get
3232
from ellar.core import ControllerBase
3333

@@ -80,7 +80,7 @@ For instance, we can convert the `UserSchema` to a dataclass by defining `UserDa
8080

8181
```python
8282
from dataclasses import dataclass
83-
from ellar.serializer import DataclassSerializer
83+
from ellar.core.serializer import DataclassSerializer
8484

8585

8686
@dataclass
@@ -101,7 +101,7 @@ The `response` parameter takes different shape. Let's see how to return a differ
101101
```python
102102
# project_name/apps/items/controllers.py
103103

104-
from ellar.serializer import Serializer
104+
from ellar.core.serializer import Serializer
105105
from ellar.common import Controller, get
106106
from ellar.core import ControllerBase
107107

@@ -185,7 +185,7 @@ Also, we can return response object from endpoint functions, and it will overrid
185185
```python
186186
# project_name/apps/items/controllers.py
187187

188-
from ellar.serializer import Serializer
188+
from ellar.core.serializer import Serializer
189189
from ellar.common import Controller, get
190190
from ellar.core import ControllerBase
191191
from starlette.responses import PlainTextResponse

docs/img/live_support_websocket.gif

69.9 KB
Loading

docs/index.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
Ellar is a lightweight ASGI framework for building efficient and scalable server-side python applications.
1616
It supports both OOP (Object-Oriented Programming) and FP (Functional Programming)
1717

18-
Ellar is based on [Starlette (ASGI toolkit)](https://www.starlette.io/), a lightweight ASGI framework/toolkit well-suited for developing asynchronous web services in Python.
19-
And while Ellar provides a high level of abstraction on top of Starlette, it still incorporates some of its features, as well as those of FastAPI.
20-
If you are familiar with these frameworks, you will find it easy to understand and use Ellar.
18+
Ellar is also a higher level of abstraction of [Starlette (ASGI toolkit)](https://www.starlette.io/), a lightweight ASGI framework/toolkit well-suited for developing asynchronous web services in Python.
2119

2220
## **Inspiration**
23-
Ellar was deeply influenced by [NestJS](https://docs.nestjs.com/) for its ease of use and ability to handle complex project structures and applications.
24-
Additionally, it took some concepts from [FastAPI](https://fastapi.tiangolo.com/) in terms of request parameter handling and data serialization with Pydantic.
21+
Ellar was deeply influenced by [NestJS](https://docs.nestjs.com/) for its ease of use, project structures and patterns that aids in building small or complex project applications.
22+
Also, Ellar took some concepts from [FastAPI](https://fastapi.tiangolo.com/) in terms of request parameter handling and data serialization with Pydantic.
23+
24+
The objective of Ellar is to provide a high level of abstracted interface to the web, along with a well-structured project setup, give room for object-oriented approach to web application design,
25+
allow you chose your desired application architecture, and ultimately, deliver speedy handling to requests.
26+
27+
As developers, we never know how big a project can become or evolve over time but following some design patterns and architecture makes it easier to build a more testable and maintainable application.
2528

26-
With that said, the objective of Ellar is to offer a high level of abstraction in its framework APIs, along with a well-structured project setup, an object-oriented approach to web application design,
27-
the ability to adapt to any desired software architecture, and ultimately, speedy request handling.
2829

2930

3031
## **Features Summary**

docs/overview/controllers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Before that, we need to define our data input/output serializers
215215

216216
```python
217217
# project_name/apps/car/schema.py
218-
from ellar.serializer import Serializer
218+
from ellar.core.serializer import Serializer
219219
from pydantic import Field
220220

221221

@@ -258,7 +258,7 @@ Ellar will compute values for all the route handler parameters and validates the
258258
!!! info
259259
if a parameter is not annotated, it will be assumed as a `string` type
260260

261-
![CreateDogSchema](../img/create-car-schema.png)
261+
![CreateCarSchema](../img/create-car-schema.png)
262262

263263
Let's add other endpoints
264264

docs/overview/custom_decorators.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ from ellar.core import WebSocket
4646
def sample_endpoint_ws(self, websocket: WebSocket, data_schema: str = WsBody()):
4747
pass
4848

49-
@sample_endpoint_ws.connect
49+
@ws_route.connect(sample_endpoint_ws)
5050
async def on_connect(self, websocket: WebSocket):
51+
# Called when there is a connection to `sample_endpoint_ws`
5152
await websocket.accept()
5253

53-
@sample_endpoint_ws.disconnect
54-
async def on_connect(self, websocket: WebSocket, code: int):
54+
@ws_route.disconnect(sample_endpoint_ws)
55+
async def on_disconnect(self, websocket: WebSocket, code: int):
56+
# Called when there is a disconnect from `sample_endpoint_ws`
5557
await websocket.close(code)
5658
```
5759

@@ -253,7 +255,7 @@ And the route function is required to return a dictionary object that follows a
253255
```python
254256
import typing as t
255257
from enum import Enum
256-
from ellar.serializer import Serializer
258+
from ellar.core.serializer import Serializer
257259

258260

259261
class ContentDispositionType(str, Enum):
@@ -361,7 +363,7 @@ For example:
361363
```python
362364
import typing as t
363365
from ellar.common import serializer_filter, get
364-
from ellar.serializer import Serializer
366+
from ellar.core.serializer import Serializer
365367

366368
class UserSchema(Serializer):
367369
username: str

docs/overview/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ Brief overview of the generated files:
146146
|-------------------|---------------------------------------------------|
147147
| `car.controllers` | A basic controller with an `index` route. |
148148
| `car.module.py` | car module/app `Module` metadata definition. |
149-
| `car.services.py` | For Dogs module service declarations. |
149+
| `car.services.py` | For Car module service declarations. |
150150
| `car.schemas.py` | Data-transfer-object or Serializers declarations. |
151-
| `car.tests/` | testing directory for the dogs module. |
151+
| `car.tests/` | testing directory for the car module. |
152152
153-
To finish up with the created `dogs` module, we need to register it to the
153+
To finish up with the created `car` module, we need to register it to the
154154
`project_name.root_module.py`
155155
156156
```python
@@ -167,7 +167,7 @@ class ApplicationModule(ModuleBase):
167167
```
168168
That's it.
169169
170-
Goto your browser and visit: [http://localhost:8000/dogs/](http://localhost:8000/car/)
170+
Goto your browser and visit: [http://localhost:8000/car/](http://localhost:8000/car/)
171171
```json
172172
{
173173
"detail": "Welcome Car Resource"

docs/parsing-inputs/body.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ First, you need to import `Serializer` from `ella.serializer`:
1414

1515
```python
1616
# project_name/apps/items/controllers.py
17-
from ellar.serializer import Serializer
17+
from ellar.core.serializer import Serializer
1818

1919
# class Item(Serializer):
2020
# name: str
@@ -33,7 +33,7 @@ Use standard Python types for all the attributes:
3333
```python
3434
# project_name/apps/items/controllers.py
3535

36-
from ellar.serializer import Serializer
36+
from ellar.core.serializer import Serializer
3737
from ellar.common import Controller, post
3838
from ellar.core import ControllerBase
3939

@@ -81,7 +81,7 @@ To add it to your *path operation*, declare it the same way you declared the pat
8181
```python
8282
# project_name/apps/items/controllers.py
8383

84-
from ellar.serializer import Serializer
84+
from ellar.core.serializer import Serializer
8585
from ellar.common import Controller, post
8686
from ellar.core import ControllerBase
8787

@@ -137,7 +137,7 @@ You can declare path parameters **and** body requests at the same time.
137137
```python
138138
# project_name/apps/items/controllers.py
139139

140-
from ellar.serializer import Serializer
140+
from ellar.core.serializer import Serializer
141141
from ellar.common import Controller, post, put
142142
from ellar.core import ControllerBase
143143

@@ -168,7 +168,7 @@ You can also declare **body**, **path** and **query** parameters, all at the sam
168168
```python
169169
# project_name/apps/items/controllers.py
170170

171-
from ellar.serializer import Serializer
171+
from ellar.core.serializer import Serializer
172172
from ellar.common import Controller, post, put
173173
from ellar.core import ControllerBase
174174

@@ -213,7 +213,7 @@ But you can instruct **Ellar** to treat it as another body key using Body:
213213
```python
214214
# project_name/apps/items/controllers.py
215215

216-
from ellar.serializer import Serializer
216+
from ellar.core.serializer import Serializer
217217
from ellar.common import Controller, Body, post, put
218218
from ellar.core import ControllerBase
219219
from pydantic import BaseModel
@@ -274,7 +274,7 @@ For example:
274274
```python
275275
# project_name/apps/items/controllers.py
276276

277-
from ellar.serializer import Serializer
277+
from ellar.core.serializer import Serializer
278278
from ellar.common import Controller, Body, post, put
279279
from ellar.core import ControllerBase
280280
from pydantic import BaseModel

0 commit comments

Comments
 (0)