Metadata-Version: 2.4
Name: datachain
Version: 0.32.0
Summary: Wrangle unstructured AI data at scale
Author-email: Dmitry Petrov <support@dvc.org>
License-Expression: Apache-2.0
Project-URL: Documentation, https://datachain.dvc.ai
Project-URL: Issues, https://github.com/iterative/datachain/issues
Project-URL: Source, https://github.com/iterative/datachain
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Development Status :: 2 - Pre-Alpha
Requires-Python: >=3.9
Description-Content-Type: text/x-rst
License-File: LICENSE
Requires-Dist: pyyaml
Requires-Dist: tomlkit
Requires-Dist: tqdm
Requires-Dist: numpy<3,>=1
Requires-Dist: pandas>=2.0.0
Requires-Dist: ujson>=5.10.0
Requires-Dist: packaging
Requires-Dist: pyarrow
Requires-Dist: typing-extensions
Requires-Dist: python-dateutil>=2
Requires-Dist: dateparser>=1.0.0
Requires-Dist: attrs>=21.3.0
Requires-Dist: fsspec>=2024.2.0
Requires-Dist: s3fs>=2024.2.0
Requires-Dist: gcsfs>=2024.2.0
Requires-Dist: adlfs>=2024.2.0
Requires-Dist: dvc-data<4,>=3.10
Requires-Dist: dvc-objects<6,>=4
Requires-Dist: shtab<2,>=1.3.4
Requires-Dist: sqlalchemy>=2
Requires-Dist: multiprocess==0.70.16
Requires-Dist: cloudpickle
Requires-Dist: pydantic
Requires-Dist: jmespath>=1.0
Requires-Dist: datamodel-code-generator>=0.25
Requires-Dist: Pillow<12,>=10.0.0
Requires-Dist: msgpack<2,>=1.0.4
Requires-Dist: psutil
Requires-Dist: huggingface_hub
Requires-Dist: iterative-telemetry>=0.0.10
Requires-Dist: platformdirs
Requires-Dist: dvc-studio-client<1,>=0.21
Requires-Dist: tabulate
Requires-Dist: websockets
Requires-Dist: tomli; python_version < "3.11"
Provides-Extra: docs
Requires-Dist: mkdocs>=1.5.2; extra == "docs"
Requires-Dist: mkdocs-gen-files>=0.5.0; extra == "docs"
Requires-Dist: mkdocs-material==9.5.22; extra == "docs"
Requires-Dist: mkdocs-section-index>=0.3.6; extra == "docs"
Requires-Dist: mkdocstrings-python>=1.6.3; extra == "docs"
Requires-Dist: mkdocs-literate-nav>=0.6.1; extra == "docs"
Requires-Dist: eval-type-backport; extra == "docs"
Provides-Extra: torch
Requires-Dist: torch>=2.1.0; extra == "torch"
Requires-Dist: torchvision; extra == "torch"
Requires-Dist: transformers>=4.36.0; extra == "torch"
Provides-Extra: audio
Requires-Dist: torchaudio; extra == "audio"
Requires-Dist: soundfile; extra == "audio"
Provides-Extra: remote
Requires-Dist: lz4; extra == "remote"
Requires-Dist: requests>=2.22.0; extra == "remote"
Provides-Extra: vector
Requires-Dist: usearch; extra == "vector"
Provides-Extra: hf
Requires-Dist: numba>=0.60.0; extra == "hf"
Requires-Dist: datasets[vision]>=4.0.0; extra == "hf"
Requires-Dist: datasets[audio]>=4.0.0; (sys_platform == "linux" or sys_platform == "darwin") and extra == "hf"
Requires-Dist: fsspec>=2024.12.0; extra == "hf"
Provides-Extra: video
Requires-Dist: ffmpeg-python; extra == "video"
Requires-Dist: imageio[ffmpeg,pyav]>=2.37.0; extra == "video"
Requires-Dist: opencv-python; extra == "video"
Provides-Extra: postgres
Requires-Dist: psycopg2-binary>=2.9.0; extra == "postgres"
Provides-Extra: tests
Requires-Dist: datachain[audio,hf,postgres,remote,torch,vector,video]; extra == "tests"
Requires-Dist: pytest<9,>=8; extra == "tests"
Requires-Dist: pytest-sugar>=0.9.6; extra == "tests"
Requires-Dist: pytest-cov>=4.1.0; extra == "tests"
Requires-Dist: pytest-mock>=3.12.0; extra == "tests"
Requires-Dist: pytest-servers[all]>=0.5.9; extra == "tests"
Requires-Dist: pytest-benchmark[histogram]; extra == "tests"
Requires-Dist: pytest-xdist>=3.3.1; extra == "tests"
Requires-Dist: pytest-dotenv; extra == "tests"
Requires-Dist: virtualenv; extra == "tests"
Requires-Dist: dulwich; extra == "tests"
Requires-Dist: hypothesis; extra == "tests"
Requires-Dist: aiotools>=1.7.0; extra == "tests"
Requires-Dist: requests-mock; extra == "tests"
Requires-Dist: scipy; extra == "tests"
Requires-Dist: ultralytics; extra == "tests"
Provides-Extra: dev
Requires-Dist: datachain[docs,tests]; extra == "dev"
Requires-Dist: mypy==1.17.0; extra == "dev"
Requires-Dist: types-python-dateutil; extra == "dev"
Requires-Dist: types-dateparser; extra == "dev"
Requires-Dist: types-pytz; extra == "dev"
Requires-Dist: types-PyYAML; extra == "dev"
Requires-Dist: types-requests; extra == "dev"
Requires-Dist: types-tabulate; extra == "dev"
Provides-Extra: examples
Requires-Dist: datachain[tests]; extra == "examples"
Requires-Dist: defusedxml; extra == "examples"
Requires-Dist: accelerate; extra == "examples"
Requires-Dist: huggingface_hub[hf_transfer]; extra == "examples"
Requires-Dist: ultralytics; extra == "examples"
Requires-Dist: open_clip_torch; extra == "examples"
Requires-Dist: openai; extra == "examples"
Dynamic: license-file

================
|logo| DataChain
================

|PyPI| |Python Version| |Codecov| |Tests| |DeepWiki|

.. |logo| image:: docs/assets/datachain.svg
   :height: 24
.. |PyPI| image:: https://img.shields.io/pypi/v/datachain.svg
   :target: https://pypi.org/project/datachain/
   :alt: PyPI
.. |Python Version| image:: https://img.shields.io/pypi/pyversions/datachain
   :target: https://pypi.org/project/datachain
   :alt: Python Version
.. |Codecov| image:: https://codecov.io/gh/iterative/datachain/graph/badge.svg?token=byliXGGyGB
   :target: https://codecov.io/gh/iterative/datachain
   :alt: Codecov
.. |Tests| image:: https://github.com/iterative/datachain/actions/workflows/tests.yml/badge.svg
   :target: https://github.com/iterative/datachain/actions/workflows/tests.yml
   :alt: Tests
.. |DeepWiki| image:: https://deepwiki.com/badge.svg
   :target: https://deepwiki.com/iterative/datachain
   :alt: DeepWiki

DataChain is a Python-based AI-data warehouse for transforming and analyzing unstructured
data like images, audio, videos, text and PDFs. It integrates with external storage
(e.g. S3) to process data efficiently without data duplication and manages metadata
in an internal database for easy and efficient querying.


Use Cases
=========

1. **ETL.** Pythonic framework for describing and running unstructured data transformations
   and enrichments, applying models to data, including LLMs.
2. **Analytics.** DataChain dataset is a table that combines all the information about data
   objects in one place + it provides dataframe-like API and vectorized engine to do analytics
   on these tables at scale.
3. **Versioning.** DataChain doesn't store, require moving or copying data (unlike DVC).
   Perfect use case is a bucket with thousands or millions of images, videos, audio, PDFs.
4. **Incremental Processing.** DataChain's delta and retry features allow for efficient
   processing workflows:

   - **Delta Processing**: Process only new or changed files/records
   - **Retry Processing**: Automatically reprocess records with errors or missing results
   - **Combined Approach**: Process new data and fix errors in a single pipeline

Getting Started
===============

Visit `Quick Start <https://docs.datachain.ai/quick-start>`_ and `Docs <https://docs.datachain.ai/>`_
to get started with `DataChain` and learn more.

.. code:: bash

        pip install datachain


Example: Download Subset of Files Based on Metadata
---------------------------------------------------

Sometimes users only need to download a specific subset of files from cloud storage,
rather than the entire dataset.
For example, you could use a JSON file's metadata to download just cat images with
high confidence scores.


.. code:: py

    import datachain as dc

    meta = dc.read_json("gs://datachain-demo/dogs-and-cats/*json", column="meta", anon=True)
    images = dc.read_storage("gs://datachain-demo/dogs-and-cats/*jpg", anon=True)

    images_id = images.map(id=lambda file: file.path.split('.')[-2])
    annotated = images_id.merge(meta, on="id", right_on="meta.id")

    likely_cats = annotated.filter((dc.Column("meta.inference.confidence") > 0.93) \
                                   & (dc.Column("meta.inference.class_") == "cat"))
    likely_cats.to_storage("high-confidence-cats/", signal="file")


Example: Incremental Processing with Error Handling
---------------------------------------------------

This example shows how to use both delta and retry processing for efficient handling of large
datasets that evolve over time and may occasionally have processing errors.

.. code:: py

    import datachain as dc
    from datachain import C, File

    def process_file(file: File):
        """Process a file, which may occasionally fail."""
        try:
            # Your processing logic here
            content = file.read_text()
            result = analyze_content(content)
            return {
                "content": content,
                "result": result,
                "error": None  # No error
            }
        except Exception as e:
            # Return an error that will trigger reprocessing next time
            return {
                "content": None,
                "result": None,
                "error": str(e)  # Error field will trigger retry
            }

    # Process files efficiently with delta and retry
    chain = (
        dc.read_storage(
            "data/",
            update=True,
            delta=True,              # Process only new/changed files
            delta_on="file.path",    # Identify files by path
            retry_on="error"         # Field that indicates errors
        )
        .map(processed_result=process_file)
        .mutate(
            content=C("processed_result.content"),
            result=C("processed_result.result"),
            error=C("processed_result.error")
        )
        .save(name="processed_data")
    )

Example: LLM based text-file evaluation
---------------------------------------

In this example, we evaluate chatbot conversations stored in text files
using LLM based evaluation.

.. code:: shell

    $ pip install mistralai # Requires version >=1.0.0
    $ export MISTRAL_API_KEY=_your_key_

Python code:

.. code:: py

    import os
    from mistralai import Mistral
    import datachain as dc

    PROMPT = "Was this dialog successful? Answer in a single word: Success or Failure."

    def eval_dialogue(file: dc.File) -> bool:
         client = Mistral(api_key = os.environ["MISTRAL_API_KEY"])
         response = client.chat.complete(
             model="open-mixtral-8x22b",
             messages=[{"role": "system", "content": PROMPT},
                       {"role": "user", "content": file.read()}])
         result = response.choices[0].message.content
         return result.lower().startswith("success")

    chain = (
       dc.read_storage("gs://datachain-demo/chatbot-KiT/", column="file", anon=True)
       .settings(parallel=4, cache=True)
       .map(is_success=eval_dialogue)
       .save("mistral_files")
    )

    successful_chain = chain.filter(dc.Column("is_success") == True)
    successful_chain.to_storage("./output_mistral")

    print(f"{successful_chain.count()} files were exported")



With the instruction above, the Mistral model considers 31/50 files to hold the successful dialogues:

.. code:: shell

    $ ls output_mistral/datachain-demo/chatbot-KiT/
    1.txt  15.txt 18.txt 2.txt  22.txt 25.txt 28.txt 33.txt 37.txt 4.txt  41.txt ...
    $ ls output_mistral/datachain-demo/chatbot-KiT/ | wc -l
    31


Key Features
============

📂 **Multimodal Dataset Versioning.**
   - Version unstructured data without moving or creating data copies, by supporting
     references to S3, GCP, Azure, and local file systems.
   - Multimodal data support: images, video, text, PDFs, JSONs, CSVs, parquet, etc.
   - Unite files and metadata together into persistent, versioned, columnar datasets.

🐍 **Python-friendly.**
   - Operate on Python objects and object fields: float scores, strings, matrixes,
     LLM response objects.
   - Run Python code in a high-scale, terabytes size datasets, with built-in
     parallelization and memory-efficient computing — no SQL or Spark required.

🧠 **Data Enrichment and Processing.**
   - Generate metadata using local AI models and LLM APIs.
   - Filter, join, and group datasets by metadata. Search by vector embeddings.
   - High-performance vectorized operations on Python objects: sum, count, avg, etc.
   - Pass datasets to Pytorch and Tensorflow, or export them back into storage.


Contributing
============

Contributions are very welcome. To learn more, see the `Contributor Guide`_.


Community and Support
=====================

* `Docs <https://docs.datachain.ai/>`_
* `File an issue`_ if you encounter any problems
* `Discord Chat <https://dvc.org/chat>`_
* `Email <mailto:support@dvc.org>`_
* `Twitter <https://twitter.com/DVCorg>`_


DataChain Studio Platform
=========================

`DataChain Studio`_ is a proprietary solution for teams that offers:

- **Centralized dataset registry** to manage data, code and
  dependencies in one place.
- **Data Lineage** for data sources as well as derivative dataset.
- **UI for Multimodal Data** like images, videos, and PDFs.
- **Scalable Compute** to handle large datasets (100M+ files) and in-house
  AI model inference.
- **Access control** including SSO and team based collaboration.

.. _PyPI: https://pypi.org/
.. _file an issue: https://github.com/iterative/datachain/issues
.. github-only
.. _Contributor Guide: https://docs.datachain.ai/contributing
.. _Pydantic: https://github.com/pydantic/pydantic
.. _publicly available: https://radar.kit.edu/radar/en/dataset/FdJmclKpjHzLfExE.ExpBot%2B-%2BA%2Bdataset%2Bof%2B79%2Bdialogs%2Bwith%2Ban%2Bexperimental%2Bcustomer%2Bservice%2Bchatbot
.. _SQLite: https://www.sqlite.org/
.. _Getting Started: https://docs.datachain.ai/
.. _DataChain Studio: https://studio.datachain.ai/
