Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modern Python through FastAPI and friends - PyCon Indonesia

Modern Python through FastAPI and friends - PyCon Indonesia

Explore some of the great features from modern Python and how to use them with FastAPI and friends.

We will see how to make code that is less error-prone, simpler, more efficient, and have a great developer experience, all at the same time.

And all this while including best practices by default.

We will see a bit about type annotations (type hints), async/await, and an overview of FastAPI, Typer, and others.

This talk doesn't expect any technical background, just some basic knowledge of Python.

02c817926d446faab88b0202be4391eb?s=128

Sebastián Ramírez

November 29, 2021
Tweet

Transcript

  1. Modern Python through and friends

  2. Who am I? Sebastián Ramírez github.com/tiangolo linkedin.com/in/tiangolo twitter.com/tiangolo tiangolo.com Berlin,

    Germany Staff Software Engineer at I created: ➕ External Consultant for other teams
  3. Modern Python Currently supported versions (3.6+) 📝 f-strings 🧙 Type

    annotations ⏱ async / await ⚡ Performance 👥 Community • Pydantic • HTTPX • Starlette • Uvicorn • Uvloop • Rich • Click @tiangolo • Pydantic • SQLAlchemy
  4. • Web API framework • 38K GitHub stars (about 1K+

    per month) • Used by Microsoft, Uber, Netflix, etc. • Performance in the top rank for Python High performance, easy to learn, fast to code, ready for production @tiangolo
  5. Modern Python 📝 f-strings (formatted strings) @tiangolo

  6. 📝 f-strings (formatted strings) @tiangolo

  7. 📝 f-strings (formatted strings) @tiangolo

  8. 📝 f-strings (formatted strings) @tiangolo

  9. 📝 f-strings (formatted strings) @tiangolo

  10. 📝 f-strings (formatted strings) @tiangolo

  11. Modern Python 🧙 Type annotations (type hints) @tiangolo

  12. 🧙 Type annotations (type hints) @tiangolo

  13. 🧙 Type annotations (type hints) @tiangolo

  14. 🧙 Type annotations (type hints) @tiangolo

  15. 🧙 Type annotations (type hints) - autocompletion @tiangolo

  16. 🧙 Type annotations (type hints) - autocompletion @tiangolo

  17. 🧙 Type annotations (type hints) - autocompletion @tiangolo

  18. 🧙 Type annotations (type hints) @tiangolo

  19. 🧙 Type annotations (type hints) @tiangolo

  20. 🧙 Type annotations (type hints) @tiangolo

  21. 🧙 Type annotations (type hints) @tiangolo

  22. 🧙 Type annotations (type hints) - error detection @tiangolo

  23. 🧙 Type annotations (type hints) - error detection @tiangolo

  24. 🧙 Type annotations (type hints) @tiangolo

  25. 🧙 Type annotations (type hints) - error detection @tiangolo

  26. 🧙 Type annotations (type hints) - error detection @tiangolo

  27. 🧙 Type annotations (type hints) - error detection @tiangolo

  28. 🧙 Type annotations (type hints) - error detection @tiangolo

  29. 🧙 Type annotations (type hints) @tiangolo

  30. 🧙 Type annotations (type hints) @tiangolo

  31. 🧙 Type annotations (type hints) @tiangolo

  32. 🧙 Type annotations (type hints) @tiangolo

  33. Some of the people behind: Jukka Lehtosalo Ivan Levkivskyi Michael

    J. Sullivan @JukkaLeh @JukkaL @ILevkivskyi @ilevkivskyi @msully4321 @msullivan 🧙 Type annotations (type hints) @tiangolo
  34. Modern Python 🧙 Type annotations with @tiangolo

  35. 🧙 Type annotations with FastAPI @tiangolo

  36. 🧙 Type annotations with FastAPI @tiangolo

  37. 🧙 Type annotations with FastAPI - autocompletion @tiangolo

  38. 🧙 Type annotations with FastAPI - autocompletion @tiangolo

  39. 🧙 Type annotations with FastAPI - error detection @tiangolo

  40. http://127.0.0.1:8000/docs FastAPI - API documentation @tiangolo

  41. FastAPI - API documentation @tiangolo

  42. FastAPI - API documentation @tiangolo

  43. FastAPI - data validation @tiangolo

  44. FastAPI - data validation @tiangolo

  45. FastAPI - data validation @tiangolo

  46. FastAPI - data conversion http://127.0.0.1:8000/recipes/crunchy-frog?quantity=2 @tiangolo

  47. FastAPI - data conversion @tiangolo

  48. FastAPI - Type hints @tiangolo

  49. • OpenAPI • JSON Schema • OAuth2 🔄 Automatic data

    conversion ✨ ✅ Automatic data validation ✨ FastAPI is based on standards 📝 Automatic API docs ✨ • Standard type annotations @tiangolo
  50. Modern Python 🧙 Type annotations with @tiangolo

  51. Type annotations with Typer @tiangolo

  52. Type annotations with Typer @tiangolo

  53. Typer - automatic help @tiangolo

  54. Typer - CLI Arguments @tiangolo

  55. Typer - CLI Options @tiangolo

  56. Typer - validation @tiangolo

  57. <TAB> Typer - shell (TAB) completion @tiangolo

  58. Typer @tiangolo

  59. Modern Python 🧙 Type annotations with and Rich @tiangolo

  60. Typer with Rich @tiangolo

  61. Typer with Rich @tiangolo

  62. Typer with Rich @tiangolo

  63. David Lord Click maintainer Will McGugan Rich creator @davidism @davidism

    @willmcgugan @willmcgugan Typer and friends - the people behind @tiangolo
  64. Modern Python 🧙 Type annotations with and Pydantic @tiangolo

  65. FastAPI with Pydantic @tiangolo

  66. FastAPI with Pydantic @tiangolo

  67. FastAPI with Pydantic - API documentation @tiangolo

  68. FastAPI with Pydantic - interactive API docs @tiangolo

  69. FastAPI with Pydantic - interactive API docs @tiangolo

  70. FastAPI with Pydantic - data validation @tiangolo

  71. FastAPI with Pydantic - data validation @tiangolo

  72. FastAPI with Pydantic - nested data @tiangolo

  73. FastAPI with Pydantic - nested data @tiangolo

  74. FastAPI with Pydantic - autocompletion @tiangolo

  75. FastAPI with Pydantic - autocompletion @tiangolo

  76. FastAPI with Pydantic - error detection @tiangolo

  77. Samuel Colvin Pydantic creator David Montague Pydantic and FastAPI notorious

    contributor @samuel_colvin @samuelcolvin @dmontagu FastAPI - the people behind Tom Christie Creator of Starlette (and more) @_tomchristie @tomchristie @tiangolo
  78. Modern Python 🧙 Type annotations with and @tiangolo

  79. FastAPI with SQLModel @tiangolo

  80. FastAPI with SQLModel @tiangolo

  81. FastAPI with SQLModel @tiangolo

  82. FastAPI with SQLModel @tiangolo

  83. FastAPI with SQLModel @tiangolo

  84. Samuel Colvin Pydantic creator @samuel_colvin @samuelcolvin SQLModel - the people

    behind Mike Bayer SQLAlchemy creator @zzzeek @zzzeek @tiangolo
  85. Modern Python ⏱ async / await @tiangolo

  86. ⏱ async / await - concurrency @tiangolo

  87. ⏱ async / await - concurrency @tiangolo

  88. ⏱ async / await - concurrency Photo by John Cameron:

    https://unsplash.com/@john_cameron @tiangolo
  89. ⏱ async / await - concurrency @tiangolo

  90. ⏱ async / await - concurrency @tiangolo

  91. ⏱ async / await - concurrency Photo by Kate Townsend:

    https://unsplash.com/@k8townsend @tiangolo
  92. ⏱ async / await - concurrency @tiangolo

  93. ⏱ async / await - FastAPI and HTTPX @tiangolo

  94. ⏱ async / await - FastAPI and HTTPX @tiangolo

  95. ⏱ async / await - FastAPI and HTTPX @tiangolo

  96. ⏱ async / await - optional with FastAPI and HTTPX

    @tiangolo
  97. ⏱ async / await - optional with FastAPI and HTTPX

    @tiangolo
  98. FastAPI async / await - the people behind Tom Christie

    Creator of Starlette, HTTPX, and more @_tomchristie @tomchristie Florimond Manca Co-maintainer of HTTPX, and others @florimondmanca @florimondmanca Andrew Godwin Author of the ASGI specification @andrewgodwin @andrewgodwin @tiangolo
  99. ⚡ Performance with FastAPI @tiangolo

  100. ⚡ Performance with FastAPI @tiangolo

  101. ⚡ Performance with FastAPI @tiangolo

  102. ⚡ Performance with FastAPI @tiangolo

  103. ⚡ Performance - the people behind Tom Christie Creator of

    Starlette, Uvicorn, and more @_tomchristie @tomchristie Yury Selivanov Creator of Uvloop @1st1 @1st1 Stefan Behnel Maintainer of Cython @scoder @tiangolo
  104. 👥 Community • All by normal people 👥 • Mostly

    during free time ⏰ • Trying to help others ✨ @tiangolo
  105. 👥 Community @tiangolo

  106. 👥 Community - FastAPI You can help too! 🚀 •

    Translate a page 👥 • Review translations from others 🔍 • Answer questions from others 🗣 • Help with bugs and features 🤓 • Help with other projects 󰠁󰞵 https://fastapi.tiangolo.com/help-fastapi/ https://fastapi.tiangolo.com/contributing/#translations @tiangolo
  107. None
  108. Thank you! Sebastián Ramírez tiangolo.com fastapi.tiangolo.com github.com/tiangolo linkedin.com/in/tiangolo twitter.com/tiangolo