unpickle

0.2.0 • Public • Published

Unpickle Python data in Node.js

This library allows to unpickle data pickled with Python 3.5 (up to pickle prococol 4).

WARNING: Not all pickle opcodes are supported. The library was created from scratch and I only added opcodes that I encountered in my test data.

Installation

Use npm (or yarn):

npm install unpickle

Usage

const data = unpickle(<Buffer>)

The following example unpickles Django session from Redis:

import unpickle from 'unpickle'
 
async function getDjangoSession (sessionId) {
  const data = await redis.getAsync('django.contrib.sessions.cache' + sessionId)
  return unpickle(data)
}

Testing

git clone https://github.com/IlyaSemenov/node-unpickle.git
cd node-unpickle
yarn
npm test

How to inspect pickle in Python

s = b"\x80\x04\x95....."
import pickleimport pickletoolsprint(pickle.loads(s))pickletools.dis(s)

Contributing

PRs and general feedback are welcome.

Readme

Keywords

Package Sidebar

Install

npm i unpickle

Weekly Downloads

89

Version

0.2.0

License

MIT

Last publish

Collaborators

  • ilyasemenov