FastAPI 비동기 API를 pytest로 테스트 하기
poetry로 Python 프로젝트를 세팅하고 FastAPI의 비동기 API를 pytest로 테스트 해보겠습니다. 보통 Database transaction이 있는 동작의 경우 DB 연결을 비동기 형태로 해서 API를 구현하는 경우가 있을텐데 이런 경우 sync 형태로 pytest를…
poetry로 Python 프로젝트를 세팅하고 FastAPI의 비동기 API를 pytest로 테스트 해보겠습니다. 보통 Database transaction이 있는 동작의 경우 DB 연결을 비동기 형태로 해서 API를 구현하는 경우가 있을텐데 이런 경우 sync 형태로 pytest를…
FastAPI에서 Celery를 사용하여 비동기 태스크를 실행하는 예제를 정리해보겠습니다. 참고로 localhost에 redis가 동작중이어야합니다. main.py from fastapi import FastAPI from celery_worker import divide app = FastAPI() @app.get("/") async def root(): return {"message":…
pyenv 설치 pyenv 설치하기 전에 의존성 패키지들을 설치한다. sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ xz-utils tk-dev 의존성 패키지…
s3 bucket에 있는 파일 목록 보기 import boto3 s3 = boto3.resource('s3') my_bucket = s3.Bucket('some/path/') for my_bucket_object in my_bucket.objects.all(): print(my_bucket_object) 참고 python - Listing contents of a bucket with boto3 -…
numpy import 하기 import numpy as np numpy array 기본 생성 nd1 = np.array([[1,2], [3,4]]) nd1 array([[1, 2, 3], [3, 4, 1]]) numpy 주요 속성 nd1.ndim ## 차원(rank) nd1.size ##…
Homebrew와 pyenv는 설치되어 있다고 가정하겠다. pyenv를 이용한 Anaconda 설치 $ pyenv install --list 위 명령으로 설치 가능한 Anaconda 버전 리스트를 확인할 수 있다. anaconda3-5.0.0 anaconda3-5.0.1 anaconda3-5.1.0 anaconda3-5.2.0 anaconda3-5.3.0 anaconda3-5.3.1 위와…
노래 파일에서 보컬과 MR 파트를 분리하는 Spleeter라는 패키지를 소개한다. 상당한 퀄리티의 분리 결과를 보여준다. 먼저 원음과 분리 결과를 비교해보자. 원곡 https://youtu.be/ruboudmBTjA 보컬만 분리한 음원 https://youtu.be/UnspAYGkxXk 원곡과 분리한 음원을 들어보면 꽤나…
$ brew install pygobject3 gtk+3 $ export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/opt/libffi/lib/pkgconfig" $ pip install gobject PyGObject
MacOS에서 PyGObject 패키지를 pip으로 설치하는 과정에서 다음과 같은 오류가 발생했다. ERROR: Command errored out with exit status 1: command: /Users/victor/venv/dev_py36/bin/python /Users/victor/venv/dev_py36/lib/python3.6/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /var/folders/cb/hj031cjn06v25qv773t8s7qm0000gn/T/tmps1lk36vj cwd: /private/var/folders/cb/hj031cjn06v25qv773t8s7qm0000gn/T/pip-install-gm85uy4t/PyGObject Complete output (43 lines): running…
pyenv 명령을 사용하면 여러 버전의 python 설치가 가능하다. $ pyenv install 3.7.5 위 명령으로 설치를 하면 다음과 같이 설치 버전들을 확인 할 수 있다. $ python versions /usr/local/Cellar/python@2/2.7.17_1/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open…