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.4.tar.gz (493.3 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.4-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.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

rds2py-0.10.4-cp313-cp313-macosx_11_0_arm64.whl (183.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rds2py-0.10.4-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.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

rds2py-0.10.4-cp312-cp312-macosx_11_0_arm64.whl (183.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rds2py-0.10.4-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.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (236.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rds2py-0.10.4-cp311-cp311-macosx_11_0_arm64.whl (181.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rds2py-0.10.4-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.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (235.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

rds2py-0.10.4-cp310-cp310-macosx_11_0_arm64.whl (180.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: rds2py-0.10.4.tar.gz
  • Upload date:
  • Size: 493.3 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.4.tar.gz
Algorithm Hash digest
SHA256 c833bbeddcd3c5fdc5dafe9a404d38f6cb911aade1f78a610a114ebdad0be396
MD5 a4f6b13cd40204541dc4118e66d5db09
BLAKE2b-256 511a67c6b690472bc0b6759868f7e7332c0004c84969fb42e5d3ae5bf4d9012f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 86c95e3f9256f7f28f1aca482aad57c01025ffb714ff6c4434fda468d2dec6d1
MD5 5b77dca8af65347c21007e0c03b3d6b1
BLAKE2b-256 4cd56182d7e25ba14907ade62f97afbb6fe704740abda144646166fce8b0b5a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bc5600ea5fe19960293568b7aa177cfe6c915aee74697fdb9f0bc658702f666f
MD5 475ac3cc858ab9c7b382f04e906511e8
BLAKE2b-256 92530a32c1f9098890ae69d717793cd129d68d6997f5004738c93aa1914d5ea4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cef40cece8167b8efefb4b0e8b858b24d6a4e82e8abb6838ef499d4abd0efa81
MD5 b90ed7f94c4be37b0579301be5521dcf
BLAKE2b-256 46fac21b4f7c9e1605dd49818fb239a6c26d42b731b36974c96fb0d0d624ef07

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5e7cb6594690fb5e0d72bf7e2799e81b553de0eed45728d8856690ee0cdc33c0
MD5 72206a5de55619b1c9fc132bac98eac1
BLAKE2b-256 26099d33de624aa05ce053f1701e29ad4075f5c5caf9d89cb5a4113c09dcadcc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7f138eab56c66b60ab590afd29f9b2fa1d1e46975c9eb606bcf56eb5cb5139d
MD5 a8bbfeb430009c3227fe74f9295f4ed2
BLAKE2b-256 3fe45ae8f411df13fe128c8d42645a4647d11519a4d0eca33672d5404a605b91

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a96097c0f38c45dc0a58cf59af177ab9212c1af85800ee60bd16c521a0ed84e3
MD5 3503bf26d8327d7786578dd6798674c7
BLAKE2b-256 0f03c507f4d569074ae9c5fe72f192122195fcaa3c5f6f420eb13e32a6caad7a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1ea961ebe249568c387188c45b6718e1e60b17f2f6d04f098320f0a276f04f36
MD5 5115a4bc9e0a5e033c976f7fda8d44cf
BLAKE2b-256 9ac72fe1f0ea29b5e62907c9f2b0f250013a7068bb69621f13cadc51ab74e220

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 43da2e43a748349acaabacc0c51c4264c531abb24116bcb8f9b8ea7070e0c207
MD5 03721443fa462f9c7b89857f32c1a294
BLAKE2b-256 b1c539addd0ab173ec57db9052fd1daf8c1b107a34630cebc762380c21bd0765

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e8c54e056e88928dad6a39f7bdee600c496d15f12d794cbfc5163627d5a442fd
MD5 e6cbc4b818d0a71779df4733391e5081
BLAKE2b-256 cb0e66732d314ec2b8879fa4b885f7c82f345fd1f735aae1cde9df781c8c2dbf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a73a87510328563e76fb038ed8870ba51ff01551aff4d206e43dd9887a2bc5bd
MD5 8ca7757242162b33f17f783273829ff5
BLAKE2b-256 a7cf994e5c76e03c3c044ddc2b7637fa599d45ea7db84e5ab9c87c5868dfc31a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0bec4c9bc3f7b3542bc0a0bae9956d62675b16a3d84b12a3f2082ed9894a371
MD5 c8e19bf8898a77bdcc2e00418ed7624f
BLAKE2b-256 1d8a4abb08e7f9a3de379cf5fea3e450470ec8dd3060b7df80abf5c73ca33984

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rds2py-0.10.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d2739f40bcfdd725c02e3a44ec2d232318a90a9b178886cc0c566a864defd26
MD5 498d734c52052bc0789570aadec2819f
BLAKE2b-256 16d72197e92f1f449b562ea80914527cda392d0802d3d863f157dbe9349e0000

See more details on using hashes here.

Provenance

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