Code Monkey home page Code Monkey logo

python-poetry-demo's Introduction

Python Poetry Demo

Setup Python

# brew install or upgrade pyenv
brew update
brew install pyenv
brew upgrade pyenv

pyenv --version
# pyenv 2.3.26

pyenv install -l | grep 3.11
pyenv install 3.11
pyenv global 3.11

pyenv versions
#   system
# * 3.11.5 (set by ~/.pyenv/version)

python --version
# Python 3.11.5

Setup Poetry

export POETRY_HOME=/opt/poetry
export PATH="$POETRY_HOME/bin:$PATH"

curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python3 -

poetry --version
# Poetry (version 1.6.1)

poetry completions zsh > ~/.zfunc/_poetry
  • update .zshrc
export PYTHONDONTWRITEBYTECODE=1

export POETRY_HOME=/opt/poetry
export PATH="$POETRY_HOME/bin:$PATH"
fpath+=~/.zfunc
autoload -Uz compinit && compinit

Setup Project

poetry new poetry-demo --src
cd poetry-demo

poetry config --list

poetry config virtualenvs.in-project true
# in ~/Library/Application\ Support/pypoetry/config.toml
poetry config virtualenvs.in-project true --local
# in poetry.toml

poetry env info
poetry env list

# create .venv
poetry env use 3.11

Manage Packages

poetry add requests
poetry show
poetry remove requests

# install from poetry.lock
poetry install

poetry update --dry-run
poetry update

poetry self update

poetry run python -V
# Python 3.11.5
poetry shell

poetry check
# All set!

Run FastAPI

poetry add fastapi uvicorn

# add src/main.py

# maybe you don't need this
# export PYTHONPATH="./src:${PYTHONPATH}"

poetry run uvicorn main:app --reload

curl http://127.0.0.1:8000/
# {"msg":"Hello World"}

# OpenAPI docs
# http://localhost:8000/docs

Run PyTest

poetry add pytest pytest-cov httpx --group dev

# add tests/test_main.py

poetry run pytest
poetry run pytest --cov=src -v
poetry run pytest --cov=src -v --cov-report=html

python -m http.server -d ./htmlcov 8001
# http://localhost:8001/

python-poetry-demo's People

Contributors

kenfj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.