Skip to content
Merged
16 changes: 8 additions & 8 deletions docs/en/docs/advanced/nosql-databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You can adapt it to any other NoSQL database like:

For now, don't pay attention to the rest, only the imports:

```Python hl_lines="6 7 8"
```Python hl_lines="3 4 5"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```

Expand All @@ -29,7 +29,7 @@ We will use it later as a fixed field `type` in our documents.

This is not required by Couchbase, but is a good practice that will help you afterwards.

```Python hl_lines="10"
```Python hl_lines="9"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```

Expand All @@ -54,7 +54,7 @@ This utility function will:
* Set defaults for timeouts.
* Return it.

```Python hl_lines="13 14 15 16 17 18 19 20 21 22"
```Python hl_lines="12 13 14 15 16 17 18 19 20 21"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```

Expand All @@ -66,7 +66,7 @@ As **Couchbase** "documents" are actually just "JSON objects", we can model them

First, let's create a `User` model:

```Python hl_lines="25 26 27 28 29"
```Python hl_lines="24 25 26 27 28"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```

Expand All @@ -80,7 +80,7 @@ This will have the data that is actually stored in the database.

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="32 33 34"
```Python hl_lines="31 32 33"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```

Expand All @@ -100,7 +100,7 @@ Now create a function that will:

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="37 38 39 40 41 42 43"
```Python hl_lines="36 37 38 39 40 41 42"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```

Expand Down Expand Up @@ -135,7 +135,7 @@ UserInDB(username="johndoe", hashed_password="some_hash")

### Create the `FastAPI` app

```Python hl_lines="47"
```Python hl_lines="46"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```

Expand All @@ -145,7 +145,7 @@ As our code is calling Couchbase and we are not using the <a href="https://docs.

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="50 51 52 53 54"
```Python hl_lines="49 50 51 52 53"
{!../../../docs_src/nosql_databases/tutorial001.py!}
```

Expand Down
5 changes: 2 additions & 3 deletions docs_src/nosql_databases/tutorial001.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Optional

from fastapi import FastAPI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to use isort in this tutorial, because fastapi and pydantic are really third party imports here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed

from pydantic import BaseModel

from couchbase import LOCKMODE_WAIT
from couchbase.bucket import Bucket
from couchbase.cluster import Cluster, PasswordAuthenticator
from fastapi import FastAPI
from pydantic import BaseModel

USERPROFILE_DOC_TYPE = "userprofile"

Expand Down
2 changes: 1 addition & 1 deletion fastapi/dependencies/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
from pydantic.typing import ForwardRef, evaluate_forwardref
except ImportError: # pragma: nocover
# TODO: remove when removing support for Pydantic < 1.0.0
from pydantic import Schema as FieldInfo # type: ignore
from pydantic.fields import Field as ModelField # type: ignore
from pydantic.fields import Required, Shape # type: ignore
from pydantic import Schema as FieldInfo # type: ignore
from pydantic.schema import get_annotation_from_schema # type: ignore
from pydantic.utils import ForwardRef, evaluate_forwardref # type: ignore

Expand Down
6 changes: 2 additions & 4 deletions fastapi/security/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
from typing import Optional

from fastapi.exceptions import HTTPException
from fastapi.openapi.models import (
HTTPBase as HTTPBaseModel,
HTTPBearer as HTTPBearerModel,
)
from fastapi.openapi.models import HTTPBase as HTTPBaseModel
from fastapi.openapi.models import HTTPBearer as HTTPBearerModel
from fastapi.security.base import SecurityBase
from fastapi.security.utils import get_authorization_scheme_param
from pydantic import BaseModel
Expand Down
3 changes: 2 additions & 1 deletion fastapi/security/oauth2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import List, Optional

from fastapi.exceptions import HTTPException
from fastapi.openapi.models import OAuth2 as OAuth2Model, OAuthFlows as OAuthFlowsModel
from fastapi.openapi.models import OAuth2 as OAuth2Model
from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
from fastapi.param_functions import Form
from fastapi.security.base import SecurityBase
from fastapi.security.utils import get_authorization_scheme_param
Expand Down
2 changes: 1 addition & 1 deletion fastapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
PYDANTIC_1 = True
except ImportError: # pragma: nocover
# TODO: remove when removing support for Pydantic < 1.0.0
from pydantic.fields import Field as ModelField # type: ignore
from pydantic import Schema as FieldInfo # type: ignore
from pydantic.fields import Field as ModelField # type: ignore

class UndefinedType: # type: ignore
def __repr__(self) -> str:
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ all = [
"async_exit_stack",
"async_generator"
]

[tool.isort]
profile = "black"
known_third_party = ["fastapi", "pydantic", "starlette"]
2 changes: 1 addition & 1 deletion scripts/format-imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
set -x

# Sort imports one per line, so autoflake can remove unused imports
isort --recursive --force-single-line-imports --thirdparty fastapi --apply fastapi tests docs_src scripts
isort fastapi tests docs_src scripts --force-single-line-imports
sh ./scripts/format.sh
2 changes: 1 addition & 1 deletion scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -x

autoflake --remove-all-unused-imports --recursive --remove-unused-variables --in-place docs_src fastapi tests scripts --exclude=__init__.py
black fastapi tests docs_src scripts
isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --thirdparty fastapi --thirdparty pydantic --thirdparty starlette --apply fastapi tests docs_src scripts
isort fastapi tests docs_src scripts
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -x

mypy fastapi
black fastapi tests --check
isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --combine-as --line-width 88 --recursive --check-only --thirdparty fastapi --thirdparty fastapi --thirdparty pydantic --thirdparty starlette fastapi tests
isort fastapi tests docs_src scripts --check-only
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to use isort in this tutorial, because fastapi are really third party here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be in all the tutorials? If so, I can tell isort to ignore the files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of them use fastapi as third party... If that's true, yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. I've made adjustment in the new isort configuration file. This should be flexible.


from additional_responses.tutorial001 import app
from docs_src.additional_responses.tutorial001 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from fastapi.testclient import TestClient

from additional_responses.tutorial002 import app
from docs_src.additional_responses.tutorial002 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from additional_responses.tutorial003 import app
from docs_src.additional_responses.tutorial003 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from fastapi.testclient import TestClient

from additional_responses.tutorial004 import app
from docs_src.additional_responses.tutorial004 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from additional_status_codes.tutorial001 import app
from docs_src.additional_status_codes.tutorial001 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from advanced_middleware.tutorial001 import app
from docs_src.advanced_middleware.tutorial001 import app


def test_middleware():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from advanced_middleware.tutorial002 import app
from docs_src.advanced_middleware.tutorial002 import app


def test_middleware():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi.responses import PlainTextResponse
from fastapi.testclient import TestClient

from advanced_middleware.tutorial003 import app
from docs_src.advanced_middleware.tutorial003 import app


@app.get("/large")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from async_sql_databases.tutorial001 import app
from docs_src.async_sql_databases.tutorial001 import app

openapi_schema = {
"openapi": "3.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from fastapi.testclient import TestClient

from background_tasks.tutorial001 import app
from docs_src.background_tasks.tutorial001 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from fastapi.testclient import TestClient

from background_tasks.tutorial002 import app
from docs_src.background_tasks.tutorial002 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from behind_a_proxy.tutorial001 import app
from docs_src.behind_a_proxy.tutorial001 import app

client = TestClient(app, root_path="/api/v1")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from behind_a_proxy.tutorial002 import app
from docs_src.behind_a_proxy.tutorial002 import app

client = TestClient(app)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_bigger_applications/test_main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from fastapi.testclient import TestClient

from bigger_applications.app.main import app
from docs_src.bigger_applications.app.main import app

client = TestClient(app)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_body/test_tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from fastapi.testclient import TestClient

from body.tutorial001 import app
from docs_src.body.tutorial001 import app

client = TestClient(app)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_body_fields/test_tutorial001.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from fastapi.testclient import TestClient

from body_fields.tutorial001 import app
from docs_src.body_fields.tutorial001 import app

# TODO: remove when removing support for Pydantic < 1.0.0
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from fastapi.testclient import TestClient

from body_multiple_params.tutorial001 import app
from docs_src.body_multiple_params.tutorial001 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from fastapi.testclient import TestClient

from body_multiple_params.tutorial003 import app
from docs_src.body_multiple_params.tutorial003 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from body_nested_models.tutorial009 import app
from docs_src.body_nested_models.tutorial009 import app

client = TestClient(app)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_body_updates/test_tutorial001.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from body_updates.tutorial001 import app
from docs_src.body_updates.tutorial001 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from fastapi.testclient import TestClient

from conditional_openapi import tutorial001
from docs_src.conditional_openapi import tutorial001

openapi_schema = {
"openapi": "3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_cookie_params/test_tutorial001.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from fastapi.testclient import TestClient

from cookie_params.tutorial001 import app
from docs_src.cookie_params.tutorial001 import app

client = TestClient(app)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tutorial/test_cors/test_tutorial001.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from cors.tutorial001 import app
from docs_src.cors.tutorial001 import app


def test_cors():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi import Request
from fastapi.testclient import TestClient

from custom_request_and_route.tutorial001 import app
from docs_src.custom_request_and_route.tutorial001 import app


@app.get("/check-class")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from custom_request_and_route.tutorial002 import app
from docs_src.custom_request_and_route.tutorial002 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from custom_request_and_route.tutorial003 import app
from docs_src.custom_request_and_route.tutorial003 import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from custom_response.tutorial001b import app
from docs_src.custom_response.tutorial001b import app

client = TestClient(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from custom_response.tutorial004 import app
from docs_src.custom_response.tutorial004 import app

client = TestClient(app)

Expand Down
Loading