Open2

FastAPI のメモ

kiaikiai

FastAPI + Django をやる準備

せっかくなので Poetry を使う.

poetry のインストール(省略)

  1. poetry new fastapi (※これはプロジェクト名を指定しているだけ,fastapi は後でインストールする)
  2. cd fastapi && mv fastapi/ src/ && mv README.rst README.md
  3. poetry add django
  4. poetry run django-admin startproject config . (※最後のドットを追加して,カレントディレクトリにプロジェクトを作成する)
  5. sed -i "s/name = \"fastapi\"/name = \"YOUR_PROJECT\"/" pyproject.toml
  6. ここまで来て初めて poetry add fastapi uvicorn[standard]が実行できる.
.
├── README.md
├── config
│   ├── __init__.py
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── poetry.lock
├── pyproject.toml
├── src
│   └── __init__.py
└── tests
    ├── __init__.py
    └── test_fastapi.py
(参考)インストールされたもの(2021/02/26)

$ poetry show で確認できる

asgiref        3.3.1  ASGI specs, helper code, and adapters
attrs          20.3.0 Classes Without Boilerplate
click          7.1.2  Composable command line interface toolkit
django         3.1.7  A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
fastapi        0.63.0 FastAPI framework, high performance, easy to learn, fast to code, ready for production
h11            0.12.0 A pure-Python, bring-your-own-I/O implementation of HTTP/1.1
httptools      0.1.1  A collection of framework independent HTTP protocol utils.
more-itertools 8.7.0  More routines for operating on iterables, beyond itertools
packaging      20.9   Core utilities for Python packages
pluggy         0.13.1 plugin and hook calling mechanisms for python
py             1.10.0 library with cross-python path, ini-parsing, io, code, log facilities
pydantic       1.7.3  Data validation and settings management using python 3.6 type hinting
pyparsing      2.4.7  Python parsing module
pytest         5.4.3  pytest: simple powerful testing with Python
python-dotenv  0.15.0 Add .env support to your django/flask apps in development and deployments
pytz           2021.1 World timezone definitions, modern and historical
pyyaml         5.4.1  YAML parser and emitter for Python
sqlparse       0.4.1  A non-validating SQL parser.
starlette      0.13.6 The little ASGI library that shines.
uvicorn        0.13.4 The lightning-fast ASGI server.
uvloop         0.15.2 Fast implementation of asyncio event loop on top of libuv
watchgod       0.7    Simple, modern file watching and code reload in python.
wcwidth        0.2.5  Measures the displayed width of unicode strings in a terminal
websockets     8.1    An implementation of the WebSocket Protocol (RFC 6455 & 7692)