Skip to content

Commit

Permalink
Minor documentation refinements (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
paolodina authored May 1, 2024
1 parent d236534 commit 1d675d2
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 75 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ custom or enterprise, fits within Esmerald ecosystem without scalability issues.
## Settings

Like every other framework, when starting an application, a lot of [settings](./application/settings.md) can/need to be
passed to the main object and this can be very dauting and hugly to maintain and see.
passed to the main object and this can be very dauting and ugly to maintain and see.

Esmerald comes with the
[settings](./application/settings.md) in mind. A set of defaults that can be overridden by your very own settings
module but not limited to it as you can still use the classic approach of passing everything into a
module but not limited to it, as you can still use the classic approach of passing everything into a
Esmerald instance directly when instantiating.

**Example of classic approach**:
Expand Down Expand Up @@ -251,7 +251,7 @@ from esmerald import EsmeraldAPISettings
from esmerald.conf.enums import EnvironmentType

class Development(EsmeraldAPISettings):
app_name: bool = 'My app in dev'
app_name: str = 'My app in dev'
environment: str = EnvironmentType.DEVELOPMENT

```
Expand Down Expand Up @@ -485,7 +485,7 @@ app = Esmerald(routes=[Include('src.urls')])

## Run the application

As mentioned before, we recomment uvicorn for production but it's not mandatory.
As mentioned before, we recommend uvicorn for production but it's not mandatory.

**Using uvicorn**:

Expand Down
16 changes: 8 additions & 8 deletions docs/application/applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ of its functionality.

Because the swagger and redoc can only do so much, for example with the
`username = request.path_params["username"]` **you won't be able to test it via docs**.
**The best way of doing it is by calling the API directly via any prefered client or browser.**
**The best way of doing it is by calling the API directly via any preferred client or browser.**

In other words, the path param can be captured using the Request.path_params, but cannot be tested from the Swagger UI.

Expand All @@ -50,12 +50,12 @@ Via Insomnia:

### Instantiating the application

Creating an appliation instance can be done in different ways and with a great plus of using the
Creating an application instance can be done in different ways and with a great plus of using the
[settings](./settings.md) for a cleaner approach.

**Parameters**:

* **debug** - Boolean indicating if a debug tracebacks should be returns on errors. Basically, debug mode,
* **debug** - Boolean indicating if debug tracebacks should be returned on errors. Basically, debug mode,
very useful for development.
* **title** - The title for the application. Used for OpenAPI.
* **app_name** - The application name. Used also for OpenAPI.
Expand Down Expand Up @@ -83,7 +83,7 @@ or <a href='https://www.lilya.dev/middleware/' target='_blank'>Lilya Middleware<
internally. Read more about [Python Protocols](https://peps.python.org/pep-0544/).
* **dependencies** - A dictionary of string and [Inject](.././dependencies.md) instances enable application level dependency
injection.
* **exception handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler
* **exception_handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler
functions on an application top level. Exception handler callables should be of the form of
`handler(request, exc) -> response` and may be be either standard functions, or async functions.
* **csrf_config** - If [CSRFConfig](../configurations/csrf.md) is set it will enable the CSRF built-in middleware.
Expand All @@ -96,7 +96,7 @@ application static files configuration.
engine from the configuration object.
* **session_config** - If [SessionConfig](../configurations/session.md) is set it will enable the session
built-in middleware.
* **response_class** - Custom subclass of [Response](../responses.md) to be used as application application response
* **response_class** - Custom subclass of [Response](../responses.md) to be used as application response
class.
* **response_cookies** - List of [cookie](../datastructures.md) objects.
* **response_headers** - Mapping dictionary of header objects.
Expand All @@ -105,14 +105,14 @@ class.
* **scheduler_tasks** - A python dictionary with key and pair values as strings mapping the [scheduler tasks](../scheduler/scheduler.md).
* **scheduler_configurations** - A python dictionary with key and pair values as strings mapping the
extra configuations of [scheduler tasks](../scheduler/handler.md).
* **enable_scheduler** - Flag indicating if the appliaction `scheduler` should be enabled or not. Defaults to `False`.
* **enable_scheduler** - Flag indicating if the application `scheduler` should be enabled or not. Defaults to `False`.
* **timezone** - The application default timezone. Defaults to `UTC`.
* **on_shutdown** - A list of callables to run on application shutdown. Shutdown handler callables do not take any
arguments, and may be be either standard functions, or async functions.

* **on_startup** - A list of callables to run on application startup. Startup handler callables do not take any
arguments, and may be be either standard functions, or async functions.
* **lifepan** - The lifespan context function is a newer style that replaces on_startup / on_shutdown handlers.
* **lifespan** - The lifespan context function is a newer style that replaces on_startup / on_shutdown handlers.
Use one or the other, not both.
* **tags** - List of tags to include in the OpenAPI schema.
* **include_in_schema** - Boolean flag to indicate if should be schema included or not.
Expand Down Expand Up @@ -149,7 +149,7 @@ To access the application settings there are different ways:

### State and application instance

You can store arbitraty extra state on the application instance using the [State](../datastructures.md) instance.
You can store arbitrary extra state on the application instance using the [State](../datastructures.md) instance.

Example:

Expand Down
10 changes: 5 additions & 5 deletions docs/application/levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
An Esmerald application is composed by levels and those levels can be [Gateway](../routing/routes.md#gateway),
[WebSocketGateway](../routing/routes.md#websocketgateway), [Include](../routing/routes.md#include),
[handlers](../routing/handlers.md) or even **another Esmerald** or
[ChildEsmerald](../routing/router.md#child-esmerald-application)
[ChildEsmerald](../routing/router.md#child-esmerald-application).

There are some levels in the application, let's use an example.

Expand Down Expand Up @@ -41,17 +41,17 @@ also **first level** as independent instance.
1. [Handler](../routing/handlers.md) - The **second level**, inside the Gateway.

!!! Warning
A `ChildEsmerald` is an independent instance that is plugged into a main `Esmerald` application but since
it is like another `Esmerald` object that also means the `ChildEsmerald` does not take precedent over the top-level
A `ChildEsmerald` is an independent instance that is plugged into a main `Esmerald` application, but since
it is like another `Esmerald` object, that also means the `ChildEsmerald` does not take precedence over the top-level
application, instead, treats its own [Gateway](../routing/routes.md#gateway),
[WebSocketGateway](../routing/routes.md#websocketgateway), [Include](../routing/routes.md#include),
[handlers](../routing/handlers.md) or even another `Esmerald` or
[ChildEsmerald](../routing/router.md#child-esmerald-application) and parameters in **isolation**.

## Exceptions

`ChildEsmerald` as per **warning** above has its own rules but there are always exceptions to any almost every rule.
Although it is an independent instance with its own rules this is not applied to **every** parameter.
`ChildEsmerald`, as per **warning** above, has its own rules, but there are always exceptions to any almost every rule.
Although it is an independent instance with its own rules, this is not applied to **every** parameter.

[Middlewares](../middleware/middleware.md) and [Permissions](../permissions.md) are actually global and the rules of
precedence can be applied between an `Esmerald` instance and the corresponding `ChildEsmerald` apps.
Expand Down
19 changes: 9 additions & 10 deletions docs/application/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

Every application in a way or another needs settings for the uniqueness of the project itself.

When the complexity of a project increases and there are settings spread across the codebase it is when the things
When the complexity of a project increases and there are settings spread across the codebase, it is when the things
start to get messy.

One great framework, Django, has the settings in place but because of the legacy codebase and the complexity of almost
20 years of development of the framework, those became a bit bloated and hard to maintain.

Inspired by Django and by the experience of 99% of the developed applications using some sort of settings
(by environment, by user...), Esmerald comes equiped to handle exactly with that natively and using
(by environment, by user...), Esmerald comes equipped to handle exactly with that natively and using
[Pydantic](https://pydantic-docs.helpmanual.io/visual_studio_code/#basesettings-and-ignoring-pylancepyright-errors)
to leverage those.

Expand All @@ -23,11 +23,11 @@ There are two ways of using the settings object within an Esmerald application.
* Using the **ESMERALD_SETTINGS_MODULE**
* Using the **[settings_module](#the-settings_module)**

Each one of them has particular use cases but they also work together is perfect harmony.
Each one of them has particular use cases but they also work together in perfect harmony.

## EsmeraldAPISettings and the application

When starting a Esmerald instance if no parameters are provided, it will automatically load the defaults from the
When starting a Esmerald instance, if no parameters are provided, it will automatically load the defaults from the
system settings object, the `EsmeraldAPISettings`.

=== "No parameters"
Expand All @@ -50,7 +50,7 @@ For that reason custom settings are needed.

**All the custom settings should be inherited from the `EsmeraldAPISettings`**.

Let's assume we have three environment for one application: `production`, `testing`, `development` and a base settings
Let's assume we have three environments for one application: `production`, `testing`, `development` and a base settings
file that contains common settings across the three environments.

=== "Base"
Expand Down Expand Up @@ -87,8 +87,7 @@ to each.

## Esmerald Settings Module

Esmerald by default is looking for a `ESMERALD_SETTINGS_MODULE` environment variable to execute any custom settings,
if nothing is provided then it will execute the application defaults.
Esmerald by default is looking for a `ESMERALD_SETTINGS_MODULE` environment variable to execute any custom settings. If nothing is provided, then it will execute the application defaults.

=== "Without ESMERALD_SETTINGS_MODULE"

Expand Down Expand Up @@ -120,7 +119,7 @@ and loads it in lazy mode.
## The settings_module

This is a great tool to make your Esmerald applications 100% independent and modular. There are cases
where you simply want to plug an existing esmerald application into another and that same esmerald application
where you simply want to plug an existing Esmerald application into another and that same Esmerald application
already has unique settings and defaults.

The `settings_module` is a parameter available in every single `Esmerald` instance as well as `ChildEsmerald`.
Expand Down Expand Up @@ -303,7 +302,7 @@ The application will:
2. Will start with a middleware `HTTPSRedirectMiddleware`.

Starting the application with the above settings will make sure that has an initial `HTTPSRedirectMiddleware` and `debug`
set with values **but** what happens if you use the settings + parameters on instantiation?
set with values, **but** what happens if you use the settings + parameters on instantiation?

```python
from esmerald import Esmerald
Expand All @@ -321,7 +320,7 @@ values in the moment of instantiating an `Esmerald` object, those will become th

**Declaring parameters in the instance will always precede the values from your settings**.

The reason why you should be using settings it is because will make your codebase more organised and easier
The reason why you should be using settings is because it will make your codebase more organised and easier
to maintain.

!!! Check
Expand Down
4 changes: 2 additions & 2 deletions docs/configurations/jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ token = Token(exp=..., iat=..., sub=...)

The parameters are pretty standard from
<a href="https://python-jose.readthedocs.io/en/latest/" target='_blank'>Python JOSE</a> so you can feel
confortable with.
comfortable with.

### Generate a Token (encode)

Expand Down Expand Up @@ -141,7 +141,7 @@ There is a lot here happening but basically what are we doing?

* Checking for `token` in the header.
* Checking if the `token_type` is of `access_token` (default name from the JWTConfig and can be whatever you want) and raises
an exception if its not `access_token`.
an exception if it's not `access_token`.
* Returns the `AuthResult` object with the details of the retrieved user.

The middleware also contains a wrapper called `AuthMiddleware`. This will be used later on in the views of the user.
Expand Down
8 changes: 4 additions & 4 deletions docs/configurations/openapi/config.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenAPIConfig

OpenAPIConfig is a simple configuration with basic fields for the auto-genmerated documentation from Esmerald.
OpenAPIConfig is a simple configuration with basic fields for the auto-generated documentation from Esmerald.

Prior to version 2, there were two pieces for the documentation but now it is simplified with a simple
one.
Expand All @@ -19,7 +19,7 @@ is up to you.

## OpenAPIConfig and application

The `OpenAPIConfig` contains a bunch of simple fields that are needed to to serve the documentation
The `OpenAPIConfig` contains a bunch of simple fields that are needed to serve the documentation
and those can be easily overwritten.

Currently, by default, the URL for the documentation are:
Expand All @@ -43,13 +43,13 @@ It is very simple actually.
This will create your own `OpenAPIConfig` and pass it to the Esmerald application but what about changing the current
default `/docs` path?

Let's use a an example for clarification.
Let's use an example for clarification.

```python
{!> ../docs_src/configurations/openapi/apiview.py !}
```

From now on the url to access the `swagger` and `redoc` will be:
From now on the url to access `swagger`, `redoc` and `stoplight` will be:

* **Swagger** - `/another-url/swagger`.
* **Redoc** - `/another-url/redoc`.
Expand Down
2 changes: 1 addition & 1 deletion docs/configurations/staticfiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ StaticFilesConfig is simple set of configurations that when passed enables the b
When a StaticFilesConfig object is passed to an application instance, it will enable the static files serving.

!!! Check
StaticFiles are considereed an `app` and they are pure Lilya app so using Lilya StaticFiles
StaticFiles are considered an `app` and they are pure Lilya app, so using Lilya StaticFiles
will also work with Esmerald.

## StaticFilesConfig and application
Expand Down
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ custom or enterprise, fits within Esmerald ecosystem without scalability issues.
## Settings

Like every other framework, when starting an application, a lot of [settings](./application/settings.md) can/need to be
passed to the main object and this can be very dauting and hugly to maintain and see.
passed to the main object and this can be very dauting and ugly to maintain and see.

Esmerald comes with the
[settings](./application/settings.md) in mind. A set of defaults that can be overridden by your very own settings
module but not limited to it as you can still use the classic approach of passing everything into a
module but not limited to it, as you can still use the classic approach of passing everything into a
Esmerald instance directly when instantiating.

**Example of classic approach**:
Expand Down Expand Up @@ -258,7 +258,7 @@ from esmerald import EsmeraldAPISettings
from esmerald.conf.enums import EnvironmentType

class Development(EsmeraldAPISettings):
app_name: bool = 'My app in dev'
app_name: str = 'My app in dev'
environment: str = EnvironmentType.DEVELOPMENT

```
Expand Down Expand Up @@ -308,7 +308,7 @@ Those are special objects that allow all the magic of Esmerald to happen.
msg = await socket.receive_json()
assert msg
assert socket
await socket.close(
await socket.close()


app = Esmerald(routes=[
Expand Down Expand Up @@ -404,7 +404,7 @@ of objects to be passed into one single object. This can be particulary useful t

## Run the application

As mentioned before, we recomment uvicorn for production but it is not mandatory.
As mentioned before, we recommend uvicorn for production but it is not mandatory.

**Using uvicorn**:

Expand Down
Loading

0 comments on commit 1d675d2

Please sign in to comment.