Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ The key features are:

---

## **Typer**, the FastAPI of CLIs

<a href="https://typer.tiangolo.com" target="_blank"><img src="https://typer.tiangolo.com/img/logo-margin/logo-margin-vector.svg" style="width: 20%;"></a>

If you are building a <abbr title="Command Line Interface">CLI</abbr> app to be used in the terminal instead of a web API, check out <a href="https://typer.tiangolo.com/" class="external-link" target="_blank">**Typer**</a>.

**Typer** is FastAPI's little sibling. And it's intended to be the **FastAPI of CLIs**. ⌨️ 🚀

## Requirements

Python 3.6+
Expand All @@ -88,16 +96,28 @@ FastAPI stands on the shoulders of giants:

## Installation

```bash
pip install fastapi
<div class="termy">

```console
$ pip install fastapi

---> 100%
```

</div>

You will also need an ASGI server, for production such as <a href="http://www.uvicorn.org" class="external-link" target="_blank">Uvicorn</a> or <a href="https://gitlab.com/pgjones/hypercorn" class="external-link" target="_blank">Hypercorn</a>.

```bash
pip install uvicorn
<div class="termy">

```console
$ pip install uvicorn

---> 100%
```

</div>

## Example

### Create it
Expand Down Expand Up @@ -151,10 +171,20 @@ If you don't know, check the _"In a hurry?"_ section about <a href="https://fast

Run the server with:

```bash
uvicorn main:app --reload
<div class="termy">

```console
$ uvicorn main:app --reload

<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
<span style="color: green;">INFO</span>: Started reloader process [28720]
<span style="color: green;">INFO</span>: Started server process [28722]
<span style="color: green;">INFO</span>: Waiting for application startup.
<span style="color: green;">INFO</span>: Application startup complete.
```

</div>

<details markdown="1">
<summary>About the command <code>uvicorn main:app --reload</code>...</summary>

Expand Down
11 changes: 9 additions & 2 deletions docs/advanced/extending-openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,17 @@ After that, your file structure could look like:

Now you need to install `aiofiles`:

```bash
pip install aiofiles

<div class="termy">

```console
$ pip install aiofiles

---> 100%
```

</div>

### Serve the static files

* Import `StaticFiles`.
Expand Down
10 changes: 8 additions & 2 deletions docs/advanced/sql-databases-peewee.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,16 @@ async def reset_db_state():

Then run your app with Uvicorn:

```bash
uvicorn sql_app.main:app --reload
<div class="termy">

```console
$ uvicorn sql_app.main:app --reload

<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```

</div>

Open your browser at <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a> and create a couple of users.

Then open 10 tabs at <a href="http://127.0.0.1:8000/docs#/default/read_slow_users_slowusers__get" class="external-link" target="_blank">http://127.0.0.1:8000/docs#/default/read_slow_users_slowusers__get</a> at the same time.
Expand Down
10 changes: 8 additions & 2 deletions docs/advanced/sub-applications-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ Here you need to make sure you use the same path that you used for the `openapi_

Now, run `uvicorn`, if your file is at `main.py`, it would be:

```bash
uvicorn main:app --reload
<div class="termy">

```console
$ uvicorn main:app --reload

<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```

</div>

And open the docs at <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.

You will see the automatic API docs for the main app, including only its own paths:
Expand Down
20 changes: 16 additions & 4 deletions docs/advanced/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@ There are utilities to configure it easily that you can use directly in your **F

Install `jinja2`:

```bash
pip install jinja2
<div class="termy">

```console
$ pip install jinja2

---> 100%
```

</div>

If you need to also serve static files (as in this example), install `aiofiles`:

```bash
pip install aiofiles
<div class="termy">

```console
$ pip install aiofiles

---> 100%
```

</div>

## Using `Jinja2Templates`

* Import `Jinja2Templates`.
Expand Down
10 changes: 8 additions & 2 deletions docs/advanced/websockets.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ To learn more about the options, check Starlette's documentation for:

If your file is named `main.py`, run your application with:

```bash
uvicorn main:app --reload
<div class="termy">

```console
$ uvicorn main:app --reload

<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```

</div>

Open your browser at <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000</a>.

You will see a simple page like:
Expand Down
3 changes: 2 additions & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ $ Get-Command pip

some/directory/fastapi/env/bin/pip
```

!!! tip
Every time you install a new package with `pip` under that environment, activate the environment again.

Expand All @@ -60,7 +61,7 @@ some/directory/fastapi/env/bin/pip

**FastAPI** uses <a href="https://flit.readthedocs.io/en/latest/index.html" class="external-link" target="_blank">Flit</a> to build, package and publish the project.

After activating the environment as described above, install `flit`:
After activating the environment as described above, install `flit`:

```console
$ pip install flit
Expand Down
108 changes: 108 additions & 0 deletions docs/css/termynal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* termynal.js
*
* @author Ines Montani <[email protected]>
* @version 0.0.1
* @license MIT
*/

:root {
--color-bg: #252a33;
--color-text: #eee;
--color-text-subtle: #a2a2a2;
}

[data-termynal] {
width: 750px;
max-width: 100%;
background: var(--color-bg);
color: var(--color-text);
font-size: 18px;
/* font-family: 'Fira Mono', Consolas, Menlo, Monaco, 'Courier New', Courier, monospace; */
font-family: 'Roboto Mono', 'Fira Mono', Consolas, Menlo, Monaco, 'Courier New', Courier, monospace;
border-radius: 4px;
padding: 75px 45px 35px;
position: relative;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}

[data-termynal]:before {
content: '';
position: absolute;
top: 15px;
left: 15px;
display: inline-block;
width: 15px;
height: 15px;
border-radius: 50%;
/* A little hack to display the window buttons in one pseudo element. */
background: #d9515d;
-webkit-box-shadow: 25px 0 0 #f4c025, 50px 0 0 #3ec930;
box-shadow: 25px 0 0 #f4c025, 50px 0 0 #3ec930;
}

[data-termynal]:after {
content: 'bash';
position: absolute;
color: var(--color-text-subtle);
top: 5px;
left: 0;
width: 100%;
text-align: center;
}

a[data-terminal-control] {
text-align: right;
display: block;
color: #aebbff;
}

[data-ty] {
display: block;
line-height: 2;
}

[data-ty]:before {
/* Set up defaults and ensure empty lines are displayed. */
content: '';
display: inline-block;
vertical-align: middle;
}

[data-ty="input"]:before,
[data-ty-prompt]:before {
margin-right: 0.75em;
color: var(--color-text-subtle);
}

[data-ty="input"]:before {
content: '$';
}

[data-ty][data-ty-prompt]:before {
content: attr(data-ty-prompt);
}

[data-ty-cursor]:after {
content: attr(data-ty-cursor);
font-family: monospace;
margin-left: 0.5em;
-webkit-animation: blink 1s infinite;
animation: blink 1s infinite;
}


/* Cursor animation */

@-webkit-keyframes blink {
50% {
opacity: 0;
}
}

@keyframes blink {
50% {
opacity: 0;
}
}
Loading