Skip to content

Poetry Guide

Installation and Setup

  1. Install Poetry:

    sh
    curl -sSL https://install.python-poetry.org | python3 -
  2. Configure Poetry:

    sh
    poetry config virtualenvs.in-project true

Creating a New Project

  1. Create a new project:

    sh
    poetry new my-project
    cd my-project
  2. Initialize a new project in an existing directory:

    sh
    cd existing-directory
    poetry init

Adding and Removing Modules

  1. Add a module:

    sh
    poetry add requests
  2. Remove a module:

    sh
    poetry remove requests

Exporting to Requirements

  1. Export dependencies to a requirements.txt file:
    sh
    poetry export -f requirements.txt --output requirements.txt

Publishing Packages to PyPI / Test PyPI

  1. Configure Poetry to use Test PyPI:

    sh
    poetry config repositories.test-pypi https://test.pypi.org/legacy/
  2. Publish to Test PyPI:

    sh
    poetry publish -r test-pypi
  3. Publish to PyPI:

    sh
    poetry publish --build

This guide provides a basic overview of using Poetry for Python project management, including installation, project creation, dependency management, exporting requirements, and publishing packages.