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.
- 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.
Requirements:
- Python 3.8+
To install memiter
, simply use pip:
pip install memiter
Here's a quick example to get you started:
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]
You can create a memiter instance from any iterable:
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:
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.
my_gen.limit(5).page(2)
like any other generator, you can iterate over the data generated by the memiter instance:
for data in my_gen:
print(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:
print(my_gen.data)
memiter is licensed under the MIT License - see the LICENSE file for details.