An open API service indexing awesome lists of open source software.

https://github.com/xpinked/memiter

memiter is a Python library that enhances the functionality of generators, making pagination and data access simpler and more intuitive.
https://github.com/xpinked/memiter

generator generator-python generators iterator iterators pagination python python3 software

Last synced: about 1 month ago
JSON representation

memiter is a Python library that enhances the functionality of generators, making pagination and data access simpler and more intuitive.

Awesome Lists containing this project

README

          

# memiter

`memiter` is a Python library that enhances the functionality of generators, making pagination and data access simpler and more intuitive.

It allows users to limit the number of elements generated, set the current page for pagination, and access the data that has been generated as many times as needed.

Additionally, it keeps the original generator, allowing the data to be generated again in a different configuration.

## Features

- **Pagination**: Easily paginate through large datasets by setting limits and pages.
- **Data Access**: Access the generated data multiple times without re-running the generator.
- **Flexibility**: Keep the original generator for re-generation of data with different parameters.

## Installation

Requirements:

- Python 3.8+

To install `memiter`, simply use pip:

```bash
pip install memiter
```

# Quick Start

Here's a quick example to get you started:

```python
from memiter import memiter

# Create a memiter instance from a range generator
my_gen = memiter(range(100)).limit(5).page(2)

# Generate and access the data
print(list(my_gen))
# Output: [5, 6, 7, 8, 9]

# Access the data that has been generated
print(my_gen.data)
# Output: [5, 6, 7, 8, 9]
```

# Usage

## Creating a Memiter Instance

You can create a memiter instance from any iterable:

```python
from memiter import memiter

my_gen = memiter(range(100))
```

Hurray! Your memiter instance is now ready to be used!

By default, the memiter instance will generate all the data from the original generator.

But if you want your can enhance the functionality of your generator by using the following methods:

## Pagination

Limit the number of elements and set the current page:

- limit - Set the number of elements to generate.
- page - Set the current page for pagination.

```python
my_gen.limit(5).page(2)
```

## Iterating Over Data

like any other generator, you can iterate over the data generated by the memiter instance:

```python

for data in my_gen:
print(data)

```

## Accessing Data

memiter allows you to access the data that has been generated multiple times without re-running the generator.

You can access the data that has been generated using the data attribute:

```python
print(my_gen.data)
```

## License

memiter is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.