Skip to main content

package for map a list

Project description

Easy Map Reduce for a list python:

Docs
Ray
Dask
Asyncio
PyArrow
Pipeline
Coverage

Description

This library was created to allow us to use functional style in a list object in python. It is easier to use functional style when we have for example to deal with a several transformation in our data.

In this little library, we can find most of the function used in a list object but with map or reduce or flatten,... methods. If you are familiar with spark rdd, the behavior of all the methods created in ListMapper object is mostly the same. The difference is that it includes some properties of a python list.

News

Now a doc-string was added to this package, so you can use it and have some example of how to use a method in the object created with ListMapper

Issues:

This Library work only with python version >=3.6. If you attempt to use it with an anterior version, there will be an error occurred in some methods.

How to use this package:

First install this package with pip by doing:

pip install functional-list

Then, you can import ListMapper to create an object:

from functional_list import ListMapper

Example:

Let's make the famous word count with this package. Suppose one have a list of a document comes from a text file, and we load it in a simple list

document =[
            "python is good",
            "python is better than x",
            "python is the best",
            ]

## Now, let tranform the list to a list mapper 
document = ListMapper[str](*document)

res = document.flat_map(lambda x:x.split())\
              .map(lambda x:(x,1))\
              .reduce_by_key(lambda x,y:x+y)

## result will be:
#List[('than', 1), ('the', 1), ('best', 1),
#        ('better', 1), ('good', 1), ('is', 3), 
#        ('python', 3), ('x', 1)]
# And you have your word count :)

The ListMapper object has also the same behavior as a standard python list.

my_list = ListMapper[int](2, 4, 9, 13, 15, 20)
## Append element 
my_list.append(55)
## will give List[2, 4, 9, 13, 15, 20, 55]
## Let make some ordianry transformation
my_list.map(lambda x: x*x)\
       .filter(lambda x:x%2==0)\
       .reduce(lambda x,y:x+y)

# Give as a result 420

I/O Operations

ListMapper now supports reading data directly from various file formats:

Supported Formats

  • CSV - Comma-separated values files
  • JSON - JSON files (arrays or single objects)
  • JSONL - JSON Lines format (one JSON object per line)
  • Parquet - Parquet files (requires pyarrow)
  • Text - Plain text files (one line per element)

Quick Examples

from functional_list import ListMapper
from functional_list.io import CSVReadOptions, TextReadOptions

# Read CSV and process
users = (
    ListMapper.from_csv(
        "users.csv",
        options=CSVReadOptions(skip_header=True),
        transform=lambda row: {"name": row[0], "age": int(row[1])},
    )
    .filter(lambda user: user["age"] >= 18)
)

# Read JSON and transform
names = ListMapper.from_json("data.json").map(lambda x: x["name"])

# Read text file
lines = ListMapper.from_text(
    "log.txt",
    options=TextReadOptions(strip_lines=True, skip_empty=True),
)

# Read Parquet with specific columns
rows = ListMapper.from_parquet("data.parquet", columns=["name", "age"])

# Read JSONL (JSON Lines)
events = ListMapper.from_jsonl("events.jsonl")

Installation for Parquet Support

# For Parquet support:
uv add pyarrow
# or
pip install pyarrow

For more details, see the MkDocs documentation in documentation/.

Documentation (MkDocs)

La documentation MkDocs est disponible dans le dossier documentation/.

Pour la lancer en local:

uv sync
mkdocs serve -f documentation/mkdocs.yml

Pour builder le site:

mkdocs build -f documentation/mkdocs.yml

Deploy documentation (GitLab CI → Netlify)

This repository includes a GitLab CI pipeline that builds MkDocs from documentation/mkdocs.yml and deploys the generated static site to Netlify.

See: documentation/NETLIFY_GITLAB.md

Getting Help

If you want to get the list of the method in this object, you just have to do the next command in python:

dir(ListMapper)

To get the doc-string of a method:

print(my_list.map.__doc__)

In each, method, there is an example of how to use the method.

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

functional_list-0.2.0.tar.gz (23.3 kB view details)

Uploaded Source

Built Distributions

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

functional_list-0.2.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (272.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

functional_list-0.2.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (259.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

functional_list-0.2.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (244.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

File details

Details for the file functional_list-0.2.0.tar.gz.

File metadata

  • Download URL: functional_list-0.2.0.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for functional_list-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ddd95542b45d68741a7c012efd3bd1bf8e4bf5a131a142962f1d9e072afb2f47
MD5 3a3a7bd29c8ab3e480899753d687d59d
BLAKE2b-256 b7fe1f4dfe6484a68d5741359f654744fc61cfd944f7a4dfed2bed01eb73c14c

See more details on using hashes here.

File details

Details for the file functional_list-0.2.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

  • Download URL: functional_list-0.2.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
  • Upload date:
  • Size: 272.8 kB
  • Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for functional_list-0.2.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 1a1ec6b05af683d1d10596d32c3040b7e506630a18abbbbe13e74a555a99d6ee
MD5 15adc8b15e05d1c8e7633bbe69442df5
BLAKE2b-256 8b7d2823a842f140c8eee79bd0d2429787a7c68754eedbf68e51f651fdaa717f

See more details on using hashes here.

File details

Details for the file functional_list-0.2.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

  • Download URL: functional_list-0.2.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
  • Upload date:
  • Size: 259.1 kB
  • Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for functional_list-0.2.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 9185fba18cccbd233053af0a4022c8be529223de2e00a4f14c775323c6fee71f
MD5 040df2f7caa29ec30823b12188de2baf
BLAKE2b-256 6995eb033b2a6cc204204732083b0cd638ffcb3e6851c62b1e5f2cf4bea42eee

See more details on using hashes here.

File details

Details for the file functional_list-0.2.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

  • Download URL: functional_list-0.2.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
  • Upload date:
  • Size: 244.3 kB
  • Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for functional_list-0.2.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 c6e5bf8dcb302d08370c6f2362b402cf0fcb88f48d66b0785a163487d8d9a2a4
MD5 b15770197db25bbdc7242895a5c28c9d
BLAKE2b-256 9eebbd5c3293bca1a9455cd0836c0f19976556e8be7f2b506cd78e61b0059b76

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