# Best practice for applying pipelines to many datasets?

**URL:** <https://discuss.dvc.org/t/best-practice-for-applying-pipelines-to-many-datasets/1147>\
**Category:** Questions\
**Created:** [April 6, 2022, 3:20pm UTC](https://discuss.dvc.org/t/best-practice-for-applying-pipelines-to-many-datasets/1147 "2022-04-06T15:20:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve.richardson](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@steve.richardson](https://discuss.dvc.org/u/steve.richardson)\
**Post date:** [April 6, 2022, 3:20pm UTC](https://discuss.dvc.org/t/best-practice-for-applying-pipelines-to-many-datasets/1147/1 "2022-04-06T15:20:14Z")

</div>

Hi folks,

I have a data analysis problem which I want to use DVC to help me with. I have a series of many different datasets which each need to have an analysis stage applied to them. Each dataset is a folder with a specific set of (large) files, and the same python analysis code needs to be applied to each one.

Rather than just run one monolithic script that loops over all the datasets, I would like to create a pipeline to help me handle this. I am imagining some sort of pipeline where the script gets applied to each dataset separately (and possibly in parallel).

Is something like this even possible with dvc?

Thanks,

Steve

---

<div class="post-metadata">

**Author:** ![steve.richardson](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@steve.richardson](https://discuss.dvc.org/u/steve.richardson)\
**Post date:** [April 6, 2022, 3:48pm UTC](https://discuss.dvc.org/t/best-practice-for-applying-pipelines-to-many-datasets/1147/2 "2022-04-06T15:48:14Z")

</div>

Actually, I just found out about “foreach” stages in the documentation:

> **[Pipelines Files (dvc.yaml)](https://dvc.org/doc/user-guide/project-structure/pipelines-files?msclkid=6aa0e6cdb5c011ec8141cc26dddd4c38#foreach-stages)**
>
> Open-source version control system for Data Science and Machine Learning projects. Git-like experience to organize your data, models, and experiments.

I am pretty sure that I can use this to solve my problem.

Thanks!

---

<div class="post-metadata">

**Author:** ![daavoo](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@daavoo](https://discuss.dvc.org/u/daavoo)\
**Post date:** [April 6, 2022, 5:21pm UTC](https://discuss.dvc.org/t/best-practice-for-applying-pipelines-to-many-datasets/1147/3 "2022-04-06T17:21:52Z")

</div>

One thing to note is that `foreach` does not currently support parallelization. There is an open issue discussing it [dvc.yaml: future of foreach stages · Issue #5440 · iterative/dvc · GitHub](https://github.com/iterative/dvc/issues/5440)

---

<div class="post-metadata">

**Author:** ![steve.richardson](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@steve.richardson](https://discuss.dvc.org/u/steve.richardson)\
**Post date:** [April 6, 2022, 5:40pm UTC](https://discuss.dvc.org/t/best-practice-for-applying-pipelines-to-many-datasets/1147/4 "2022-04-06T17:40:10Z")

</div>

Thanks for pointing that out. While parallelization would be awesome for my use case, even having the `foreach` loop capability in serial seems like it will work for me.
