He pointed out some of the issues on pipenv, and his suggestion was to use Poetry instead of pipenv.
In this post, I’ll briefly cover what Poetry is and some usage of it. This is just a first try to use Poetry, and hopefully, I write more details in the future blog posts :)
Poetry is a Python dependency management tool.
The main reason why Poetry developed is mentioned here.
Packaging systems and dependency management in Python are rather convoluted and hard to understand for newcomers. Even for seasoned developers it might be cumbersome at times to create all files needed in a Python project:setup.py, requirements.txt, setup.cfg, MANIFEST.in and the newly added Pipfile.
This is really true that there are many files we should consider such as:
- Pipfile and Pipfile.lock (pipenv)
To solve this messy situation, Poetry comes here for us with only one
pyproject.toml file to manage all the dependencies.
Now, let’s setup Poetry!
- Python 2.7 or 3.4+
I’ll use Python 3.6.0 in this post.
$ python --version Python 3.6.0
Install Poetry via an installer provided.
$ curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python Retrieving Poetry metadata # Welcome to Poetry! This will download and install the latest version of Poetry, a dependency and package manager for Python. It will add the `poetry` command to Poetry's bin directory, located at: $HOME/.poetry/bin This path will then be added to your `PATH` environment variable by modifying the profile files located at: $HOME/.profile $HOME/.bash_profile You can uninstall at any time with `poetry self:uninstall`, or by executing this script with the --uninstall option, and these changes will be reverted. Installing version: 0.12.12 - Downloading poetry-0.12.12-darwin.tar.gz (7.23MB) Poetry (0.12.12) is installed now. Great! To get started you need Poetry's bin directory ($HOME/.poetry/bin) in your `PATH` environment variable. Next time you log in this will be done automatically. To configure your current shell run `source $HOME/.poetry/env`
poetry command, run the following command:
poetry command should be available. Let’s check the Poetry version installed.
$ poetry —version Poetry 0.12.12
First, I’ll create a demo app.
poetry new poetry-demo
The project structure is like this.
$ cd poetry-demo $ tree . ├── README.rst ├── poetry_demo │ └── __init__.py ├── pyproject.toml └── tests ├── __init__.py └── test_poetry_demo.py
[tool.poetry] name = "poetry-demo" version = "0.1.0" description = "" authors = ["[Your Name] <[Your Email]>"] [tool.poetry.dependencies] python = "^3.6" [tool.poetry.dev-dependencies] pytest = "^3.0" [build-system] requires = ["poetry>=0.12"] build-backend = "poetry.masonry.api"
I can specify a dependency in the
pyproject.toml file directly, but it looks easy for me to use
poetry add pendulum
pendulum is added to the
[tool.poetry.dependencies] python = "^3.6" pendulum = "^2.0"
poetry.lock is created.
$ tree . ├── README.rst ├── poetry.lock ├── poetry_demo │ └── __init__.py ├── pyproject.toml └── tests ├── __init__.py └── test_poetry_demo.py
Since this is just a first try to use Poetry, I’ll continue using it and may write a blog post again if I find something useful :)
There are several things I’d like to try:
- [ ] How to integrate with existing requirements.txt?
- [ ] Try Poetry
publishcommand to publish my package to PyPI
- [ ] Compare Poetry with pipenv