Skip to content

Commit

Permalink
0.3.6 (#1056)
Browse files Browse the repository at this point in the history
* docs: polish

* docs: remove EmailStr double

* test: fix python3.9 compatibility

* lint: fix mypy

* docs: revert API index page
  • Loading branch information
Lancetnik authored Dec 14, 2023
1 parent 6fb3c8b commit c4c35c0
Show file tree
Hide file tree
Showing 169 changed files with 1,726 additions and 737 deletions.
2 changes: 1 addition & 1 deletion docs/docs/en/api/faststream/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Here's the reference or code API, the classes, functions, parameters, attributes
all the FastAPI parts you can use in your applications.

If you want to **learn FastStream** you are much better off reading the
[FastStream Tutorial](../../../getting-started/index.md).
[FastStream Tutorial](../../../getting-started/index.md).
31 changes: 15 additions & 16 deletions docs/docs/en/faststream.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
hide:
- navigation
- footer
search:
exclude: true
---
Expand Down Expand Up @@ -98,7 +97,7 @@ That's **FastStream** in a nutshell—easy, efficient, and powerful. Whether you
**FastStream** works on **Linux**, **macOS**, **Windows** and most **Unix**-style operating systems.
You can install it with `pip` as usual:

{!> includes/index/1.md !}
{! includes/index/1.md !}

!!! tip ""
By default **FastStream** uses **PydanticV2** written in **Rust**, but you can downgrade it manually, if your platform has no **Rust** support - **FastStream** will work correctly with **PydanticV1** as well.
Expand All @@ -107,8 +106,8 @@ You can install it with `pip` as usual:

## Writing app code

**FastStream** brokers provide convenient function decorators `#!python @broker.subscriber`
and `#!python @broker.publisher` to allow you to delegate the actual process of:
**FastStream** brokers provide convenient function decorators `#!python @broker.subscriber(...)`
and `#!python @broker.publisher(...)` to allow you to delegate the actual process of:

- consuming and producing data to Event queues, and

Expand All @@ -121,12 +120,12 @@ JSON-encoded data into Python objects, making it easy to work with structured da

Here is an example Python app using **FastStream** that consumes data from an incoming data stream and outputs the data to another one:

{!> includes/index/2.md !}
{! includes/index/2.md !}

Also, **Pydantic**’s [`BaseModel`](https://docs.pydantic.dev/usage/models/){.external-link target="_blank"} class allows you
to define messages using a declarative syntax, making it easy to specify the fields and types of your messages.

{!> includes/index/3.md !}
{! includes/index/3.md !}

---

Expand All @@ -138,21 +137,21 @@ The Tester will redirect your `subscriber` and `publisher` decorated functions t

Using pytest, the test for our service would look like this:

{!> includes/index/4.md !}
{! includes/index/4.md !}

## Running the application

The application can be started using the built-in **FastStream** CLI command.

To run the service, use the **FastStream CLI** command and pass the module (in this case, the file where the app implementation is located) and the app symbol to the command.

``` shell
```shell
faststream run basic:app
```

After running the command, you should see the following output:

``` {.shell .no-copy}
```{.shell .no-copy}
INFO - FastStream app starting...
INFO - input_data | - `HandleMsg` waiting for messages
INFO - FastStream app started successfully! To exit press CTRL+C
Expand All @@ -161,13 +160,13 @@ INFO - FastStream app started successfully! To exit press CTRL+C

Also, **FastStream** provides you with a great hot reload feature to improve your Development Experience

``` shell
```shell
faststream run basic:app --reload
```

And multiprocessing horizontal scaling feature as well:

``` shell
```shell
faststream run basic:app --workers 3
```

Expand All @@ -189,8 +188,8 @@ The availability of such documentation significantly simplifies the integration

**FastStream** (thanks to [**FastDepends**](https://lancetnik.github.io/FastDepends/){.external-link target="_blank"}) has a dependency management system similar to `pytest fixtures` and `FastAPI Depends` at the same time. Function arguments declare which dependencies you want are needed, and a special decorator delivers them from the global Context object.

```python linenums="1" hl_lines="9-10"
{!> docs_src/index/dependencies.py [ln:1,6-14] !}
```python linenums="1" hl_lines="8-9"
{! docs_src/index/dependencies.py [ln:1,5-14] !}
```

---
Expand Down Expand Up @@ -228,16 +227,16 @@ As evident, **FastStream** is an incredibly user-friendly framework. However, we
Save application description inside `description.txt`:

```
{!> docs_src/index/app_description.txt !}
{! docs_src/index/app_description.txt !}
```

and run the following command to create a new **FastStream** project:

``` shell
```shell
faststream_gen -i description.txt
```

``` {.shell .no-copy}
```{.shell .no-copy}
✨ Generating a new FastStream application!
✔ Application description validated.
✔ FastStream app skeleton code generated. akes around 15 to 45 seconds)...
Expand Down
26 changes: 18 additions & 8 deletions docs/docs/en/getting-started/asyncapi/custom.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 10
---

# Customizing AsyncAPI Documentation for FastStream

In this guide, we will explore how to customize **AsyncAPI** documentation for your **FastStream** application. Whether you want to add custom app info, broker information, handlers, or fine-tune payload details, we'll walk you through each step.
Expand All @@ -9,7 +19,7 @@ Before we dive into customization, ensure you have a basic **FastStream** applic
Copy the following code in your basic.py file:

```python linenums="1"
{!> docs_src/getting_started/asyncapi/asyncapi_customization/basic.py !}
{! docs_src/getting_started/asyncapi/asyncapi_customization/basic.py !}
```

Now, when you run
Expand All @@ -31,8 +41,8 @@ Let's start by customizing the app information that appears in your **AsyncAPI**

Copy the following code in your basic.py file, we have highligted the additional info passed to **FastStream** app:

```python linenums="1" hl_lines="6-15"
{!> docs_src/getting_started/asyncapi/asyncapi_customization/custom_info.py !}
```python linenums="1" hl_lines="6-16"
{! docs_src/getting_started/asyncapi/asyncapi_customization/custom_info.py !}
```

Now, when you run
Expand All @@ -46,7 +56,7 @@ you should see the following in your general app documentation:
Now, your documentation reflects your application's identity and purpose.

!!! note
The ```description``` field in the above example supports ```Markdown``` text.
The `description` field in the above example supports `Markdown` text.

## Setup Custom Broker Information

Expand All @@ -61,7 +71,7 @@ The next step is to customize broker information. This helps users understand th
Copy the following code in your basic.py file, we have highligted the additional info passed to the **FastStream** app broker:

```python linenums="1" hl_lines="5-9"
{!> docs_src/getting_started/asyncapi/asyncapi_customization/custom_broker.py !}
{! docs_src/getting_started/asyncapi/asyncapi_customization/custom_broker.py !}
```

Now, when you run
Expand Down Expand Up @@ -89,12 +99,12 @@ Customizing handler information helps users comprehend the purpose and behavior
Copy the following code in your basic.py file, we have highligted the additional info passed to the **FastStream** app handlers:

```python linenums="1" hl_lines="17-25 27-31"
{!> docs_src/getting_started/asyncapi/asyncapi_customization/custom_handler.py !}
{! docs_src/getting_started/asyncapi/asyncapi_customization/custom_handler.py !}
```

Now, when you run
```shell
{!> docs_src/getting_started/asyncapi/serve.py [ln:17] !}
{! docs_src/getting_started/asyncapi/serve.py [ln:17] !}
```
you should see the descriptions in your handlers:

Expand All @@ -115,7 +125,7 @@ To describe your message payload effectively, you can use Pydantic models. Here'
Copy the following code in your basic.py file, we have highligted the creation of payload info and you can see it being passed to the return type and the `msg` argument type in the `on_input_data` function:

```python linenums="1" hl_lines="7-10 19"
{!> docs_src/getting_started/asyncapi/asyncapi_customization/payload_info.py !}
{! docs_src/getting_started/asyncapi/asyncapi_customization/payload_info.py !}
```

Now, when you run
Expand Down
24 changes: 17 additions & 7 deletions docs/docs/en/getting-started/asyncapi/export.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 10
---

# How to Generate and Serve AsyncAPI Documentation

In this guide, let's explore how to generate and serve [**AsyncAPI**](https://www.asyncapi.com/){.external-link target="_blank"} documentation for our FastStream application.
Expand All @@ -8,29 +18,29 @@ Here's an example Python application using **FastStream** that consumes data fro
topic, increments the value, and outputs the data to another topic.
Save it in a file called `basic.py`.

``` python
{!> docs_src/kafka/basic/basic.py!}
```python title="basic.py"
{! docs_src/kafka/basic/basic.py!}
```

## Generating the AsyncAPI Specification

Now that we have a FastStream application, we can proceed with generating the AsyncAPI specification using a CLI command.

``` shell
{!> docs_src/getting_started/asyncapi/serve.py[ln:9]!}
```shell
{! docs_src/getting_started/asyncapi/serve.py [ln:9] !}
```

The above command will generate the AsyncAPI specification and save it in a file called `asyncapi.json`.

If you prefer `yaml` instead of `json`, please run the following command to generate `asyncapi.yaml`.

``` shell
{!> docs_src/getting_started/asyncapi/serve.py[ln:13]!}
```shell
{! docs_src/getting_started/asyncapi/serve.py [ln:13] !}
```

!!! tip
To generate the documentation in yaml format, please install the necessary dependency to work with **YAML** file format at first.

``` shell
```shell
pip install PyYAML
```
24 changes: 17 additions & 7 deletions docs/docs/en/getting-started/asyncapi/hosting.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 10
---

# Serving the AsyncAPI Documentation

FastStream provides a command to serve the AsyncAPI documentation.

!!! note
This feature requires an Internet connection to obtain the **AsyncAPI HTML** via **CDN**.

``` shell
{!> docs_src/getting_started/asyncapi/serve.py[ln:17]!}
```shell
{! docs_src/getting_started/asyncapi/serve.py [ln:17] !}
```

In the above command, we are providing the path in the format of `python_module:FastStream`. Alternatively, you can also specify `asyncapi.json` or `asyncapi.yaml` to serve the AsyncAPI documentation.

=== "JSON"
``` shell
{!> docs_src/getting_started/asyncapi/serve.py[ln:21]!}
```shell
{!> docs_src/getting_started/asyncapi/serve.py [ln:21] !}
```

=== "YAML"
``` shell
{!> docs_src/getting_started/asyncapi/serve.py[ln:25]!}
```shell
{!> docs_src/getting_started/asyncapi/serve.py [ln:25] !}
```

After running the command, it should serve the AsyncAPI documentation on port **8000** and display the following logs in the terminal.

``` {.shell .no-copy}
```{.shell .no-copy}
INFO: Started server process [2364992]
INFO: Waiting for application startup.
INFO: Application startup complete.
Expand Down
10 changes: 10 additions & 0 deletions docs/docs/en/getting-started/cli/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 10
---

# CLI

**FastStream** has its own built-in **CLI** tool for your maximum comfort as a developer.
Expand Down
14 changes: 12 additions & 2 deletions docs/docs/en/getting-started/config/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 10
---

# Settings and Environment Variables

In many cases, your application may require external settings or configurations, such as a broker connection or database credentials.
Expand Down Expand Up @@ -47,7 +57,7 @@ It will also convert and validate the data, so when you use that `settings` obje
Now you can use the new `settings` object in your application:

```python linenums='1' hl_lines="3 9 14" title="serve.py"
{!> docs_src/getting_started/config/usage.py !}
{! docs_src/getting_started/config/usage.py !}
```

### Running the Application
Expand Down Expand Up @@ -91,7 +101,7 @@ QUEUE="test-queue"
Then update your `config.py` as follows:

```python linenums='1' hl_lines="1 11"
{!> docs_src/getting_started/config/settings_env.py !}
{! docs_src/getting_started/config/settings_env.py !}
```

This way, you can specify different `.env` files directly from your terminal, which can be extremely helpful for various testing and production scenarios.
Expand Down
18 changes: 14 additions & 4 deletions docs/docs/en/getting-started/context/custom.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 10
---

# Context Fields Declaration

You can also store your own objects in the `Context`.
Expand All @@ -6,11 +16,11 @@ You can also store your own objects in the `Context`.

To declare an application-level context field, you need to call the `context.set_global` method with with a key to indicate where the object will be placed in the context.

{!> includes/getting_started/context/custom_global.md !}
{! includes/getting_started/context/custom_global.md !}

Afterward, you can access your `secret` field in the usual way:

{!> includes/getting_started/context/custom_global_2.md !}
{! includes/getting_started/context/custom_global_2.md !}

In this case, the field becomes a global context field: it does not depend on the current message handler (unlike `message`)

Expand All @@ -24,8 +34,8 @@ context.reset_global("my_key")

To set a local context (available only within the message processing scope), use the context manager `scope`

{!> includes/getting_started/context/custom_local.md !}
{! includes/getting_started/context/custom_local.md !}

You can also set the context by yourself, and it will remain within the current call stack until you clear it.

{!> includes/getting_started/context/manual_local.md !}
{! includes/getting_started/context/manual_local.md !}
Loading

0 comments on commit c4c35c0

Please sign in to comment.