Skip to main content

RubyMarshal

Read and write Ruby-marshalled data. Only basics Ruby data types can be read and written:

  • float,
  • bool,
  • int,
  • str (mapped to rubymarshal.classes.RubyString if dumped with instance variables),
  • nil (mapped to None in Python),
  • array (mapped to list),
  • hash (mapped to dict),
  • symbols and other classes are mapped to specific Python classes.

Installation

    pip install rubymarshal

Usage

    from rubymarshal.reader import loads, load
    from rubymarshal.writer import writes, write
    with open('my_file', 'rb') as fd:
        content = load(fd)
    with open('my_file', 'wb') as fd:
        write(fd, my_object)
    loads(b"\x04\bi\xfe\x00\xff")
    writes(-256)

You can map Ruby types to Python ones:

    from rubymarshal.reader import loads
    from rubymarshal.classes import RubyObject

    class DomainError(RubyObject):
        ruby_class_name = "Math::DomainError"
    
    class_mapping = {"Math::DomainError": DomainError}

    loads(b'\x04\x08c\x16Math::DomainError', class_mapping=class_mapping)

You can use Ruby's symbols:

    from rubymarshal.reader import loads
    from rubymarshal.writer import writes
    from rubymarshal.classes import Symbol
    
    x = Symbol("test")
    dump = writes(Symbol("test"))
    y = loads(dump)
    assert y is x

Infos

Code is on github: https://github.com/d9pouces/RubyMarshal Documentation is on readthedocs: http://rubymarshal.readthedocs.org/en/latest/ Tests are on travis-ci: https://travis-ci.org/d9pouces/RubyMarshal

Release files for rubymarshal 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rubymarshal 1.2.0
File Size Uploaded
rubymarshal-1.2.0.tar.gz 12.4 kB Details

Release files / rubymarshal-1.2.0.tar.gz

Download URL rubymarshal-1.2.0.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0945e358df8d7f18ea5ebe9ed0986e0f923f7a569544b96a3deef36868f7bb31
BLAKE2b-256 checksum
How to use checksums
6a202553222fc5686d367f7d9d6734c29ea31bafc0803f08f118ff774618ea93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1

Release history Release notifications | RSS feed

1.2.10

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

1 release file

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

1 release file

1.2.1

1 release file

This release

1.2.0 This release

1 release file

1.0.3

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.9.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page