DEV Community

Tuana Celik
Tuana Celik

Posted on

Building My First Python Package with Poetry

A lot of firsts happening for me here. First post on Dev.to AND first published Python package. So I though I'd take the opportunity to share my experience building and publishing the package with Poetry 😊

Cumul.io has a number of SDKs available for people to install and use, but we were missing one in Python. So I built one! It's a simple one that provides interaction with our Core API (For those of you who don't know I'll add some info about Cumul.io at the end of this post). This might not be surprising to a lot of you but as it was my first go, I soon discovered there are a plethora of routes you can take to publish a package in PyPI and so I put in some research time to decide which one would be the least painful for me. In the end I decided on going for Poetry. This video by Black Hills Information Security was extremely helpful to understand the different options and the advantages and disadvantages that come with them. Here's my takeaway and experience:

  1. Poetry makes the configuration of your project a lot simpler than some of the other methods out there. You end up with only a pyproject.toml (not even a requirements.txt is needed any more) vs setup.py and reqiurements.txt that you need with Pipenv for example. Example pyproject.toml:
[tool.poetry]
name = "cumulio"
version = "x.x.x"
description = "Cumulio Python SDK for the Core API"
authors = []
readme = "README.md"
homepage = "Link to your homepage"
repository = "Link to your repo"
exclude = ["test/*"]
include = ["LICENSE"]
classifiers = [
    "Topic :: Software Development :: Libraries :: Python Modules"
]
packages = [
    { include = "cumulio"}
]

[tool.poetry.scripts]

[tool.poetry.dependencies]
python = "^3.7"
requests = "^2.25.1"

[tool.poetry.dev-dependencies]
autopep8 = "^1.5.6"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Enter fullscreen mode Exit fullscreen mode

Notice how you can set your classifiers for PyPI as well as your dependencies.

  1. Not only does it manage your dependencies, it also manages your packaging and upload to PyPI.
  2. Super easy to work in a virtual environment and get shell access inside the virtual environment. Literally just poetry shell

The current Cumul.io Python Package provides a simple endpoint to the Cumul.io API. The code and Poetry setup are all open source on GitHub. Now I know how to upload packages to PyPI, I intend to expand the SDK!

As a first timer, Poetry made my life a lot easier than it could have been. Let me know what your experiences were and if any what disadvantages to poetry you've noticed that I haven't yet. I would be interested to know!

About Cumul.io:

Cumul.io is an API first data analytics and dashboarding platform that makes integrating dashboards and charts into your own platforms super easy. It's designed so that anything you can do frim within Cumul.io's UI, you can also do via the API which makes it quite a customizable option for a data analytics tool. The SDKs are there and are being expanded to cover a wide range of languages that are most commonly used in web development and data science (hence the reason for a Python SDK).

Top comments (0)