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.2.tar.gz (493.0 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.2-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.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

rds2py-0.10.2-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.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (182.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rds2py-0.10.2-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.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (237.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rds2py-0.10.2-cp311-cp311-macosx_11_0_arm64.whl (181.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rds2py-0.10.2-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.2-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.2-cp310-cp310-macosx_11_0_arm64.whl (180.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: rds2py-0.10.2.tar.gz
  • Upload date:
  • Size: 493.0 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.2.tar.gz
Algorithm Hash digest
SHA256 f1a87dfa268f6c2f66caa559230d6b246e71d26e5c78a49ccf87bf6b629f3ec9
MD5 4e44c68ac4c79bbb9021384fffea1576
BLAKE2b-256 04840c067863e58e0ca859ef33f33ce98c7882b7732790dc376c8fb6a2de8381

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f3bc6c34b1fffd0b4bbd87796331e6027d176cb282ebed63d1762bccc43c0675
MD5 32a7cb529ff25074266d7a92be070976
BLAKE2b-256 8f960f7a87b7eb2a3b04a109f13e9f1a1e848aa385d5c0185b2f2c0ae49dbb3e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 978d7085197182dcf3febfcba937c353a2d4411a406eb8941b83c75e82974a74
MD5 f84c6107c2d2a8eccd2e770a978d6f54
BLAKE2b-256 821e9e01156d8b59e5133327a94692bf592a90bc3987859ede29845517fab4d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f29cd42525132916c3debffbd73a34e1e8b867dca64a975d9cfc319e1aa912c0
MD5 2ec7e3eb67f4bbcb007230df892428f9
BLAKE2b-256 a73869b0b6e273d4350d671edb27dff3a040d3583fc3be5f8b0a33b546118021

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fdaa83c71aa9fe670ad0c38f94ea762e4add7074e0f814404ac78725b62f2fc3
MD5 a5415f7c910d6e7808806b6690ede6cc
BLAKE2b-256 5a40cca1b2526512e4c068e14c012ab1c4249cc6c05a7ce5c48975af5c623be2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 90622eeef788e8ca15c4f1070e314e666f5d4e3c242e8933cb1eca7f01581bfa
MD5 f377bfc4ac6e257de3456a344979376a
BLAKE2b-256 08a1ab8a8bf8a2c195009cc99905ab83016abf8fd02fc41cf2bc43b4bdc0d6f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f756384c072b6ebf23ae7de3c174231ae402811a5eb0111b4c2d40a6c71add6
MD5 f48b2b31c5e2584abfa1c78d34dd8eae
BLAKE2b-256 47780261f24d2341bbd1d5776645ef6c335a4604fbcf622e3d4964f24646de38

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c70f395154d69ec00f307fd25c86c00ffc44bf0fa2b37c6229a5d95ce3b5dd92
MD5 20f4d753cad19c43bd5f60fd0912ee70
BLAKE2b-256 c6c265578d25eaf015bbd89ef4a4a4b00c73060d15cf71c6345a6f518b1caa91

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 584435d9e02ab133f6b585cef5483bfa952c837ea92145702c2016365d14ac98
MD5 10d40cafe087e2715686985ffc292e3e
BLAKE2b-256 ce3c376579f960c746614c6491205654d7b169f225d3fecbdf3eaa4faf571792

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c24488afd35096bc2e0d906a5dc7cdf888451ec94a80007fbe15638aaec3a29c
MD5 8b951a96e574bb1924a951ea256ef505
BLAKE2b-256 830948e6157624eaf01b768e295d3f3d4a85e9824f076de91a653a580e274e09

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3a75d7ccf034da1e2bf28a7f0653262f64641a5be9617c62ac63a5a27f4b5ab8
MD5 3c775e8cffa8fa3399151d5f38c59dc0
BLAKE2b-256 9a80522b2d2a6375604eb31f00750639700a9c930f9902d9ac1d964d8770e021

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 89619ab28950727c8cfc28487a6ed0e6b361fe646a762a3f028cec9dbfa1ea3c
MD5 569522be825c4f78d61dbe72bd045031
BLAKE2b-256 1909ef5866cb6e5ce450179f252ce16fd53d17a6f7d50cb9c98ec6743a690a45

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 59494f076b777f7374b8f16e59cb0e8479841463f2cbbcf3f1cf5b5af08d592c
MD5 fce40fdc735cace9678ea9b80f4a9147
BLAKE2b-256 6c45438528e99ee6463569b8c1f2261897e7fc767abbc3b18f6e9e74b011579c

See more details on using hashes here.

Provenance

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