Python libraries of interest

Python libraries

A collection I libraries I have seen that maybe useful in the future, or have used or just sound cool etc.

MQTT

This is one of the "main" Python client libraries for MQTT https://pypi.org/project/paho-mqtt

pip install paho-mqtt

pynput

Monitor and control user input devices

Simulate input from Mouse or keyboard or listen to mouse oir keyboard events https://pypi.org/project/pynput/

https://pastebin.com/t2iyW2gc?fbclid=IwAR1ahUmQ_VAocUSbSX0k0wMes_Ylp-9RFUaRaIjZdmHzHlWM6LayGDzMYLo

uMQTT

Micro Python MQTT library

Functools

Data structures

https://levelup.gitconnected.com/3-data-structures-you-probably-didnt-know-already-existed-in-python-f4cc313c5520

Heap

A heap is a tree-based data structure that is used to implement an abstract data type called Priority Queue.

Double Ended Queue (Deque)

A Double-ended queue is a generalization of stacks and queues that allows append and pop operations from both ends.

It is preferable to a list as it has approximately O(1) time complexity for append and pop operations in either direction.

Array

An Array is a data structure that stores its elements in contiguous memory locations.
Will a list normally be ok? - Lets look at speeds and memory and do some testing...

While lists can store heterogeneous data (data of different types), arrays store homogeneous items (requiring a type specification at initialization) which makes them more memory-efficient for large datasets of uniform data.

Packaging in Python / Debian

pyproject.toml

Define the meta data first - generally the main single source of truth for "modern" Python systems

Pybuilder

https://pybuilder.io/documentation/tutorial

Some decorators

https://levelup.gitconnected.com/top-10-python-decorators-every-developer-should-master-b78420574b9f

  1. @retry - Resilience in Code Handling errors gracefully is essential. The @retry decorator allows you to retry a function in case of exceptions, ensuring your data analysis pipelines keep running smoothly.

from tenacity import retry, stop_after_attempt @retry(stop=stop_after_attempt(3)) def process_data(): # Data processing code 8. @log_function_call - Debugging Friend Struggling with debugging? The @log_function_call decorator logs every function call, helping you trace issues in your data analysis scripts.

def log_function_call(func): def wrapper(args, kwargs): print(f"Calling {func.name} with args: {args}, kwargs: {kwargs}") result = func(args, **kwargs) print(f"{func.name} returned: {result}") return result 9. @time_it - Performance Tracker Optimize your code by measuring execution time. The @time_it decorator provides valuable insights into performance bottlenecks.

import time def time_it(func): def wrapper(args, *kwargs): start_time = time.time()

links

social