PitchHut
Log in / Sign up
Leopards
22 views
Effortlessly query your Python lists like a database.
Pitch

Leopards is a powerful tool that enables you to query lists of dictionaries or objects using familiar DBMS-style filtering. With support for various conditions and fast performance, it's an ideal alternative to Pandas for list operations. Simplify your data handling and enhance your Python projects.

Description

Leopards is an innovative library that allows you to query lists of dictionaries or objects with the efficiency and simplicity of a database management system (DBMS). Whether you're filtering data with logical operators like OR, AND, or NOT, Leopards provides a swift and intuitive interface that outperforms traditional libraries such as Pandas.

Fast and Flexible Data Queries

Utilizing Leopards means you can apply complex filtering criteria on your datasets, retrieving precisely what you need without the overhead common to heavier frameworks. Below is a concise example of how you can use it:

from leopards import Q

# Sample data
l = [{"name":"John","age":"16"}, {"name":"Mike","age":"19"},{"name":"Sarah","age":"21"}]

# Filter data using Leopards
filtered = Q(l, {'name__contains': "k", "age__lt": 20})
print(list(filtered))  # Output: [{'name': 'Mike', 'age': '19'}]

With support for various filters like _eq, _gt, _lt, and more, Leopards allows for extensive customizations and logical operations.

Supported Filters Include:

  • eq: Equals (default filter).
  • gt: Greater than.
  • gte: Greater than or equal.
  • lt: Less than.
  • lte: Less than or equal.
  • in: Check if a value is within a list.
  • contains: Case-sensitive substring check.
  • icontains: Case-insensitive substring check.
  • startswith / istartswith: Check beginnings of strings.
  • endswith / iendswith: Check endings of strings.
  • isnull: Check for null-like values.

With the ability to negate filters (nin, equivalent to not in) and apply sophisticated logical constructs like OR, AND, and NOT, you gain unparalleled control over your data querying processes.

Powerful Aggregation Capabilities

Leopards isn't just limited to querying; it also offers robust aggregation features, allowing you to summarize your data effectively. You can compute:

  • Count of unique values.
  • Max and Min values in specified columns.
  • Sum and Avg calculations for numerical datasets.

To demonstrate:

from leopards import Count

# Sample data
l = [{"name": "John", "age": "16"}, {"name": "Mike", "age": "19"}, {"name": "Sarah", "age": "21"},{"name":"John","age":"19"}]

# Count occurrences in dataset
count = Count(l, ['age'])
print(count)  # Output: [{"age":"16","count":1},{"age":"19","count":2},{"age":"21","count":1}]

Speed Comparison with Pandas

Leopards stands out in performance, especially when handling large datasets. A direct comparison with Pandas demonstrates significant advantages:

ComparisonPandasLeopards
Package Size29.8 MB7.5 KB
Import Time (Worst)146 ms1.05 ms
Load 10k CSV lines0.295s0.138s
Get first matched record0.310s0.017s
Print all filtered records (10/10k)0.310s0.137s
Filter by integers0.316s0.138s

With Leopards, you can load data on-the-fly, as it can work with iterables like DictReader, resulting in remarkable efficiency.

Further Learning

Explore more about leveraging Leopards for your data management needs and check out our tutorial: Work on CSV Files with Leopards.

Embrace the agility of Leopards to streamline your Python data querying efforts today!