Skip to main content

A fried mix of python utilities

Project description

FrittoMisto 🍟


Welcome to FrittoMisto, a Python module with a Fried Mix of utilities to enhance your day to day coding experience.

Please note that FrittoMisto is currently at its very verge and not thoroughly tested. We invite you to explore, experiment, share your feedback or, even better, contribute! 👩‍🍳



🍤 Features / Philosophy

If you frequently develop Python tools, you might have experienced the repetition of using similar utilities or helpers across various applications. FrittoMisto was born out of my desire to consolidate these commonly used tools into a single swiss army knife. Now, I can effortlessly import and reuse them whenever necessary.

  • Mix of Utilities: FrittoMisto serves up a diverse array of utilities, ranging from string manipulation to system interactions.

  • Simplicity: Enjoy the simplicity and ease of use that FrittoMisto brings to your projects. FrittoMisto utilities are designed to be intuitive and require minimal code to achieve common tasks.

🍳 Installation

Install FrittoMisto using pip: pip install frittomisto

🍽️ Usage

Whet your appetite with a quick sample of FrittoMisto in action:

from frittomisto.path import cd

with cd("/temporarily/move/here"):
  # do some stuff 

🍲 Documentation

Path module

Utilities for paths and file system operations.

cd context manager

A context manager to temporarily move to a directory.

from pathlib import Path
from frittomisto.path import cd

with cd("/path/to/dir"):
  print(Path.cwd()) # temporarely moved to "/path/to/dir"

sanitize_path

An utility to sanitize untrusted paths.

from frittomisto.path import sanitize_path

# Throws a ValueError exception if path is not within allowed_dir 
sanitize_path("/path/to/dir", "/path/to/allowed/dir")

# Returns normalized absolude path if path is within allowed_dir
sanitize_path("/path/../to/dir", "/path/") # returns "/path/dir"

Async module

Mix of asyncio utilities.

make_sync

A simple decorator to transform any async function into an sync function.

from frittomisto.asyncio import make_sync

@make_sync
async def an_async_function():
  ...

def a_sync_function():
  # The async function is now a sync function
  an_async_function()

Profiling module

pp utils

The profiling module offers a set of simple functions to manage multiple perf counters:

  • pp_start(name) starts a new counter named name
  • pp_stop(name) stops the counter name
  • pp_get(name) gets stat info of the counter name
  • pp_stats() pretty print stats for all counters
from frittomisto.profiling import pp_start, pp_stop, pp_stats

pp_start("outer")
  for i in range(10):
    pp_start("func1")
    func1()
    pp_stop("func1")
    if i % 2 == 0:
      pp_start("func2")
      func2()
      pp_stop("func2")

pp_stop("outer")
pp_stats()

# This will show perf stats in a table format:
# PID    | Name  | tot_time           | rounds | avg_time            | max_time
# 169003 | outer | 5.679527849017177  | 1      | 5.679527849017177   | 5.679527849017177
# 169003 | func1 | 4.06138202897273   | 10     | 0.406138202897273   | 0.8546963339904323
# 169003 | func2 | 1.6178952640620992 | 5      | 0.32357905281241983 | 0.46843800198985264

Config module

Utilities to manage your project configs.

cfg

The global instance of the program's config.

import os
from pathlib import Path
from frittomisto.cfg import cfg
 with open(str(Path.cwd() / "frittomisto.toml"), "w", encoding="utf-8") as f:
  f.write(
    """
    [foo]
    bar = "hello"
    """
)

os.chdir("subdir") # configs are searched in all parent dirs
print(cfg["foo"]["bar"]) # prints hello

IO module

no_print

Context manager to disable all calls to print

from frittomisto.io import no_print

with no_print():
  print("hello") # does nothing

Logging module

Logging utils.

get_logger

Get a named logger.

from frittomisto.logging import get_logger

log = get_logger("my logger")
log.error("error message") # logs an error

log_level

Context manager to temporarily change log level.

from frittomisto.logging import get_logger, log_level

with log_level("DEBUG"):
  log = get_logger("my logger")
  log.debug("debug message") # the debug message will be shown

URL module

Utilities to work with URLs

extract_urls

Scan text for urls.

from frittomisto.url import extract_urls
text = "My URL is http://example.com"
urls = extract_urls(text)
print(urls[0]) # http://example.com

👨‍🍳 Contributing

Craving more features or found a bug in our recipe? Contribute to FrittoMisto by opening an issue or submitting a pull request. Your contributions make the mix even more delightful!

License

FrittoMisto is released under the MIT License.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

frittomisto-0.0a2.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

frittomisto-0.0a2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file frittomisto-0.0a2.tar.gz.

File metadata

  • Download URL: frittomisto-0.0a2.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for frittomisto-0.0a2.tar.gz
Algorithm Hash digest
SHA256 866b5968dc1035de22d78ce66419ab2d6725bed62bb7e23e72e6fc257febf133
MD5 13d4d09ae72f92da0277364992f20887
BLAKE2b-256 3ab4c9099a04e23cbb5629e4d15f7d1e07f0354fd6f01a0ac125aa31990e855b

See more details on using hashes here.

File details

Details for the file frittomisto-0.0a2-py3-none-any.whl.

File metadata

  • Download URL: frittomisto-0.0a2-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for frittomisto-0.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 2c6686021309bef1658d0b0b7f8a05c24a539d0ba5388a13e38b85a03a9e2028
MD5 e6412282f6b6380865fb4b60bc25c45a
BLAKE2b-256 f8cf0184df64b9845639fce2e53e95b5ded70e5945ba3c8ef0394a4883c26a41

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page