Skip to main content

PyCFUtils (Cristi Fati's Utils for Python (&& more)) - a collection of goodies ((cool) scripts / utilities)

Project description

PyCFUtils

PyPI version Python versions License: MIT

PyCFUtils (Cristi Fati's Utils for Python (&& more)) is a cross-platform collection of utility modules covering IO, networking, system operations, ctypes helpers, GUI wrappers (Windows), and SetupTools extensions for building native libraries. It has no global dependencies outside the Python standard library.

Install

python -m pip install --upgrade pycfutils

Usage

IO

import pycfutils.io

print("Press a key in less than one second...")
print(pycfutils.io.read_key(timeout=1))

CTypes

import pycfutils.ctypes

print(pycfutils.ctypes.endianness())

Miscellaneous utilities

import pycfutils.miscellaneous as misc

print(misc.timestamp_string(human_readable=True, separator="T", microseconds=True))
print(tuple(misc.progression(ratio=2, count=20)))
print(
    misc.merge_dicts({1: 2}, misc.nest_object((1,), 3)),
    misc.nested_dict_item({1: {2: 3}}, (1, 2)),
)
print(misc.randomize(180, round_result=True))
print(misc.call_stack())
misc.pretty_print(
    tuple(
        misc.process_path_items(
            path="${a_directory_with_few_child_items}",
            processor=lambda arg: __import__("os").stat(arg).st_size,
        )
    ),
    head="Path items:",
    tail="",
)

Timed execution decorator

import time

import pycfutils.miscellaneous as misc


@misc.timed_execution()
def func(arg0, kw0=1):
    time.sleep(0.2)
    return 5


func("123")

Networking

import pycfutils.network
from pycfutils.exceptions import NetworkException

try:
    print(pycfutils.network.connect_to_server("127.0.0.1", 22))
except NetworkException as e:
    print(e)

System

import pycfutils.system

pycfutils.system.cpu_stress(3)

GUI (Windows only)

import pycfutils.gui

print(pycfutils.gui.message_box("Title", "Text to display", x=320, y=200))

Building a native library (.dll / .so) with SetupTools

Parts of setup.py:

# Requires SetupTools (python -m pip install setuptools) for Python >= 3.12
from setuptools import setup

from pycfutils.setup.command.build_clibdll import build_clibdll
from pycfutils.setup.command.install_platlib import install_platlib  # Optional

dll = (
    "dll_name",
    {
        "sources": [
            "src0.c",
            "src1.c",
        ],
        # ...
        "dll": True,  # False (or nothing) for regular (static) library
        "copy_files": {  # Optional (copy artifacts)
            "dll_name.so": "pkg_name",  # dll_name.dll on Win
        },
        # ...
    },
)


setup(
    name="pkg_name",
    # ...
    cmdclass={
        "build_clib": build_clibdll,
        "install": install_platlib,
    },
    libraries=[dll],
    # ...
)

CLI tools

The tools folder contains CLI wrapper scripts. To list them and view their help:

Unix:

ls "pycfutils/tools"
for script in $(find "pycfutils/tools" -maxdepth 1 -type f); do python "${script}" -h; done

Windows:

dir /b "pycfutils\tools"
for /f %g in ('dir /b /a-d /a-l "pycfutils\tools\*.py"') do (python "pycfutils\tools\%g" -h)

They can also be run as modules. For example, in two separate terminals:

Terminal 1:

python -m pycfutils.tools.connect_to_server -a 127.0.0.1 -p 16180

# Go to Terminal 2 and start the server, then come back and re-run:

python -m pycfutils.tools.connect_to_server -a 127.0.0.1 -p 16180

Terminal 2:

python -m pycfutils.tools.start_server -a 127.0.0.1 -p 16180

Notes

  • The package has no global dependencies outside the Python standard library. However, some subpackages have their own requirements:
    • pycfutils.setup.command: requires SetupTools (python -m pip install setuptools) for Python >= 3.12

Changelog

See CHANGELOG for a full list of changes.

Contributing

Contributions are welcome. Please open an issue or submit a pull request on GitHub.

License

This project is licensed 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

pycfutils-2026.6.12.tar.gz (44.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pycfutils-2026.6.12-py3-none-win_amd64.whl (54.3 kB view details)

Uploaded Python 3Windows x86-64

pycfutils-2026.6.12-py3-none-win32.whl (53.6 kB view details)

Uploaded Python 3Windows x86

pycfutils-2026.6.12-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file pycfutils-2026.6.12.tar.gz.

File metadata

  • Download URL: pycfutils-2026.6.12.tar.gz
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for pycfutils-2026.6.12.tar.gz
Algorithm Hash digest
SHA256 c523477027c99d877a395228e712d64778babf9207c78a45d2e17fc9bb773942
MD5 a133d83e90069ffbed241d23047ecb6c
BLAKE2b-256 492f672740b1c086e42ae1f833b222e9a2082e52961092b2609bfcca4ad53bad

See more details on using hashes here.

File details

Details for the file pycfutils-2026.6.12-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for pycfutils-2026.6.12-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 d3a1dec72d415f0a98918844f2b51533a5837bc9e8443feadd1a45a72d2cbf87
MD5 0e559da33977d96928685cb6263a07f1
BLAKE2b-256 743b3a49751ab4e5650af9aeedeedda4db1e35a5081a3af4485a28605026413d

See more details on using hashes here.

File details

Details for the file pycfutils-2026.6.12-py3-none-win32.whl.

File metadata

  • Download URL: pycfutils-2026.6.12-py3-none-win32.whl
  • Upload date:
  • Size: 53.6 kB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for pycfutils-2026.6.12-py3-none-win32.whl
Algorithm Hash digest
SHA256 ee20f360f954488480955af23363cde377362f66be6b7fddb79783d36e97cd53
MD5 9ad35ca0587b667ad15c7b6dd352e238
BLAKE2b-256 4b53dd400cfc836d85ecd4cf4e22e2e88f6a38fcd8fd3740d030d7f8627db311

See more details on using hashes here.

File details

Details for the file pycfutils-2026.6.12-py3-none-any.whl.

File metadata

  • Download URL: pycfutils-2026.6.12-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for pycfutils-2026.6.12-py3-none-any.whl
Algorithm Hash digest
SHA256 8f15f06d617b4306a85190b1c074612c2731c826361b6bb15f23c68977d84462
MD5 4dc17b63d81b81ce3d7bdba26302bafb
BLAKE2b-256 9aef5c3454e313c0752470aa94d80bdf4480e72d978a289badb283b88c5c5862

See more details on using hashes here.

Supported by

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