Skip to main content

Parse and save Python objects as **RDS or RData** files

Project description

Project generated with PyScaffold PyPI-Server Unit tests

rds2py

rds2py allows you to read and write R's native RDS and RData files directly in Python. Beyond standard R types, it provides integration with the BiocPy ecosystem, allowing you to easily roundtrip complex S4 data structures like SummarizedExperiment, SingleCellExperiment, and GenomicRanges. For more details, check out rds2cpp library.

Installation

Package is published to PyPI

pip install rds2py

To enable automatic conversion to Bioconductor/BiocPy classes, make sure to install the optional dependencies:

pip install rds2py[optional]

Quickstart

1. Reading RDS and RData files

Reading an RDS or RData file is as simple as a single function call. rds2py automatically detects and maps known R/Bioconductor classes to their Python equivalents:

from rds2py import read_rds, read_rda

# Read an RDS file (returns a Python/BiocPy object or dict)
data = read_rds("path/to/file.rds")

# Read objects from an RData workspace file (returns a dictionary of objects)
workspace = read_rda("path/to/workspace.rda")

If rds2py encounters an S4 class or complex R structure it doesn't have a parser registered for, it falls back to returning a dictionary so you don't lose any data.

2. Saving to RDS and RData files

You can serialize Python objects back to RDS or RData formats. This includes NumPy arrays, SciPy sparse matrices, standard dictionaries/lists, and BiocPy objects:

import numpy as np
from rds2py import write_rds, write_rda
from genomicranges import GenomicRanges
from iranges import IRanges

# 1. Write an atomic NumPy array
write_rds(np.array([10, 20, 30], dtype=np.int32), "array.rds")

# 2. Write a complex Bioconductor GenomicRanges object
gr = GenomicRanges(seqnames=["chr1", "chr2"], ranges=IRanges(start=[1, 100], width=[10, 50]), strand=["+", "-"])
write_rds(gr, "genomic_ranges.rds")

# 3. Write multiple Python objects into a single RData workspace
objects = {"my_array": np.array([1.1, 2.2, 3.3]), "my_granges": gr}
write_rda(objects, "workspace.rda")

3. Custom Extensions

If you have custom S4 representations or class mapping needs, you can parse the raw RDS structure into Python dictionary representations using parse_rds/parse_rda and apply your custom deserializers:

from rds2py import parse_rds
from rds2py.read_granges import read_genomic_ranges

# 1. Parse into a raw dictionary representation of the RDS tree
raw_dict = parse_rds("path/to/file.rds")
print(raw_dict.keys())  # ['type', 'class_name', 'attributes', 'data', ...]

# 2. Build or invoke custom parser logic
if raw_dict.get("class_name") == "GRanges":
    gr = read_genomic_ranges(raw_dict)
    print(gr)

For writing custom objects, you can register your classes to rds2py's serialization registry using the save_rds singledispatch generic:

from rds2py.generics import save_rds


class MyCustomClass:
    def __init__(self, value):
        self.value = value


@save_rds.register(MyCustomClass)
def _serialize_custom(x: MyCustomClass, path=None):
    # Construct the raw RDS dictionary representation expected by rds2cpp
    converted = {
        "type": "integer",
        "data": [x.value],
        "attributes": {"class": {"type": "string", "data": ["MyCustomRClass"]}},
    }

    # Optionally save if path is provided, otherwise return representation
    if path is not None:
        from rds2py.lib_rds_parser import write_rds as write_rds_native

        write_rds_native(converted, path)
    return converted

Type Conversion Reference

The table below describes how core R types are mapped to Python/NumPy/SciPy counterparts:

R Type / Class Python / NumPy / SciPy Counterpart
numeric numpy.ndarray (float64)
integer numpy.ndarray (int32)
logical numpy.ndarray (bool)
character list of str
factor list / representation levels
matrix (dense) numpy.ndarray
dgCMatrix (Column-sparse) scipy.sparse.csc_matrix
dgRMatrix (Row-sparse) scipy.sparse.csr_matrix
data.frame / DFrame biocframe.BiocFrame

Supported Bioconductor Classes

When rds2py[optional] is installed, the package fully translates R/S4 classes to their BiocPy equivalents:

  • GenomicRanges / GRanges <-> genomicranges.GenomicRanges
  • GenomicRangesList / GRangesList <-> genomicranges.CompressedGenomicRangesList
  • SummarizedExperiment <-> summarizedexperiment.SummarizedExperiment
  • RangedSummarizedExperiment <-> summarizedexperiment.RangedSummarizedExperiment
  • SingleCellExperiment <-> singlecellexperiment.SingleCellExperiment
  • MultiAssayExperiment <-> multiassayexperiment.MultiAssayExperiment

Developer Notes

  • rds2py uses pybind11 to bind the core C++ rds2cpp library. Compiling from source requires a compatible C++ compiler.
  • Tests can be run via tox or directly using pytest.

Note

This project has been set up using PyScaffold 4.5. For details and usage information on PyScaffold see https://pyscaffold.org/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rds2py-0.10.1.tar.gz (491.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rds2py-0.10.1-cp313-cp313-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

rds2py-0.10.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (237.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

rds2py-0.10.1-cp313-cp313-macosx_11_0_arm64.whl (181.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rds2py-0.10.1-cp312-cp312-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

rds2py-0.10.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (237.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

rds2py-0.10.1-cp312-cp312-macosx_11_0_arm64.whl (181.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rds2py-0.10.1-cp311-cp311-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

rds2py-0.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (235.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rds2py-0.10.1-cp311-cp311-macosx_11_0_arm64.whl (180.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rds2py-0.10.1-cp310-cp310-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

rds2py-0.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (234.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

rds2py-0.10.1-cp310-cp310-macosx_11_0_arm64.whl (179.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file rds2py-0.10.1.tar.gz.

File metadata

  • Download URL: rds2py-0.10.1.tar.gz
  • Upload date:
  • Size: 491.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rds2py-0.10.1.tar.gz
Algorithm Hash digest
SHA256 a4fb2bdd231019585220c2ad637432e03f17d2139d73e690c58e4e88c586af7a
MD5 8d65322f5d476836f20df72358fc7622
BLAKE2b-256 8951fddbca9ebcf242f77f03774734770c7d65ba58899edf098e1c30fd70219d

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1.tar.gz:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 660cd2766fdf9de5921f076c9c30c5378d2f36b6468053a65015d7eee45c4a57
MD5 db8dcb637edfd31116b06df2d191c8c2
BLAKE2b-256 770f746e1c459d59efb20b2dc3f5b81826a87ff980bea4b2111bf918cc81a64e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a2a8e1cb851670b5e89806e2791232efacf683f9a76b75a44117fdc96bbb2bed
MD5 a03b9270ad6edc371ec5285261391de7
BLAKE2b-256 b8cc85ab4b96072a5a895bb3fb1b4f657328e078285616471d8774f6da9129d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f53a8ee0c5086124ee5852c6f51a1571e7ba585f1727452459bc5d1aa8b95185
MD5 8e9d16feda34b2fd78f660cfde164258
BLAKE2b-256 29b889855a079e162b5da888cd44cd06f70e290eef168dd891f9cb1c34fff634

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 21757b475ab174c081ed12fe58dd74ffa3d4a51c0cb86d384c4038144a955120
MD5 151a84fd3ee14e6a55ce4cf390f15015
BLAKE2b-256 88cf1ffde9b9ed0dbb275e028c9269279c307796f1429221dc48a4cb6da92029

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 88f2f85721584bf2a993bbd6b6e285a7e5de544fc212b46a8a2ef04ff1d4c848
MD5 15a00f289e1b32050f8b8680d22a7753
BLAKE2b-256 bf28a410571cce5811419670b4acac58d4e90c89700301665fc04849fa18df6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b6de3714885a435e48bd09eb8f9c1c76088d9d18b24f604be1358db602e77ed
MD5 02307acf354ebd3fd14f14ca9da2481f
BLAKE2b-256 e8eefa35528ff42668ae225d209f960e2cc0bc502a8882f2eb9f3de0b3cb7ba3

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1429d2501724cf61e9dda44c220b41d865d25cf6e3889ed6a1305cc1af5cdab2
MD5 10baa0c66cc7e9a2cbcd9639f51cca86
BLAKE2b-256 b9f49335de8a0dafc693a33ae4972b22b645504e22d2dd20d37ac25913f01dc9

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 43d422e2d2feac94fd9a2572cd9108b438bbb32f030e0b79dffda5d9ab966cdf
MD5 736119830d558f7ba329660d76161ddb
BLAKE2b-256 6c567c5f77796c3bd3280a0acee1e4d60ec0c76ffcb6f652d775b73f45df4440

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fd7137f3de2ae68b1fd632b040cf7d5baec749a0da136f04976856a37cb687de
MD5 3b1de99f96cefba19cd882c6d4532e6a
BLAKE2b-256 644cc9623031f41f522d1387195eecbf31e5a6fedbb01f47ad720780ad806c2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4fc58d43da28d854c1774a37038e3442e41212e12c204cc73b15469ac43e895e
MD5 e0ac7097571a542b02256291e48b638c
BLAKE2b-256 b772e4947032631bf5a601edfe5f4a2e417e81daa2bbf2cf5beee16601cc192a

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34e3405bb83033d52b009714a9177fd3eb95518d74a0400464291fee289dd09c
MD5 e7bdc170e316f4516336f2d2b3104176
BLAKE2b-256 f7b4d87e7767f1186903204c1d78284978a613a5a214f51ff0700bf0665b644f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rds2py-0.10.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b95f78ca70d09ab6070cc8d251013cea6bc7b01e52e6d434fb0f1eff49309e79
MD5 b90936d5df834a8f6d26aa0f8864295d
BLAKE2b-256 9db36164c28d53f3ea320e299ff94211660aae8cd0144cf5b23181813b73429e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.1-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on BiocPy/rds2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page