2
0
Fork
You've already forked datasalad
0
Python utilities for working with data in the vicinity of Git and git-annex [public mirror] https://hub.datalad.org/datalad/datasalad
  • Python 99.9%
Michael Hanke 3b74d0396d
chore: switch to sphinx-autodoc-typehints
This sidesteps complaints of sphinx not finding a setup function for the
previous dependency.
2026年06月01日 07:31:50 +02:00
.forgejo/workflows chore: boost actions to use codespell v2.2 2026年01月22日 14:04:40 +01:00
.github/workflows chore: boost actions to use codespell v2.2 2026年01月22日 14:04:40 +01:00
datasalad doc: add trailing empty line to address API doc builder issue 2026年06月01日 07:31:40 +02:00
docs chore: switch to sphinx-autodoc-typehints 2026年06月01日 07:31:50 +02:00
tools/appveyor ci: Remove git-annex installation setup from appveyor spec 2025年06月06日 15:30:18 +02:00
.changelog.md.j2 chore: consolidate changelog "looks" in template 2024年09月22日 18:44:12 +02:00
.gitignore chore: ignore coverage output 2024年09月29日 10:59:35 +02:00
.noannex Some first basic information 2024年05月14日 13:26:02 +02:00
.readthedocs.yaml chore: tune documentation setup 2024年09月29日 10:57:50 +02:00
appveyor.yml doc: fix typo 2026年01月17日 13:37:52 +01:00
CHANGELOG.md bump: version 0.7.1 → 0.8.0 2026年05月28日 13:10:33 +02:00
conftest.py test: new cat_util, ls_util, and funzip_util fixtures 2025年07月04日 08:37:10 +02:00
CONTRIBUTING.md doc: show uv in contributing docs and document better hatch usage 2025年07月04日 08:37:10 +02:00
LICENSE doc: correct year in copyright/license terms 2024年06月14日 08:12:07 +02:00
pyproject.toml chore: switch to sphinx-autodoc-typehints 2026年06月01日 07:31:50 +02:00
README.md chore: remove GitHub releases badge, no longer available 2026年01月22日 14:36:18 +01:00

DataSALad

PyPI version fury.io Documentation Status Hatch project

This is a pure-Python library with a collection of utilities for working with data in the vicinity of Git and git-annex. While this is a foundational library from and for the DataLad project, its implementations are standalone, and are meant to be equally well usable outside the DataLad system.

A focus of this library is efficient communication with subprocesses, such as Git or git-annex commands, which read and produce data in some format.

Here is a demo of what can be accomplished with this library. The following code queries a remote git-annex repository via a git annex find command running over an SSH connection in batch-mode. The output in JSON-lines format is then itemized and decoded to native Python data types. Both inputs and outputs are iterables with meaningful items, even though at a lower level information is transmitted as an arbitrarily chunked byte stream.

>>> from more_itertools import intersperse
>>> from pprint import pprint
>>> from datasalad.runners import iter_subproc
>>> from datasalad.itertools import (
... itemize,
... load_json,
... )
>>> # a bunch of photos we are interested in
>>> interesting = [
... b'DIY/IMG_20200504_205821.jpg',
... b'DIY/IMG_20200505_082136.jpg',
... ]
>>> # run `git-annex find` on a remote server in a repository
>>> # that has these photos in the worktree.
>>> with iter_subproc(
... ['ssh', 'photos@pididdy.local',
... 'git -C "collections" annex find --json --batch'],
... # the remote process is fed the file names,
... # and a newline after each one to make git-annex write
... # a report in JSON-lines format
... inputs=intersperse(b'\n', interesting),
... ) as remote_annex:
... # we loop over the output of the remote process.
... # this is originally a byte stream downloaded in arbitrary
... # chunks, so we itemize at any newline separator.
... # each item is then decoded from JSON-lines format to
... # native datatypes
... for rec in load_json(itemize(remote_annex, sep=b'\n')):
... # for this demo we just pretty-print it
... pprint(rec)
{'backend': 'SHA256E',
 'bytesize': '3357612',
 'error-messages': [],
 'file': 'DIY/IMG_20200504_205821.jpg',
 'hashdirlower': '853/12f/',
 'hashdirmixed': '65/qp/',
 'humansize': '3.36 MB',
 'key': 'SHA256E-s3357612--700a52971714c2707c2de975f6015ca14d1a4cdbbf01e43d73951c45cd58c176.jpg',
 'keyname': '700a52971714c2707c2de975f6015ca14d1a4cdbbf01e43d73951c45cd58c176.jpg',
 'mtime': 'unknown'}
{'backend': 'SHA256E',
 'bytesize': '3284291',
 ...

Developing with datasalad

API stability is important, just as adequate semantic versioning, and informative changelogs.

Public vs internal API

Anything that can be imported directly from any of the sub-packages in datasalad is considered to be part of the public API. Changes to this API determine the versioning, and development is done with the aim to keep this API as stable as possible. This includes signatures and return value behavior.

As an example: from datasalad.runners import iter_git_subproc imports a part of the public API, but from datasalad.runners.git import iter_git_subproc does not.

Use of the internal API

Developers can obviously use parts of the non-public API. However, this should only be done with the understanding that these components may change from one release to another, with no guarantee of transition periods, deprecation warnings, etc.

Developers are advised to never reuse any components with names starting with _ (underscore). Their use should be limited to their individual subpackage.

Contributing

Contributions to this library are welcome! Please see the contributing guidelines for details on scope and style of potential contributions.