--- /dev/null
+There is a project generator that you can use to get started, with a lot of the initial set up, security, database and first API endpoints already done for you.
+
+## Full-Stack-FastAPI-Couchbase
+
+GitHub: <a href="https://github.com/tiangolo/full-stack-fastapi-couchbase" target="_blank">https://github.com/tiangolo/full-stack-fastapi-couchbase</a>
+
+### Features
+
+* Full **Docker** integration (Docker based).
+* Docker Swarm Mode deployment.
+* **Docker Compose** integration and optimization for local development.
+* **Production ready** Python web server using Uvicorn and Gunicorn.
+* Python **FastAPI** backend with all its features.
+* **Celery** worker that can import and use code from the rest of the backend selectively (you don't have to install the complete app in each worker).
+* **NoSQL Couchbase** database that supports direct synchronization via Couchbase Sync Gateway for offline-first applications.
+* **Full Text Search** integrated, using Couchbase.
+* REST backend tests based on Pytest, integrated with Docker, so you can test the full API interaction, independent on the database. As it runs in Docker, it can build a new data store from scratch each time (so you can use ElasticSearch, MongoDB, or whatever you want, and just test that the API works).
+* Easy Python integration with **Jupyter** Kernels for remote or in-Docker development with extensions like Atom Hydrogen or Visual Studio Code Jupyter.
+* **Email notifications** for account creation and password recovery, compatible with:
+ * Mailgun
+ * SparkPost
+ * SendGrid
+ * ...any other provider that can generate standard SMTP credentials.
+* **Vue** frontend:
+ * Generated with Vue CLI.
+ * **JWT Authentication** handling.
+ * Login view.
+ * After login, main dashboard view.
+ * Main dashboard with user creation and edition.
+ * Self user edition.
+ * **Vuex**.
+ * **Vue-router**.
+ * **Vuetify** for beautiful material design components.
+ * **TypeScript**.
+ * Docker server based on **Nginx** (configured to play nicely with Vue-router).
+ * Docker multi-stage building, so you don't need to save or commit compiled code.
+ * Frontend tests ran at build time (can be disabled too).
+ * Made as modular as possible, so it works out of the box, but you can re-generate with Vue CLI or create it as you need, and re-use what you want.
+* Flower for Celery jobs monitoring.
+* Load balancing between frontend and backend with **Traefik**, so you can have both under the same domain, separated by path, but served by different containers.
+* Traefik integration, including Let's Encrypt **HTTPS** certificates automatic generation.
+* GitLab **CI** (continuous integration), including frontend and backend testing.
Now we can return a Pydantic model from the dependency ("dependable") with the same data as the dict before:
-```Python hl_lines="18"
+```Python hl_lines="17"
{!./src/dependencies/tutorial002.py!}
```
It won't be interpreted as a JSON request `Body` because we are using `Depends`:
-```Python hl_lines="22"
+```Python hl_lines="21"
{!./src/dependencies/tutorial002.py!}
```
And now we can use that model in our code, with all the lovable editor support:
-```Python hl_lines="24 25 26"
+```Python hl_lines="23 24 25"
{!./src/dependencies/tutorial002.py!}
```
* **ArangoDB**
* **ElasticSearch**, etc.
+!!! tip
+ There is an official project generator with **FastAPI** and **Couchbase**, all based on **Docker**, including a frontend and more tools: <a href="https://github.com/tiangolo/full-stack-fastapi-couchbase" target="_blank">https://github.com/tiangolo/full-stack-fastapi-couchbase</a>
+
## Import Couchbase components
For now, don't pay attention to the rest, only the imports:
* Set defaults for timeouts.
* Return it.
-```Python hl_lines="13 14 15 16 17 18 19 20"
+```Python hl_lines="13 14 15 16 17 18 19 20 21 22"
{!./src/nosql_databases/tutorial001.py!}
```
First, let's create a `User` model:
-```Python hl_lines="23 24 25 26 27"
+```Python hl_lines="25 26 27 28 29"
{!./src/nosql_databases/tutorial001.py!}
```
We don't create it as a subclass of Pydantic's `BaseModel` but as a subclass of our own `User`, because it will have all the attributes in `User` plus a couple more:
-```Python hl_lines="30 31 32"
+```Python hl_lines="32 33 34"
{!./src/nosql_databases/tutorial001.py!}
```
By creating a function that is only dedicated to getting your user from a `username` (or any other parameter) independent of your path operation function, you can more easily re-use it in multiple parts and also add <abbr title="Automated test, written in code, that checks if another piece of code is working correctly.">unit tests</abbr> for it:
-```Python hl_lines="35 36 37 38 39 40 41"
+```Python hl_lines="37 38 39 40 41 42 43"
{!./src/nosql_databases/tutorial001.py!}
```
### Create the `FastAPI` app
-```Python hl_lines="45"
+```Python hl_lines="47"
{!./src/nosql_databases/tutorial001.py!}
```
Also, Couchbase recommends not using a single `Bucket` object in multiple "<abbr title="A sequence of code being executed by the program, while at the same time, or at intervals, there can be others being executed too.">thread</abbr>s", so, we can get just get the bucket directly and pass it to our utility functions:
-```Python hl_lines="48 49 50 51 52"
+```Python hl_lines="50 51 52 53 54"
{!./src/nosql_databases/tutorial001.py!}
```
**FastAPI** doesn't require you to use a SQL (relational) database.
-But you can use relational database that you want.
+But you can use any relational database that you want.
Here we'll see an example using <a href="https://www.sqlalchemy.org/" target="_blank">SQLAlchemy</a>.
So, your models will behave very similarly to, for example, Flask-SQLAlchemy.
-```Python hl_lines="15 16 17 18 19"
+```Python hl_lines="16 17 18 19 20"
{!./src/sql_databases/tutorial001.py!}
```
## Create the SQLAlchemy `Base` model
-```Python hl_lines="22"
+```Python hl_lines="23"
{!./src/sql_databases/tutorial001.py!}
```
Here's a user model that will be a table in the database:
-```Python hl_lines="25 26 27 28 29"
+```Python hl_lines="26 27 28 29 30"
{!./src/sql_databases/tutorial001.py!}
```
By creating a function that is only dedicated to getting your user from a `username` (or any other parameter) independent of your path operation function, you can more easily re-use it in multiple parts and also add <abbr title="Automated test, written in code, that checks if another piece of code is working correctly.">unit tests</abbr> for it:
-```Python hl_lines="32 33"
+```Python hl_lines="33 34"
{!./src/sql_databases/tutorial001.py!}
```
Create your app and path operation function:
-```Python hl_lines="37 40 41 42 43"
+```Python hl_lines="38 41 42 43 44"
{!./src/sql_databases/tutorial001.py!}
```
Then we should declare the path operation without `async def`, just with a normal `def`:
-```Python hl_lines="41"
+```Python hl_lines="42"
{!./src/sql_databases/tutorial001.py!}
```
- Extra Starlette options: 'tutorial/extra-starlette.md'
- Concurrency and async / await: 'async.md'
- Deployment: 'deployment.md'
+ - Project Generation - Template: 'project-generation.md'
markdown_extensions:
- markdown.extensions.codehilite: