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

For custom R classes or S4 structures, you can register custom parser functions dynamically using the register_parser decorator:

import rds2py

@rds2py.register_parser("MyCustomRClass")
def parse_my_custom_class(robject, **kwargs):
    # Construct your custom Python representation from the raw RDS dictionary
    value = robject.get("data", None)
    return {"coerced": True, "value": value}

You can also 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.5.tar.gz (493.8 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.5-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.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (213.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

rds2py-0.10.5-cp313-cp313-macosx_11_0_arm64.whl (182.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rds2py-0.10.5-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.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (213.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

rds2py-0.10.5-cp312-cp312-macosx_11_0_arm64.whl (182.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rds2py-0.10.5-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.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (210.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

rds2py-0.10.5-cp311-cp311-macosx_11_0_arm64.whl (181.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rds2py-0.10.5-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.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (209.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

rds2py-0.10.5-cp310-cp310-macosx_11_0_arm64.whl (179.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: rds2py-0.10.5.tar.gz
  • Upload date:
  • Size: 493.8 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.5.tar.gz
Algorithm Hash digest
SHA256 7b84c42e6e9babc27130dac95d33f6a19b455fd7b529d408952276aa9807725c
MD5 ac6ecfcff5a45b6f0cdbd09821f8a7a0
BLAKE2b-256 8866c1c975ff4e210802b569b832aab710d8eb1d15c20ad0ce9ca1a6f6831189

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 94eb1bc7bc11921e96b050ae84057cbeb72d5bb6e266d52d1909e6669a39412c
MD5 6b538b1408b3a6534855e893af4bb6db
BLAKE2b-256 6c05eab43f5cda7a5204d27b52e96c1247072b62cb6dd3cecff82784f3df19fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.5-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.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f17ceca2eb0c60f8b193c9a630a487704f6f2fd6bbc7c75be6d9e301ef5799d4
MD5 20de34f099f4693b816dd41dc58bad8c
BLAKE2b-256 53e9b539218db303f15245a1cb3e5e77255d0700624950ea5dd44df0441e1fbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_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.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6c331fe9f74b01505178a1608dfd40913c7796fba7d7a090a3bd0249f9462d71
MD5 0a67aa74c8b0a995ebc82c6e768cd30f
BLAKE2b-256 354067ce473c6a9234f217b5b40aa91e34a04cce5866705f7cccc72eaada3203

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3c05835c49808177472c359b44eeb8cf15daab63785cdf189a0b2736a70215ce
MD5 4b89fb900cb0bdaa7e38e4e5e9eaac1f
BLAKE2b-256 0ca731e24fe0753e6ef47c9aea728c3edcfb66927a6677aaed58ebf551152956

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.5-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.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1be05e83b39447bba8a6ed29e61183404f553615798ba75085869713f437c217
MD5 cd97c6b1990b9faf708cd8a81aadd304
BLAKE2b-256 ca9eb6d822760270a42d396a043c0afde161c82b538411f3232579b8f1c1f01c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_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.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 88d9e45734ea6e8aad87a3162702caceb56e90cb5eea4d325d9e42e94cd5f640
MD5 46b368a5fd6dc138e23cb3848def9be6
BLAKE2b-256 a915371127a511c28c3cb976fcdb0fc8572651eb7557c278f737e97981a1e1d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 133a6a87ab8afbfafe1deea81a99db145fe3c25f09b338f8690aae5afb9b94f1
MD5 9ffbcf843e967d9cb0a1f3933474678b
BLAKE2b-256 b4228a4c1d53d463de4d7dfe9a8e230514c10701a3bf2fe06766a3e7f46e2e9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.5-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.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3a28abaecd7f42cdcacc686a05a05eeab2896bd3ab9cd0e4e2868a0f0b57e3a4
MD5 91a36b07986f0ac5995a480400e35a44
BLAKE2b-256 c70e2d9f876746175b5baeca6d8bf52d0af179e0f0be6711e6e03c02356b6539

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_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.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 649582992a5a9e88266b3f6fa92456762e8b6ac51db328c8ee7fe14809d7e0e8
MD5 82c1ec3e0666d5cb185b1b3cf7eaff44
BLAKE2b-256 d4994f31e6ea07220b461ec6a848b98d7693b3b9908992eab005f7810b1d7a3f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.5-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f7e715961f945a8616b3b3d3c7bd3b237bfb72e13ea34b4a4781320af967c3c3
MD5 a1350e568c322325b65217bc46bd1f55
BLAKE2b-256 df8324b326570754a208339e29bb5d5c7c6e81d85db992458eb36291ee06e10d

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.5-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.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b750f65975cfb130a89f702e935a234d5fb8986593b2f7f1b026caa05fde2c3
MD5 e00388db6752920ef1295e55e7840125
BLAKE2b-256 9e617d3e29d9dba68256a35e27854d0035134789aa2f9e0ca2ba1cc936aed50f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rds2py-0.10.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_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.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rds2py-0.10.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5b89b31b9fbbb96421b420ed9688ddfc312c016de50e6ecda429e54e2190a8ca
MD5 e9c7cd9f797a9b867fe0a9567e3b0a6b
BLAKE2b-256 1b7ecaac7bd5de7e964f236d7839df0dd2ab66432d5ab1bf5afeffb12d541df4

See more details on using hashes here.

Provenance

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