Skip to content
Muslu Yüksektepe

cemirutils

A library of helper functions and decorators that saves time for both Python beginners and experienced developers.

cemirutils is a helper library that gathers functions, classes and decorators into one package to help both Python beginners and experienced users save time in everyday work. It brings commonly used Linux and Python commands, simple data processing functions, and HTTP, email and PostgreSQL operations under the same roof. I developed the library together with Cem Emir Yüksektepe. The first version was published on PyPI in May 2024, and the latest version, 2.2.5, came out in August 2025.

Purpose

I noticed I was writing the same small helper functions over and over in different projects. Measuring how long a function takes, retrying a failed operation a few times, counting the business days between two dates or flattening a list came up again in every project. We built cemirutils to collect these pieces in one place and make them usable with a single import, both for ourselves and for people learning Python. We wrote the comments in the code in both Turkish and English, so anyone looking through the library can read what each function does in their own language.

How it works

The library is made up of classes, each covering a particular area. The main class, CemirUtils, works on a list or dictionary passed to it. With this class you can get the first and last elements of a list, its unique values, sum, average, and largest and smallest values. A list can be sorted in ascending or descending order, elements above or below a given value can be filtered, and nested lists can be flattened into one level. On the dictionary side, you can list keys, filter by key and merge two dictionaries.

The same class also has functions for working with time. Some of them find the number of days and business days between two dates, return the difference between two times in hours, minutes and seconds, add days to a date, and check whether a day falls on a weekend or a year is a leap year. Functions that call Linux commands such as ls, cat, cp, mv, mkdir, find and grep from inside Python also live in this class.

Key features

  • The CemirUtilsDecorators class offers decorators that time a function, log its calls, retry it a set number of times when it fails, cache its result, and expire that cache after a given period.
  • The same class includes a rate limiting decorator that caps how many times a function can be called within a time window, a decorator that warns when a deprecated function is used, and a decorator that sends the function's result to a webhook address when it finishes.
  • CemirUtilsLoopTimer reports how long each loop inside a function took, separately and with its line number.
  • CemirUtilsConditions shows, with line numbers, which if and elif conditions fired while a function ran; this helps when debugging complex blocks of conditions.
  • The cprint function prints data types such as dictionaries, lists, numbers and strings in different colors in the terminal.
  • The CemirUtilsHTTP class sends GET, POST, PUT, PATCH and DELETE requests and can start a simple HTTP server with optional SSL and basic authentication.
  • CemirUtilsEmail sends emails with an HTML body and attachments, and can compress the attachments into a zip file if asked. CemirUtilsFunctionNotification emails the result of a function when it runs.
  • The CemirPostgreSQL class creates tables and inserts, reads, updates and deletes records; it can create the database if it does not exist and supports writing queries against JSONB columns.
  • The IPGeolocation class downloads the free IP2Location LITE database, loads it into an SQLite database and finds which country an IP address belongs to.
  • CemirUtilsAMP fetches the HTML of a web page and converts it to AMP format. AMP is a simplified HTML format designed to load quickly on mobile devices.

Technical stack

cemirutils is written with the Python standard library alone and needs no extra packages to install. It uses http.client and urllib for HTTP, smtplib and email for email, sqlite3, csv and zipfile for the IP database, and ast and inspect for analyzing conditions and loops. PostgreSQL operations go through the system's psql command-line client instead of a database driver, and the output is turned into a dictionary structure. The package supports Python 3.9 and later and is distributed under the MIT license.

Use cases

  • I use it in small scripts and automation jobs to cover needs such as timing, retrying and caching with a few decorators.
  • It is a good starting point for showing people who are learning Python how list, dictionary and date operations work, with documented examples.
  • It can be used to get notified by email or webhook when a long or important operation finishes.
  • On servers where extra packages cannot be installed, it provides ready-made tools for HTTP requests, sending email and simple database work.
Category
Python libraries
Year
2024

Technologies

  • Python
  • PyPI
  • Open Source

Links

  • PyPI https://pypi.org/project/cemirutils/
  • GitHub https://github.com/cememir/cemirutils

Back to all projects