Loading...
2022. 2. 25. 15:43

[Python] Python Database API - Python์—์„œ๋Š” ์–ด๋–ป๊ฒŒ DB์™€ ์—ฐ๊ฒฐํ• ๊นŒ?

์˜ค๋Š˜์€ ๊ธฐ์ดˆ์ ์ธ ์ง€์‹์„ ๋Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.โ€‹ ์šฐ๋ฆฌ๊ฐ€ ์„œ๋ฒ„๋ฅผ ๊ฐœ๋ฐœํ•˜๋‹ค ๋ณด๋ฉด ์ž์—ฐ์Šค๋ ˆ ๋“ฑ์žฅํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋กœ Database์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ์š”์ฒญํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐ๋„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ์•ก์„ธ์Šคํ•˜๋Š” ๋ฐ๋„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋Š” ๋„๋Œ€์ฒด ๋ฌด์—‡์ผ๊นŒ์š”? What is Database ? ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค, ํ˜„๋Œ€ ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ(?)์„ ๊ณต๋ถ€ํ•˜๋‹ค๋ณด๋ฉด ์ž์—ฐ์Šค๋ ˆ ๋“ฑ์žฅํ•˜๋Š” ๋‹จ์–ด์ž…๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ž€, ์ปดํ“จํ„ฐ ์‹œ์Šคํ…œ์—์„œ ์ „์ž์ ์œผ๋กœ ์ €์žฅ๋˜๊ณ  ์•ก์„ธ์Šค๋˜๋Š” ์กฐ์งํ™” ๋œ ๋ฐ์ดํ„ฐ ๋ชจ์Œ์„ ์ด์•ผ๊ธฐํ•ฉ๋‹ˆ๋‹ค. ํ•œ๋งˆ๋””๋กœ ํ˜„์‹ค ์„ธ๊ณ„์— ์กด์žฌํ•˜๋Š” ์ˆซ์ž, ๋ฌธ์ž ๋“ฑ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์ž์ ์œผ๋กœ(๋ฉ”๋ชจ๋ฆฌ, ๋””์Šคํฌ) ์ €์žฅํ•˜๊ณ , ์ด๋ฅผ ์กฐ์งํ™”ํ•˜์—ฌ ์•ก์„ธ์Šค ํ•˜๋Š” ๊ฒƒ์ด์ฃ . ๊ทธ๋Ÿผ DBMS๋Š” ๋ฌด์—‡์ผ๊นŒ์š”? DBMS๋Š” Database Management..

2022. 1. 9. 14:18

[Python] anyio - ํ•œ ์ธต ๋” ๊ฐ•ํ™”๋œ ๋น„๋™๊ธฐ ํŒจ๋Ÿฌ๋‹ค์ž„

์–ด๋Š๋ง ์‹ค๋ฌด์—์„œ Python ๋ฐฑ์—”๋“œ ์—”์ง€๋‹ˆ์–ด๋กœ ๋ณด๋‚ธ์ง€ 1๋…„์ด ์กฐ๊ธˆ ๋„˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋งŽ์€ ๊ณ ๋ฏผ๊ณผ ๊ณ ๋‚œ, ๊ทธ๋ฆฌ๊ณ  ์ด ์ž๋ฆฌ์— ์˜ค๊ธฐ๊นŒ์ง€ ์ˆ˜๋งŽ์€ ๋ฐ˜์„ฑ๊ณผ ๋…ธ๋ ฅ์œผ๋กœ ํŒŒ์ด์ฌ ๋ฐฑ์—”๋“œ ์—”์ง€๋‹ˆ์–ด๋กœ์จ์˜ ์ž๋ฆฌ๋ฅผ ์žก์•˜๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์˜ค๋Š˜ ์ด์•ผ๊ธฐ๋ฅผ ์œ„ํ•ด ๋‹จ๋„์ง์ž…์ ์œผ๋กœ ๋ง์”€๋“œ๋ฆฌ์ž๋ฉด Python์€ Java์˜ Spring๊ณผ ๋‹ฌ๋ฆฌ ๋™๊ธฐ ์ฒ˜๋ฆฌ๋ณด๋‹ค๋Š” ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ๊ฐ€ ๋” ๋‚˜์€ ๋น›์˜ ์„ฑ๋Šฅ์„ ๋ณด์ธ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํŒŒ์ด์ฌ์˜ ๋น„๋™๊ธฐ ํŒจ๋Ÿฌ๋‹ค์ž„์€ ๊ทธ ์—ญ์‚ฌ๊ฐ€ ๋งค์šฐ ๋ณต์žกํ•˜๋‹ค๊ณ  ํ•  ์ˆ˜ ์žˆ์„ ์ •๋„๋กœ ์ˆ˜๋งŽ์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ๊ณ  ๊ทธ ๋งˆ์ €๋„ ์“ฐ๊ธฐ ์–ด๋ ค์šด ๋ถ€๋ถ„์— ์†ํ•ฉ๋‹ˆ๋‹ค. Coroutine๊ณผ asyncio Python์˜ ๋™์‹œ์„ฑ ์ฒ˜๋ฆฌ๋Š” Thread, Process์™€ ๊ฐ™์ด ๋™๊ธฐ์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ ์ˆ˜ํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ Process๋ฅผ ์ด์šฉํ•œ ๋™์‹œ์„ฑ ์ฒ˜๋ฆฌ๋Š” Context swi..

2021. 5. 2. 19:38

[FastAPI] 10. Middleware๋ฅผ ์ด์šฉํ•œ ์ „ํ›„ ์ฒ˜๋ฆฌ

API๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ฒ˜๋ฆฌ ์‹œ๊ฐ„์ด ์–ด๋Š ์ •๋„ ์†Œ๋ชจ๋˜๋Š”์ง€ ๊ถ๊ธˆํ•˜๋‹ค๊ฑฐ๋‚˜ ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ์š”์ฒญ์„ ๋ฐ›์•˜์„ ๋•Œ ๋ฐ›์€ EndPoint์™€ ๋ฐ์ดํ„ฐ๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ์š”? Middleware Spring์—์„œ๋Š” Intercepter, Filter์™€ ๊ฐ™์€ ์ค‘๊ฐ„ ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค๋ฉด, Flask์—์„œ๋Š” App Context ์ค‘ after_request๋‚˜ before_request ๋“ฑ์˜ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋กœ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋“ฑ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค. FastAPI์—๋Š” Middleware ํŒจํ„ด์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. Middleware ํŒจํ„ด์€ API ํ˜ธ์ถœ ์ „ํ›„๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ํ•˜๋‚˜์˜ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋˜๊ณ  ๋‚œ ๋’ค, API Router๋กœ ์š”์ฒญ์„ ๋„˜๊ธฐ๋Š” ํŒจํ„ด์ž…๋‹ˆ๋‹ค. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์š”์ฒญ์„ ๋ฐ›์œผ๋ฉด ์ด ์š”์ฒญ์€ ๋จผ์ € Middleware์—์„œ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ..

2021. 2. 13. 13:26

[FastAPI] 6. Google-auth ๋ฐ PyJWT๋ฅผ ์ด์šฉํ•œ OAuth2 ์ธ์ฆ ๊ตฌํ˜„ 1

์ด๋ฒˆ ํฌ์ŠคํŠธ์—์„œ๋Š” ์ธ์ฆ์— ๋Œ€ํ•œ ์ด์•ผ๊ธฐ๋ฅผ ํ•ด๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค. Spring์—์„œ๋Š” Spring Security๋ผ๋Š” ๋ชจ๋“ˆ์„ ์ œ๊ณตํ•˜์—ฌ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ธ์ฆ์— ๋Œ€ํ•œ ๊ตฌํ˜„์„ ๊ฐœ๋ณ„์ ์œผ๋กœ ํ•˜์ง€ ์•Š๊ณ ๋„ ์‰ฝ๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์กด์žฌํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•˜์—ฌ Google ๊ฐœ๋ฐœ์ž ์ฝ˜์†”์—์„œ Client ID๋ฅผ ๋ฏธ๋ฆฌ ๋ฐœ๊ธ‰๋ฐ›์€ ํ›„ ๊ตฌํ˜„๋˜์–ด ์žˆ๋Š” ๊ตฌํ˜„์ฒด๋งŒ ์ž˜ ์‚ฌ์šฉํ•˜๋ฉด ์–ด๋ ต์ง€ ์•Š๊ฒŒ OAuth2 ์ธ์ฆ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์—ˆ์ฃ . FastAPI๋„ ์ด์™€ ๋น„์Šทํ•˜๊ฒŒ OAuth2 ์ธ์ฆ์„ ๊ตฌํ˜„ํ•˜์ง€๋งŒ JWT๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์—๋Š” ๋ณ„๋„์˜ ๊ตฌํ˜„ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ ํฌ์ŠคํŠธ์—์„œ๋Š” ์ด ๋‘ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ฐ€์ง€๊ณ  OAuth2 ์ธ์ฆ์„ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋Š”์ง€์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. [Spring boot] Spring boot Security๋กœ ์‹œ์ž‘ํ•ด๋ณด๋Š” ์ธ์ฆ Spring ..

2020. 12. 25. 16:42

[FastAPI] 1. GET, POST, PUT, DELETE ๋“ฑ ๊ธฐ๋ณธ API ๋งŒ๋“ค๊ณ  ๋ฌธ์„œ ์ž๋™ํ™” ํ•ด๋ณด๊ธฐ

์ง€๋‚œ ๊ธ€์— ์ด์–ด์„œ FastAPI๋ฅผ ์ด์šฉํ•ด์„œ ๊ธฐ๋ณธ์ ์ธ REST API ๊ฐœ๋ฐœ ์ด์•ผ๊ธฐ ๋‘ ๋ฒˆ์งธ๋ฅผ ์ด์–ด๊ฐ€๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ REST API๋ฅผ ๊ฐœ๋ฐœํ•˜๋ฉด ์ฃผ์š” ๋ฉ”์†Œ๋“œ ์ข…๋ฅ˜ 5๊ฐ€์ง€๊ฐ€ ์žˆ๋Š”๋ฐ์š”. ๋ฐ”๋กœ GET, POST, PUT, DELETE, PATCH ์ด๋ ‡๊ฒŒ 5๊ฐ€์ง€ ์ž…๋‹ˆ๋‹ค. ๋ฌผ๋ก  ์ด ์™ธ์—๋„ OPTIONS๊ฐ€ ์žˆ์ง€๋งŒ ์ด ๊ธ€์—์„œ๋Š” ๋‹ค๋ฃจ์ง€ ์•Š๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ API ๋งŒ๋“ค๊ธฐ (GET) REST API์˜ ๊ธฐ๋ณธ API๋Š” ๋จผ์ € GET ๋ฉ”์†Œ๋“œ๋ถ€ํ„ฐ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค. GET ๋ฉ”์†Œ๋“œ๋Š” ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฐ€์ ธ์˜ฌ ๋•Œ ์“ฐ๋Š” READ API ์ž…๋‹ˆ๋‹ค. FastAPI์—์„œ๋Š” ์•„๋ž˜์˜ ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. from fastapi import FastAPI app = FastAPI() @app.route('/health') async ..

2020. 12. 25. 15:16

[Python] FastAPI ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ด์šฉํ•œ ๋น„๋™๊ธฐ REST API ๊ฐœ๋ฐœ

Python ์–ธ์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ REST API ์„œ๋ฒ„๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ตญ๋‚ด ํ˜น์€ ๋งŽ์€ ๊ฐœ๋ฐœ์ž๋“ค์˜ ์‚ฌ๋ž‘์„ ๋ฐ›๊ณ  ์žˆ๋Š” Django, ๊ทธ๋ฆฌ๊ณ  ๊ฐ€๋ฒผ์šด ํ”„๋ ˆ์ž„์›Œํฌ๋กœ์จ ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” Flask ๋“ฑ ์—ฌ๋Ÿฌ๊ฐ€์ง€๊ฐ€ ์žˆ๋Š”๋ฐ์š”. ์ด๋ฒˆ ๊ธ€์—์„œ๋Š” Jetbrains์˜ IDE ๋„๊ตฌ์ธ PyCharm๊ณผ FastAPI ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ด์šฉํ•ด์„œ REST API ์„œ๋ฒ„๋ฅผ ๊ฐœ๋ฐœํ•˜๋Š” ์‹œ๊ฐ„์„ ๊ฐ€์ ธ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. What is FastAPI? Python์—์„œ๋Š” ์›น ์„œ๋ฒ„์™€ ์—ฐ๋™ํ•˜๊ธฐ ์œ„ํ•ด WSGI๋ผ๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ WSGI๋Š” ๋™๊ธฐ ๋ฐฉ์‹์œผ๋กœ ํ”„๋กœ๊ทธ๋žจ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฏธ๋ฆฌ ๋“ค์–ด์˜จ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ๋•Œ๊นŒ์ง€ ๋‹ค์Œ ์‚ฌ๋žŒ์ด ๊ณ„์† ๊ธฐ๋‹ค๋ ค์•ผ ํ•˜๋Š” ๋‹จ์ ์„ ๊ฐ์ˆ˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. FastAPI๋Š” Starlette์ด๋ผ๋Š” ๋น„๋™๊ธฐ ํ”„..

2020. 12. 20. 11:14

[Python] PyCharm์—์„œ Poetry๋ฅผ ์ด์šฉํ•œ ๋””ํŽœ๋˜์‹œ ๊ด€๋ฆฌ

์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์‹œ ๋””ํŽœ๋˜์‹œ์˜ ๊ด€๋ฆฌ๋Š” ์ด์ œ ์„ ํƒ์ด ์•„๋‹Œ ํ•„์ˆ˜๊ฐ€ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์—ฌํƒœ๊นŒ์ง€ Python ์–ธ์–ด๋ฅผ ์ด์šฉํ•ด ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์„ ํ•˜์˜€์„ ๋•Œ๋Š” requirement๋ฅผ ์ด์šฉํ•˜์—ฌ ํ™˜๊ฒฝ๋ณ„๋กœ ๋””ํŽœ๋˜์‹œ ๊ด€๋ฆฌ๋ฅผ ํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ requirements๋Š” ํ•˜๋‚˜์˜ ๋””ํŽœ๋˜์‹œ๋ฅผ ์„ค์น˜ํ•  ๋•Œ ํ•˜์œ„ ์š”์†Œ๊นŒ์ง€ ์„ค์น˜ํ•ด์ฃผ์ง€ ์•Š์•„ ์ข…์†๋˜๋Š” ๋””ํŽœ๋˜์‹œ๋ฅผ ์ˆ˜๋™์œผ๋กœ ์„ค์น˜ํ•ด์•ผ ํ•˜๋Š” ๋ถˆํŽธํ•จ์ด ์žˆ์Šต๋‹ˆ๋‹ค. Poetry Poetry - Python dependency management and packaging made easy. Intuitive CLI Poetry's commands are intuitive and easy to use, with sensible defaults while still being configurable. Soon ex..

2020. 12. 6. 18:42

[Python] REST API ๊ฐœ๋ฐœ๋กœ ์•Œ์•„๋ณด๋Š” WSGI, ASGI

REST API ์„œ๋ฒ„๋ฅผ ๊ฐœ๋ฐœํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ด์ œ ํŠน์ • ์–ธ์–ด๋ฅผ ๋ฐฐ์›Œ์•ผ ํ•  ํ•„์š” ์—†์ด ์›ํ•˜๋Š” ์–ธ์–ด๋กœ ์ž์œ ๋กญ๊ฒŒ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๋Š” ์„ธ์ƒ์ด ์˜ค๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. Python ์–ธ์–ด ๋˜ํ•œ ๋‹ค์–‘ํ•œ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ œ๊ณตํ•จ์œผ๋กœ์จ REST API ์„œ๋ฒ„๋ฅผ ์‰ฝ๊ฒŒ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ์š”. ์ด๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋‹ค์–‘ํ•œ ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ๋งŽ์ด ์กด์žฌํ•˜์ง€๋งŒ ๊ทธ ์ค‘ ๊ฐ€์žฅ ๋ณดํŽธํ™” ๋˜์–ด ์•Œ๋ ค์ง„ ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ์•„๋ž˜์˜ ๋‘ ๊ฐ€์ง€ ์ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. Django Flask Django๋Š” MTV ํŒจํ„ด์„ ์ œ๊ณตํ•˜์—ฌ API ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํ…œํ”Œ๋ฆฟ์„ ์ด์šฉํ•˜์—ฌ ์ •์  HTML ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด ๋ทฐ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋„๋ก ์ œ๊ณตํ•˜์—ฌ ๋น ๋ฅธ ๊ฐœ๋ฐœ์„ ํ†ตํ•ด ๋†’์€ ์ƒ์‚ฐ์„ฑ์„ ์ž๋ž‘ํ•˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ์ž…๋‹ˆ๋‹ค. ๋ฐ˜๋ฉด Flask๋Š” ์˜ค์ง API๋งŒ์„ ์‰ฝ๊ฒŒ ์ œ๊ณตํ•˜์—ฌ ๋น ๋ฅธ API ์„œ๋ฒ„๋งŒ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋„๋ก ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด ํŠน์ง•์ด์ฃ . Sprin..