Skip to main content

A collection of tools for developers

Project description

toolsed — Simple, Practical Utilities for Python

toolsed is a lightweight Python library that provides simple, reusable, and practical utility functions for everyday programming tasks. It’s designed to reduce boilerplate code and make common operations more readable and expressive.

No magic. No bloat. Just useful tools you'd write yourself — but already tested, documented, and ready to use.


🚀 Why toolsed?

In Python, you often write the same small helpers over and over:

  • Get the first item from a list (or return None if empty)
  • Safely access nested dictionaries
  • Flatten a list of lists
  • Truncate long strings
  • Handle optional values gracefully

toolsed collects these patterns into one clean, reliable package so you don’t have to reinvent the wheel.


📦 Installation

Install from PyPI:

pip install toolsed

Or install locally in development mode:

pip install -e .

🧰 Functions

Below is a full list of utilities provided by toolsed.


first(iterable, default=None)

Returns the first item from an iterable, or a default value if the iterable is empty.

Useful for safely getting values from lists, generators, or database queries.

Parameters:

  • iterable: Any iterable (list, tuple, generator, etc.)
  • default: Value to return if iterable is empty

Returns: First item or default

from toolsed import first

first([1, 2, 3])           # → 1
first([])                  # → None
first([], default="empty") # → "empty"
first(iter(range(10)))     # → 0

last(iterable, default=None)

Returns the last item from an iterable, or a default value if empty.

Parameters:

  • iterable: Any iterable
  • default: Value to return if empty or not iterable

Returns: Last item or default

from toolsed import last

last([1, 2, 3])            # → 3
last("hello")              # → 'o'
last([], default="end")    # → "end"
last(None, default="n/a")  # → "n/a"

noop(*args, **kwargs)

A no-operation function. Does nothing and returns None.

Useful as a default callback or placeholder.

from toolsed import noop

on_success = noop
on_success("Done!")  # → no effect

always(value)

Returns a function that always returns the given value, regardless of arguments.

Parameters:

  • value: The value to always return

Returns: A callable that returns value

from toolsed import always

get_default = always("unknown")
get_default()           # → "unknown"
get_default(1, 2, x=3)  # → "unknown"

is_iterable(obj)

Checks if an object is iterable, but excludes strings and bytes (which are iterable but often treated as scalars).

Returns: True if iterable and not a string/bytes

from toolsed import is_iterable

is_iterable([1, 2])     # → True
is_iterable("hello")    # → False
is_iterable((1, 2))     # → True
is_iterable(42)         # → False

flatten(nested_list)

Flattens a list of lists into a single-level list. Only flattens one level deep.

Returns: Flat list

from toolsed import flatten

flatten([[1, 2], [3], 4])  # → [1, 2, 3, 4]
flatten([1, 2, 3])         # → [1, 2, 3]
flatten([[1, 2], [3, [4]]]) # → [1, 2, 3, [4]] (only one level)

ensure_list(obj)

Ensures the input is a list. Wraps scalars in a list, converts tuples, returns [] for None.

Returns: A list

from toolsed import ensure_list

ensure_list(1)        # → [1]
ensure_list([1, 2])   # → [1, 2]
ensure_list(None)     # → []
ensure_list("text")   # → ["text"]

compact(iterable)

Removes "falsy" values (None, False, 0, "", [], {}) from an iterable.

Returns: List without falsy values

from toolsed import compact

compact([0, 1, "", "a", None, [], [1], False, True])  # → [1, "a", [1], True]

chunks(iterable, n)

Splits an iterable into chunks of size n.

Useful for batching data (e.g., API calls).

Yields: Lists of size n (last chunk may be smaller)

from toolsed import chunks

list(chunks(range(7), 3))  # → [[0,1,2], [3,4,5], [6]]

safe_get(d, *keys, default=None)

Safely retrieves a value from a nested dictionary. Returns default if any key is missing.

Parameters:

  • d: Dictionary (or any object)
  • *keys: Chain of keys
  • default: Value to return on failure

Returns: Value or default

from toolsed import safe_get

data = {"user": {"profile": {"name": "Alice"}}}
safe_get(data, "user", "profile", "name")           # → "Alice"
safe_get(data, "user", "email", default="no@ex.com") # → "no@ex.com"
safe_get(data, "admin", "level", default=0)         # → 0

dict_merge(*dicts)

Merges multiple dictionaries. Later dicts override earlier ones.

Returns: New merged dict

from toolsed import dict_merge

a = {"x": 1, "y": 2}
b = {"y": 99, "z": 3}
merged = dict_merge(a, b)  # → {"x": 1, "y": 99, "z": 3}

truncate(text, length, suffix="...")

Truncates a string to a given length, appending a suffix if needed.

If the suffix is longer than length, returns the first length characters of the text.

Returns: Truncated string

from toolsed import truncate

truncate("Hello world", 8)     # → "Hello..."
truncate("Short", 10)          # → "Short"
truncate("Hi", 1)              # → "H"
truncate("Test", 4, "..")      # → "Te.."

pluralize(count, singular, plural=None)

Returns a string like "1 file", "2 files", etc.

If plural is not provided, adds "s" to singular.

Returns: Formatted string with correct pluralization

from toolsed import pluralize

pluralize(1, "file")           # → "1 file"
pluralize(2, "file")           # → "2 files"
pluralize(5, "яблоко", "яблок") # → "5 яблок"

🧪 Testing

Run tests with:

pytest

All functions are tested and safe for production use.


🛠️ Development

To contribute or extend:

  1. Fork the repo
  2. Install in dev mode: pip install -e .
  3. Add tests in tests/
  4. Submit a PR

📄 License

MIT License. See LICENSE for details.


toolsed — because you shouldn't have to write the same helpers twice.

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

toolsed-0.1.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

toolsed-0.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file toolsed-0.1.1.tar.gz.

File metadata

  • Download URL: toolsed-0.1.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.2

File hashes

Hashes for toolsed-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5aba7db43ba15a34d3f4b337bf959b4cbf852c22cfcf98fe65acc25661074441
MD5 5bc62562abe2edaf7697578b7576c9a3
BLAKE2b-256 0524d73b50842193583689ede6d2f39623ca072987946133b76d87fb4fbded84

See more details on using hashes here.

File details

Details for the file toolsed-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: toolsed-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.2

File hashes

Hashes for toolsed-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e32573ee15f73900b2e49a905e665c52b2964bd4ee8d2f917b059f31ac3c1de
MD5 2e3016e9bf0bf169f90989d6a65d4235
BLAKE2b-256 02ba13497a16b5d08da01ea1d3b06b515017e32b519019e97f7bb4aa3f71547e

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