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.3.tar.gz (493.2 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.3-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.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

rds2py-0.10.3-cp313-cp313-macosx_11_0_arm64.whl (183.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rds2py-0.10.3-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.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

rds2py-0.10.3-cp312-cp312-macosx_11_0_arm64.whl (183.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rds2py-0.10.3-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.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (237.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rds2py-0.10.3-cp311-cp311-macosx_11_0_arm64.whl (182.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rds2py-0.10.3-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.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (236.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

rds2py-0.10.3-cp310-cp310-macosx_11_0_arm64.whl (181.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: rds2py-0.10.3.tar.gz
  • Upload date:
  • Size: 493.2 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.3.tar.gz
Algorithm Hash digest
SHA256 edcca692a1289b4eb90b52adf814d950470b9aa1af7f839776778e92db39e8ad
MD5 842cad5dc1a975ea8926a93092f7b5d9
BLAKE2b-256 260777e63781dbc9a4b630c260b8914fe2b7d23045a105950d5ba2a3bdd5c231

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3.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.3-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3a6580cdfbb12328760d0cc60775717d8da57e0c5851563df692a6baa481c9be
MD5 70584e701889289342fe028267f65256
BLAKE2b-256 e74a23b38489351efdd73fa776062c2e2fdc66776941658c54a3bb5d52875b2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2dd35e113e486e3b4d86664cf1bec536abb32f8f94698a411ce38974d1e794f4
MD5 9eb1d6d982de1f633e0241d8b8ee5fda
BLAKE2b-256 81ed24b817e83b7d9d4d6440a85815523b32b53d1066b7386a661e160df9bf22

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9901667bd862889b1601052604ab5655f35a3074309aa208a429c75c23259ca
MD5 dcc9f135422c7a122920cacc05626e28
BLAKE2b-256 2979abb7a0d6fbb2a927d346f5c7d65f6e624c01757af932d307eee270218608

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 86242e44172ba476cd327558d7d38665e10b26d50c0bc4584b47b3c2a908dad9
MD5 2854a0f4dd1941c933c55e2ae6824cb9
BLAKE2b-256 cdf87e0e0de4ac35aa75b92472073f69822343e4010d2e441c164271bcfd678c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 914c3dcd03068cf5309f2721ccc020c38dce6bcefa0395e2df7beb58119139fb
MD5 7597d482c51876cc2ac41a3dc50be1c5
BLAKE2b-256 f84c97d18ad8c6a61294196521e1929f383fda548b483d0599178c160c003b81

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d634fe9f902b1d989884d3d3e92bd7a6b24a8750b7e42a11ef65e35c06af9009
MD5 a2f5d88066ce749a5df490041ba403ee
BLAKE2b-256 e4ed1bf407bb139db51d3074f7bc80cd9457699ebaa0f1d457769a37eea65b7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 480bf0edc0b23fb5c30b5ac560d05a1029dd644b5ebd2a6eb0b7cd3c26c0bffc
MD5 0093a450a6e95228f6338f0033ff0af1
BLAKE2b-256 6d73f0a7fe2a38f58f518df3e650cfa83a71442a1b4596d4e7ac32444a109f99

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33a4187bfc6f8be5f52f3d58053b47325457935c3a5d19129532e66b00e93edc
MD5 a0a6be5543db85980f10e7621c14ebcc
BLAKE2b-256 648099a547e8c285cf6b9d1ad2121d33f308c823ffceeb8452212fcde001d956

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6456f574597c3e207ef2cadd530256bad1ca625ab3669459ef54647fcceeb301
MD5 169bcffeb0b0df65adaddf4d149e7321
BLAKE2b-256 3bf592487d697ce3a62c8c1338a24d57b8ed918ab5297a00cb3e0cf2f59b7c74

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2ebfc633e34f086523afc6efdae22c9b9149c7a70a36f124d2a9377b988c085f
MD5 c490b32171ba7da1e430777a12d341b4
BLAKE2b-256 2a9816395c84a4965bfe40c1c870c256c399a4a8b0b66aba128ac632a3a02d6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0046f69466570fea850a3349431f29bd5c855af50f03e823e3321322e1111414
MD5 c5c1be568f9e3cdfdd8c6e9d1287a85b
BLAKE2b-256 b7ccd0990b3e632dde687ef58705d8c1fff4d89eff377bdcc0bb5f976cd6e1e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16ca3f5d559a54da1c3fec8300e947adb2a10ccce56dd00554d3b8187b6422ef
MD5 f600190ed4918bdddb8e7eacb111204c
BLAKE2b-256 9009a4e081c3c683138285f4c98fe86efba4dcc6adecfe73247a6aade5bdb04e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.3-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