Skip to main content

morebuiltins

PyPIGitHub Workflow StatusPyPI - WheelPyPI - Python VersionPyPI - DownloadsPyPI - License

Project Overview:

This library extends Python's standard library by packaging practical utilities inspired by the official documentation and the CPython source code. It provides convenient, production-minded wrappers for common business scenarios while preserving compatibility.

This project enhances Python’s built-ins with additional utilities and follows these principles:

  • No third-party dependencies: Keep the code self-contained for easier distribution.
  • Performance-focused: Designed to be efficient and lightweight.
  • Reusable modules: Standalone functions and modules for simple reuse.
  • MIT licensed: Free to use, modify, and redistribute under the MIT License.
  • Well tested: Modules include tests to ensure stability and compatibility.
  • Beginner friendly: Examples and snippets to help new users solve common tasks.
  • Command-line ready: Includes CLI tools for tasks like downloading Python, building zipapps, running log servers, and analyzing dependencies.
  • Minimal external dependencies: Avoids third-party libraries to simplify packaging (e.g., zipapp/pyz).

Compatibility Break Warnings

  1. 1.3.4 (2025-09-17)
    1. Refactor of morebuiltins.cmd.log_server
  2. 1.3.2 (2025-08-02)
    1. move async_logger, AsyncQueueListener, LogHelper, RotatingFileWriter, and SizedTimedRotatingFileHandler from morebuiltins.funcs to morebuiltins.logs.
  3. 1.3.0 (2025-03-08)
    1. rename morebuiltins.functools to morebuiltins.funcs to avoid conflict with functools in python standard library.

Changelog

Install

pip install -U morebuiltins

pip install git+https://github.com/ClericPy/morebuiltins.git@master

pip install git+https://github.com/ClericPy/morebuiltins.git@1.0.3

  • Use pyz(downloaded from releases)

  • Use uvx morebuiltins morebuiltins.cmd.xxx

import sys
sys.path.insert(0, 'morebuiltins.pyz')
import morebuiltins
print(morebuiltins.__file__)
# morebuiltins.pyz/morebuiltins/__init__.py
  • morebuiltins.pyz command-line

zipapps: python morebuiltins.pyz -m morebuiltins.zipapps -o morebuiltins.pyz -c morebuiltins

download_python: python morebuiltins.pyz -m morebuiltins.download_python

Doc

Module Docs

Compatibility Warning. rename morebuiltins.functools to morebuiltins.funcs to avoid conflict with functools in python standard library after 1.3.0 (2025-04-03).

More Modules:


1. morebuiltins.utils

1.1 ttime - Translates a timestamp to a human-readable string formatted as %Y-%m-%d %H:%M:%S.

1.2 ptime - Parses a timestring formatted as %Y-%m-%d %H:%M:%S back into a timestamp.

1.3 slice_into_pieces - Divides a sequence into “n” segments, returning a generator that yields at most “n” pieces.

1.4 slice_by_size - Slices a sequence into chunks of a specified “size”, returning a generator that produces tuples of chunks.

1.5 unique - Removes duplicate elements from a sequence while preserving the original order efficiently.

1.6 retry - A decorator that retries the decorated function up to “tries” times if the specified exceptions are raised.

1.7 guess_interval - Analyzes a sequence of numbers and returns the median, calculating intervals only if they are greater than or equal to the specified accuracy.

1.8 get_hash - Generates a hash string from the given input string.

1.9 find_jsons - A generator that locates valid JSON strings, supporting only dictionaries and lists.

1.10 code_inline - Minifies Python source code into a single line.

1.11 read_size - Converts byte counts into a human-readable string. Setting shorten=True and precision=0.99 will trim unnecessary decimal places from the tail of floating-point numbers.

1.12 read_time - Converts seconds into a more readable time duration string.

1.13 Validator - Validator for dataclasses. This is very experimental, choose pydantic or msgspec for production use.

1.14 stagger_sort - Ensures that identical groups are ordered and evenly distributed, mitigating data skew. The function does not alter the original list and returns a generator.

1.15 default_dict - Initializes a dictionary with default zero values based on a subclass of TypedDict.

1.16 always_return_value - Got a function always return the given value.

1.17 format_error - Extracts frame information from an exception, with an option to filter out “-packages” details by default. To shorten your exception message.

1.18 Trie - Transforms a standard dictionary into a trie structure that supports prefix matching.

1.19 GuessExt - Determines whether the input bytes of a file prefix indicate a compressed file format.

1.20 xor_encode_decode - Perform XOR encryption or decryption on the given data using a provided key.

1.21 is_running - Check if the given process ID is running.

1.22 set_pid_file - Sets a PID file to prevent multiple instances of a script or process from running concurrently.

1.23 get_paste - This module offers a simple utility for retrieving text from the system clipboard with tkinter.

1.24 set_clip - Copies the given text to the clipboard using a temporary file in a Windows environment.

1.25 switch_flush_print - Set builtins.print default flush=True.

1.26 unix_rlimit - Unix only. RLIMIT_RSS, RLIMIT_FSIZE to limit the max_memory and max_file_size

1.27 SimpleFilter - Simple dup-filter with pickle file.

1.28 FileDict - A dict that can be saved to a file.

1.29 PathLock - A Lock/asyncio.Lock of a path, shared along the path hierarchy.

1.30 i2b - Convert an int to bytes of a specified length, commonly used in TCP communication.

1.31 b2i - Convert a byte sequence to an integer.

1.32 get_hash_int - Generates a int hash(like docid) from the given input bytes.

1.33 iter_weights - Generates an element sequence based on weights.

1.34 get_size - Recursively get size of objects.

1.35 base_encode - Encode a number to a base-N string.

1.36 base_decode - Decode a base-N string to a number.

1.37 gen_id - Generate a readable & unique ID based on the current time(us) and random bytes.

1.38 timeti - Return the number of iterations per second for a given statement.

1.40 cut_file - Cut file to max_bytes, remain_ratio is the ratio of the end part to remain, ensure_line_start is to ensure the first line is a complete line

2. morebuiltins.date

2.1 ScheduleTimer - The ScheduleTimer class facilitates the creation and evaluation of datetime patterns for scheduling purposes.

2.2 Crontab - Crontab python parser.

3. morebuiltins.funcs

3.1 lru_cache_ttl - A Least Recently Used (LRU) cache with a Time To Live (TTL) feature.

3.2 threads - Quickly convert synchronous functions to be concurrent. (similar to madisonmay/Tomorrow)

3.3 bg_task - Avoid asyncio free-flying tasks, better to use the new asyncio.TaskGroup to avoid this in 3.11+. https://github.com/python/cpython/issues/91887

3.4 NamedLock - Reusable named locks, support for timeouts, support for multiple concurrent locks.

3.5 FuncSchema - Parse the parameters and types required by a function into a dictionary, and convert an incoming parameter into the appropriate type.

3.6 InlinePB - Inline progress bar.

3.7 get_type_default - Get the default value for a type. {int: 0, float: 0.0, bytes: b"", str: "", list: [], tuple: (), set: set(), dict: {}}

3.8 func_cmd - Handle function with argparse, typing-hint is nessessary.

3.9 file_import - Import function from file path.

3.10 get_function - Get the function object from entrypoint.

3.11 to_thread - Asynchronously run function func in a separate thread, same as asyncio.to_thread in python 3.9+.

3.12 check_recursion - Check if a function is recursive by inspecting its AST.

3.13 debounce - Debounce a function, rate-limiting (leading) or delaying (trailing) its execution.

3.14 async_call - Automatically call a function asynchronously, whether it's sync or async.

3.15 countdown - A simple countdown timer that prints to the console inline.

3.17 LineProfiler - Line-by-line performance profiler.

3.18 line_profiler - Decorator to profile a function line-by-line.

4. morebuiltins.ipc

4.1 IPCEncoder - An abstract base class for all encoders; implementing the necessary communication protocol requires only the definition of two abstract methods. Be mindful that varying header lengths will impact the maximum packaging size.

4.2 JSONEncoder - JSON text encoder (UTF-8); see IPCEncoder.dumps/loads for the frame convention.

4.3 PickleEncoder - Pickle bytes encoder; only use it between trusted peers, pickle can execute arbitrary code on load.

4.4 SocketLogHandlerEncoder - For a practical demonstration, refer to the test code: morebuiltins/ipc.py:_test_ipc_logging.

4.5 SocketServer - To see an example in action, view the test code: morebuiltins/ipc.py:_test_ipc.

4.6 SocketClient - Client counterpart to SocketServer: use async with SocketClient(host, port, encoder=...),

4.7 find_free_port - Finds and returns an available port number.

4.8 is_port_free - Checks if a port is free.

5. morebuiltins.request

5.1 req - A basic mock for requests, performant albeit simplistic.

5.2 DomainParser - Extracts the Second-level domain (SLD) from a provided hostname or URL.

5.3 unparse_qsl - Provides the inverse operation of parse_qsl, converting query string lists back into a URL-encoded string.

5.4 update_url - Organizes the query arguments within a URL to standardize its format.

5.6 make_response - Generates an HTTP response based on the provided parameters.

5.7 custom_dns - Patch socket.getaddrinfo to translate hosts/ports through a custom map.

5.8 restore_dns - Restore socket.getaddrinfo to the original function frozen at import time.

6. morebuiltins.download_python

6.1 download_python - Download python portable interpreter from https://github.com/indygreg/python-build-standalone/releases.

7. morebuiltins.tk

7.1 TKit - Tkinter kit for dialog usages.

8. morebuiltins.emails

8.1 SimpleEmail - SimpleEmail Sender.

9. morebuiltins.cmd.log_server

9.1 LogServer - Log server for SocketHandler, create a socket server with asyncio.start_server. Custom formatter or rotation strategy with extra in log record.

9.2 get_logger - Get a singleton logger that sends logs to the LogServer.

10. morebuiltins.cmd.proxy_checker

10.1 ProxyChecker - A command line toolkit to check available proxies.

11. morebuiltins.cmd.ui

11.1 launch_ui - Interactive mode, value can be parsed by JSON parser.

11.2 handle_cli - Command Line Interface: interactive mode

11.3 handle_web - Function to Web UI.

11.4 handle_tk1 - Function to tkinter UI. (interactive mode)

11.5 handle_tk2 - Function to tkinter UI.

12. morebuiltins.cmd.parse_deps

12.1 parse_deps - Parse dependencies of a project directory, and find circular dependencies.

13. morebuiltins.snippets.event

13.1 EventTemplate - Event template for event sourcing

14. morebuiltins.snippets.sql

14.1 SqliteSQL - Sqlite SQL generator

15. morebuiltins.cmd.systemd.service

15.1 service_handler - Generate and manage systemd service files

16. morebuiltins.cmd.systemd.timer

16.1 timer_handler - Generate and manage systemd timer files

17. morebuiltins.sqlite

18. morebuiltins.shared_memory

18.1 PLock - A simple process lock using shared memory, for singleton control.

18.2 SharedBytes - Shared Memory for Python, for python 3.8+.

19. morebuiltins.logs

19.1 async_logger - Asynchronous non-blocking QueueListener that manages logger handlers.

19.2 AsyncQueueListener - Asynchronous non-blocking QueueListener that manages logger handlers.

19.3 LogHelper - Quickly bind a logging handler to a logger, with a StreamHandler or SizedTimedRotatingFileHandler.

19.4 RotatingFileWriter - RotatingFileWriter class for writing to a file with rotation support.

19.5 SizedTimedRotatingFileHandler - TimedRotatingFileHandler with maxSize, to avoid files that are too large.

19.6 ContextFilter - A logging filter that injects context variables into extra of log records. ContextVar is used to manage context-specific data in a thread-safe / async-safe manner.

19.7 LoggerStream - LoggerStream constructor.

cmd utils

  1. download_python
    1. python -m morebuiltins.download_python -a -k 3.11 -u
    2. -a will filt with current platform(x86_64+install_only), -k is the keywords, -u will unzip the tar.gz
  2. zipapps
    1. python -m morebuiltins.zipapps -h
    2. https://github.com/ClericPy/zipapps
  3. log_server
    1. python -m morebuiltins.cmd.log_server --log-dir=./logs
    2. client use the logging.handlers.SocketHandler (support python2/3)
    3. Update settings of rotation/formatter with extra: {"max_size": 1024**2, "formatter": logging.Formatter(fmt="%(asctime)s - %(filename)s - %(message)s")}

Metadata

Release files for morebuiltins 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for morebuiltins 1.4.1
File Size Uploaded Provenance Actions
morebuiltins-1.4.1.tar.gz 195.1 kB Without provenance Details for morebuiltins-1.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for morebuiltins 1.4.1
File Interpreter ABI Platform Actions
morebuiltins-1.4.1-py3-none-any.whl Python 3 none any Details for morebuiltins-1.4.1-py3-none-any.whl

Total release size: 354.6 kB

Release files / morebuiltins-1.4.1.tar.gz

Download URL morebuiltins-1.4.1.tar.gz
Size 195.1 kB
Tags Source
SHA-256 checksum
How to use checksums
940f3ba49f565cf820c3a3dcbd83a89ced5d4f5a7447f07909d3a26a00e2937b
BLAKE2b-256 checksum
How to use checksums
17e2418f6756aeace3992b382e46ef5ae1247d14596e8f985a4efb1b0bb0c551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.33.1

Release files / morebuiltins-1.4.1-py3-none-any.whl

Download URL morebuiltins-1.4.1-py3-none-any.whl
Size 159.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce8d7cd0f6435bfa11333ddf00f55c31b4658b05568ba8f7434be9d28cdfcf5c
BLAKE2b-256 checksum
How to use checksums
50bb99eaab7ea6f44e7c74ba616b699fe1e3c7138bdf48f3abcac93242632d82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.33.1

Security for morebuiltins 1.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page