Skip to main content

Easy Python functions making making functional Python functions easier.

Project description

hunterMakesPy

A modular Python toolkit for defensive programming, parameter validation, file system utilities, and flexible data structure manipulation.

pip install hunterMakesPy

Overview

hunterMakesPy provides utilities for safe error handling, flexible input validation, dynamic module and attribute importing, and merging or transforming complex data structures. The package emphasizes clear identifiers, robust type handling, and reusable components for building reliable Python applications.

Installation

pip install hunterMakesPy

Defensive Programming

Utilities for handling None values and defensive programming patterns.

from hunterMakesPy import raiseIfNone

# Ensure a function result is not None
def findConfiguration(configName: str) -> dict[str, str] | None:
    # ... search logic ...
    return None

config = raiseIfNone(
    findConfiguration("database"),
    "I could not find Configuration 'database', but I need it to continue."
)

Parameter Validation

Parameter validation, integer parsing, and concurrency handling.

import hunterMakesPy as humpy

# Smart concurrency limit calculation
cpuLimit = humpy.defineConcurrencyLimit(limit=0.75)  # Use 75% of available CPUs
cpuLimit = humpy.defineConcurrencyLimit(limit=True)  # Use exactly 1 CPU
cpuLimit = humpy.defineConcurrencyLimit(limit=4)     # Use exactly 4 CPUs

# Robust integer validation
validatedIntegers = humpy.intInnit([1, "2", 3.0, "4"], "port_numbers")

# String-to-boolean conversion for configuration
userInput = "True"
booleanValue = humpy.oopsieKwargsie(userInput)  # Returns True

File System Utilities

Safe file operations and dynamic module importing.

import hunterMakesPy as humpy

# Dynamic imports
gcdFunction = humpy.importLogicalPath2Identifier("math", "gcd")
customFunction = humpy.importPathFilename2Identifier("path/to/module.py", "functionName")

# Safe file operations
pathFilename = Path("deep/nested/directory/file.txt")
humpy.writeStringToHere("content", pathFilename)  # Creates directories automatically

Data Structure Manipulation

Utilities for string extraction, data flattening, and array compression.

import hunterMakesPy as humpy
import numpy

# Extract all strings from nested data structures
nestedData = {"config": [1, "host", {"port": 8080}], "users": ["alice", "bob"]}
allStrings = humpy.stringItUp(nestedData)  # ['config', 'host', 'port', 'users', 'alice', 'bob']

# Merge dictionaries containing lists
dictionaryAlpha = {"servers": ["chicago", "tokyo"], "databases": ["elm"]}
dictionaryBeta = {"servers": ["mumbai"], "databases": ["oak", "cedar"]}
merged = humpy.updateExtendPolishDictionaryLists(dictionaryAlpha, dictionaryBeta, destroyDuplicates=True)

# Compress NumPy arrays with run-length encoding
arrayData = numpy.array([1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9])
compressed = humpy.autoDecodingRLE(arrayData)  # "[1,*range(2,6)]+[5]*2+[*range(6,10)]"

Testing

The package includes comprehensive test suites that you can import and run:

from hunterMakesPy.tests.test_parseParameters import (
    PytestFor_defineConcurrencyLimit,
    PytestFor_intInnit,
    PytestFor_oopsieKwargsie
)

# Run tests on the built-in functions
listOfTests = PytestFor_defineConcurrencyLimit()
for nameOfTest, callablePytest in listOfTests:
    callablePytest()

# Or test your own compatible functions
@pytest.mark.parametrize(
  "nameOfTest,callablePytest"
  , PytestFor_intInnit(callableToTest=myFunction))
def test_myFunction(nameOfTest, callablePytest):
    callablePytest()

My recovery

Static Badge YouTube Channel Subscribers

How to code

Coding One Step at a Time:

  1. WRITE CODE.
  2. Don't write stupid code that's hard to revise.
  3. Write good code.
  4. When revising, write better code.

CC-BY-NC-4.0

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

huntermakespy-0.2.2.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

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

huntermakespy-0.2.2-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

Details for the file huntermakespy-0.2.2.tar.gz.

File metadata

  • Download URL: huntermakespy-0.2.2.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for huntermakespy-0.2.2.tar.gz
Algorithm Hash digest
SHA256 a3bf8b0f92ba3df8a65de5b5953218e9f53fd5754c893967a0bdd1bfbc852dce
MD5 d9b457e65691401b9cdd8a9fa0b872fe
BLAKE2b-256 0ab5712c0d0fef839ab9d796d74f86f142ab09f0c6abba7b57715e24bbeb7552

See more details on using hashes here.

Provenance

The following attestation bundles were made for huntermakespy-0.2.2.tar.gz:

Publisher: pypiRelease.yml on hunterhogan/hunterMakesPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file huntermakespy-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: huntermakespy-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 38.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for huntermakespy-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c28368a2ed76a86c45c1ac8a979967fa5e72545aa8e6cae6c0cf6f9ac17c0e0
MD5 84dbb798e40d1237e0bc88679074eb69
BLAKE2b-256 1b75403ecdbac047afa97ccd2f834843fcbba4273d2d5ab42264e2ce2107cda7

See more details on using hashes here.

Provenance

The following attestation bundles were made for huntermakespy-0.2.2-py3-none-any.whl:

Publisher: pypiRelease.yml on hunterhogan/hunterMakesPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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