or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

arrays.mdchaining.mdcollections.mdfunctions.mdindex.mdnumerical.mdobjects.mdpredicates.mdstrings.mdutilities.md
tile.json

tessl/pypi-pydash

A comprehensive Python utility library for functional programming inspired by JavaScript's Lo-Dash

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pydash@8.0.x

To install, run

npx @tessl/cli install tessl/pypi-pydash@8.0.0

index.mddocs/

PyDash - Python Utility Library

PyDash is a comprehensive Python port of Lo-Dash (Lodash) that provides functional programming helpers and utilities for Python. It offers a complete suite of 365 functions for manipulating arrays, objects, collections, strings, and more, following functional programming paradigms.

Package Information

  • Package Name: pydash
  • Package Type: pypi
  • Language: Python
  • Installation: pip install pydash
  • Version: 8.0.5
  • Total Functions: 365 public functions across 8 main modules
  • Type Hints: Full type annotation support throughout
  • Python Compatibility: Modern Python with comprehensive type checking

Installation

pip install pydash

Core Imports

Functional Style Import

import pydash as _

# Use functions directly
result = _.chunk([1, 2, 3, 4, 5], 2)
# [[1, 2], [3, 4], [5]]

Selective Imports

from pydash import chunk, compact, map_, filter_
from pydash import get, set_, has
from pydash import camel_case, kebab_case

Chaining Style Import

from pydash import chain, _

# Method chaining
result = _([1, 2, 3, 4, 5, 6]).filter(lambda x: x % 2 == 0).map(lambda x: x * 2).value()
# [4, 8, 12]

# Or using chain() function
result = chain([1, 2, 3, 4, 5, 6]).filter(lambda x: x % 2 == 0).map(lambda x: x * 2).value()

Direct Module Imports

from pydash.arrays import flatten, uniq
from pydash.objects import get, merge
from pydash.strings import snake_case, title_case
from pydash.collections import group_by, sort_by

Basic Usage Examples

Array Manipulation

import pydash as _

# Group arrays into chunks
_.chunk([1, 2, 3, 4, 5, 6], 3)
# [[1, 2, 3], [4, 5, 6]]

# Remove falsey values
_.compact([0, 1, False, 2, '', 3, None])
# [1, 2, 3]

# Find unique values
_.uniq([1, 2, 1, 3, 2, 4])
# [1, 2, 3, 4]

# Flatten nested arrays
_.flatten_deep([1, [2, [3, [4]]]])
# [1, 2, 3, 4]

Object Operations

import pydash as _

user = {
    'name': {'first': 'John', 'last': 'Doe'},
    'age': 30,
    'active': True
}

# Safe property access
_.get(user, 'name.first')  # 'John'
_.get(user, 'name.middle', 'N/A')  # 'N/A'

# Set nested properties
_.set_(user, 'address.city', 'New York')

# Pick specific properties
_.pick(user, 'name', 'age')
# {'name': {'first': 'John', 'last': 'Doe'}, 'age': 30}

Collection Processing

import pydash as _

users = [
    {'name': 'John', 'age': 30, 'active': True},
    {'name': 'Jane', 'age': 25, 'active': False},
    {'name': 'Bob', 'age': 35, 'active': True}
]

# Filter collections
active_users = _.filter_(users, {'active': True})

# Map over collections
names = _.map_(users, 'name')  # ['John', 'Jane', 'Bob']

# Group by property
by_active = _.group_by(users, 'active')
# {True: [{'name': 'John', ...}, {'name': 'Bob', ...}], False: [{'name': 'Jane', ...}]}

# Sort by property
sorted_users = _.sort_by(users, 'age')

String Transformations

import pydash as _

# Case conversions
_.camel_case('hello world')      # 'helloWorld'
_.snake_case('helloWorld')       # 'hello_world'  
_.kebab_case('Hello World')      # 'hello-world'
_.title_case('hello world')      # 'Hello World'

# String utilities
_.pad('abc', 8)                  # '  abc   '
_.trim('  hello  ')             # 'hello'
_.truncate('This is a long string', 10)  # 'This is...'

Architecture: Chaining System

PyDash supports both functional and chaining programming styles:

Functional Style

Execute operations directly on data:

import pydash as _

result = _.map_(_.filter_([1, 2, 3, 4, 5], lambda x: x % 2 == 0), lambda x: x * 2)
# [4, 8]

Chaining Style

Chain operations for better readability:

from pydash import _

result = _([1, 2, 3, 4, 5]).filter(lambda x: x % 2 == 0).map(lambda x: x * 2).value()
# [4, 8]

# Complex chaining example
result = _(users)\
    .filter({'active': True})\
    .sort_by('age')\
    .map('name')\
    .take(2)\
    .value()

Debugging with Tap

from pydash import _

result = _(data)\
    .filter(predicate)\
    .tap(print)  # Debug intermediate results\
    .map(transform)\
    .value()

Module Capabilities

Arrays - 75 Functions

Functions for array/list manipulation and transformation.

import pydash as _

# Core array operations
_.chunk([1, 2, 3, 4, 5], 2)              # Group into chunks
_.flatten([[1, 2], [3, 4]])              # Flatten arrays  
_.uniq([1, 2, 1, 3, 2])                  # Remove duplicates
_.difference([1, 2, 3], [2, 3, 4])       # Array differences

# Array transformations
_.zip_([1, 2], ['a', 'b'])               # Zip arrays: [(1, 'a'), (2, 'b')]
_.from_pairs([['a', 1], ['b', 2]])       # Create dict from pairs

Collections - 33 Functions

Functions that work on both arrays and objects.

import pydash as _

# Collection processing
_.map_([1, 2, 3], lambda x: x * 2)       # Transform elements
_.filter_([1, 2, 3, 4], lambda x: x % 2 == 0)  # Filter elements
_.reduce_([1, 2, 3, 4], lambda acc, x: acc + x)  # Reduce to single value

# Collection grouping
_.group_by(['one', 'two', 'three'], len)  # Group by length
_.count_by(['A', 'B', 'A', 'C'], _.identity)  # Count occurrences

Objects - 49 Functions

Functions for object/dictionary manipulation.

import pydash as _

obj = {'a': {'b': {'c': 42}}}

# Property access
_.get(obj, 'a.b.c')                      # Safe nested access: 42
_.has(obj, 'a.b')                        # Check property exists: True
_.set_(obj, 'a.b.d', 100)               # Set nested property

# Object transformation
_.keys({'a': 1, 'b': 2})                # Get keys: ['a', 'b']
_.values({'a': 1, 'b': 2})              # Get values: [1, 2]  
_.merge({'a': 1}, {'b': 2})             # Merge objects: {'a': 1, 'b': 2}

Strings - 69 Functions

Comprehensive string manipulation and formatting.

import pydash as _

# Case transformations  
_.camel_case('foo bar')                  # 'fooBar'
_.snake_case('fooBar')                   # 'foo_bar'
_.kebab_case('Foo Bar')                  # 'foo-bar'
_.title_case('foo bar')                  # 'Foo Bar'

# String utilities
_.pad('abc', 8)                          # '  abc   '
_.truncate('A long string', 10)          # 'A long...'
_.words('Hello world!')                  # ['Hello', 'world']

Numerical - 28 Functions

Mathematical operations and statistical functions.

import pydash as _

# Basic math
_.add(6, 4)                              # 10
_.multiply(3, 4)                         # 12  
_.clamp(10, 1, 5)                        # 5

# Statistics
_.mean([1, 2, 3, 4, 5])                  # 3.0
_.sum_([1, 2, 3, 4, 5])                  # 15
_.max_([1, 5, 3, 9, 2])                  # 9

Functions - 30 Functions

Higher-order functions and function utilities.

import pydash as _

# Function composition
add_one = lambda x: x + 1
multiply_two = lambda x: x * 2
composed = _.flow(add_one, multiply_two)
composed(3)                              # 8

# Function control
debounced = _.debounce(expensive_func, 100)  # Debounce calls
throttled = _.throttle(api_call, 1000)       # Throttle calls
once_only = _.once(initialization)           # Call only once

Predicates - 59 Functions

Type checking and value testing functions.

import pydash as _

# Type checking
_.is_string('hello')                     # True
_.is_number(42)                          # True
_.is_empty([])                           # True
_.is_equal({'a': 1}, {'a': 1})          # True

# Value comparison  
_.gt(3, 1)                               # True
_.in_range(3, 2, 6)                      # True
_.is_match({'a': 1, 'b': 2}, {'a': 1})  # True

Utilities - 38 Functions

General utility functions and helpers.

import pydash as _

# Function creation
always_true = _.constant(True)           # Function that always returns True
get_name = _.property_('name')           # Function to get 'name' property
is_adult = _.matches({'age': lambda x: x >= 18})  # Matching function

# Utilities
_.random(1, 10)                          # Random number between 1-10
_.times(3, lambda i: i * 2)              # [0, 2, 4]
_.unique_id('user_')                     # 'user_1', 'user_2', etc.

Chaining - Method Chaining

Fluent interface for composing operations.

from pydash import _, chain

# Chain multiple operations
result = _([1, 2, 3, 4, 5, 6])\
    .filter(lambda x: x % 2 == 0)\
    .map(lambda x: x ** 2)\
    .sum_()\
    .value()  # 56

# Complex data processing  
processed = _(raw_data)\
    .filter({'active': True})\
    .group_by('department')\
    .map_values(lambda group: _.sum_by(group, 'salary'))\
    .value()

Key Features

Flexible Iteratees

Many functions accept flexible iteratee arguments:

users = [{'name': 'John', 'age': 30}, {'name': 'Jane', 'age': 25}]

# Function iteratee
_.map_(users, lambda u: u['name'])       # ['John', 'Jane']

# String property iteratee  
_.map_(users, 'name')                    # ['John', 'Jane']

# Dict matcher iteratee
_.filter_(users, {'age': 30})            # [{'name': 'John', 'age': 30}]

Safe Operations

Built-in error handling for common operations:

import pydash as _

# Safe property access - no KeyError
_.get({'a': 1}, 'b.c.d', 'default')     # 'default'

# Safe function application  
_.attempt(risky_function, arg1, arg2)    # Returns result or exception

Type Safety

Comprehensive type hints for better development experience:

from pydash import chunk, get
from typing import List, Any

# Full type support
chunks: List[List[int]] = chunk([1, 2, 3, 4], 2)
value: Any = get({'a': {'b': 1}}, 'a.b')

This documentation covers all 365 functions across PyDash's 8 main modules. Each module page provides detailed API documentation with parameters, return types, and usage examples for every function.