Skip to main content

A simple python framework for building data processing pipelines

Project description

Pypeliner

pypeliner is a simple python framework for building data processing pipelines.

you can check out the documentation here.

and checkout some examples here.

Installation

it can be simply installing using pip:

pip install simple-pypeliner

Getting Started

Let's say we want to build a pipeline for processing textual data coming from a file. we will need 3 main components to achieve this using pypeliner.

Reader

first we will need a reader for reading the file, and it can be defined like the following:

from pypeliner.readers.base import BaseReader

class FileReader(BaseReader):
    def __init__(self, file_path: str) -> None:
        self.file_path = file_path

    def read(self) -> str:
        with open(self.file_path, "r") as file_handler:
            return file_handler.read()

inheriting from BaseReader makes sure that the read method is implemented to be used later within the Reader. the code basically is reading a file and returning its content as a string.

Processors

next we will define our processing logic, lets say we want to make all letters in the text file lower case, then remove stop words i.g: but, and, or, etc after that remove numbers.

to achieve that we will write a processor for each one of these tasks.

each processor should define its own process method. a processor will receive the state it needs to process from the Runner.

if input_state is passed the that processor will use the input_state instead of the state passed by the runner, this is achieved using the super call for process method and passing input_state there. it is recommended to always call super for the process method as a best practice.

PROCESSOR_NAME is a verbose name for a processor.

1- Lower Case Processor

class LowerCaseProcessor(BaseProcessor):
    PROCESSOR_NAME = "Lower Case Processor"

    def process(self, input_state: Any = None) -> Any:
        self.state = super().process(input_state)
        return self.state.lower()

2- Remove Stop Words Processor

class RemoveStopWordsProcessor(BaseProcessor):
    PROCESSOR_NAME = "Remove Stop Words Processor"

    def process(self, input_state: Any = None) -> Any:
        self.state = super().process(input_state)
        stop_words = [
            "the", "to", "and", "a",
            "in", "it", "is", "am,
            "I", "that", "had", "on",
            "for", "be", "were", "was",
            "of", "or", "it", "an",
        ]
        self.state = super().process(input_state)

        for stop_word in stop_words:
            self.state = re.sub(rf"\W+{stop_word}\W+", " ", self.state)
            self.state = re.sub(rf"\W+{stop_word.title()}\W+", " ", self.state)

        return self.state

3- Remove Numbers Processor

class RemoveNumbersProcessor(BaseProcessor):
    PROCESSOR_NAME = "Remove Numbers Processor"

    def process(self, input_state: Any = None) -> Any:
        self.state = super().process(input_state)
        return re.sub(r"\d+", "", self.state)

Runner

the runner is the place where everything comes together, it will use the Reader to load the file and define the running loop for the Processor

we'll be using the built in BaseRunner

from runners.base import BaseRunner

runner = BaseRunner(
    processors=[
        LowerCaseProcessor(),
        RemoveStopWordsProcessor(),
        RemoveNumbersProcessor(),
    ],
    reader=FileReader(
        file_path="test.txt"
    ),
    verbose=True,
    run_timers=True
)

print(runner.run())

processors parameter will set the processors of the pipeline and also its order.

reader parameter will set the reader of the pipeline to be the file reader we defined earlier.

verbose parameter will print the current processor that is running.

run_timers parameter will print the time consumed by each processor to run.

for more information visit the documentation at pypeliner

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

simple-pypeliner-0.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distributions

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

simple_pypeliner-0.0.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

simple_pypeliner-0.0.1-1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file simple-pypeliner-0.0.1.tar.gz.

File metadata

  • Download URL: simple-pypeliner-0.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for simple-pypeliner-0.0.1.tar.gz
Algorithm Hash digest
SHA256 edcdf3b26a372cc5c8a2d15c3f8963e4429c57365dfa87566750b2266b0ffb8b
MD5 c58a645134cbd066f2549e068eba45d3
BLAKE2b-256 408bd37ef75b70d16bee43bd748cd4daaed2208f58dd794009ba53b817cc4552

See more details on using hashes here.

File details

Details for the file simple_pypeliner-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_pypeliner-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9be8fc04c1b3409dc9885186f0a7dfe9999d6a08d54f0085d0012ff892a3b2fc
MD5 e1c9c4903a69165d8f5680c41592ec02
BLAKE2b-256 c94e3de296790ccfcf1b6e6d43e5d0e414ff11bac7195ce3a4ea9b8d0a31c94b

See more details on using hashes here.

File details

Details for the file simple_pypeliner-0.0.1-1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_pypeliner-0.0.1-1-py3-none-any.whl
Algorithm Hash digest
SHA256 7824aa18dd5c851e27f8549264133211a983bfbe10b492d060b2f0b5835b46f4
MD5 0e4c72fb647d1a84496a724ea8040ce6
BLAKE2b-256 a6154f00384863a2bad602d9116f42f2bed05844923e8fca55af2dd57042f040

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