Skip to main content

r2pipe for Python

Interact with radare2 using the #!pipe command or in standalone scripts that communicate with local or remote r2 via pipe, tcp or http.

Installation

$ pip install r2pipe

or

$ pip3 install r2pipe

Usage example:

import r2pipe

r2 = r2pipe.open("/bin/ls")
r2.cmd('aa')
print(r2.cmd("afl"))
print(r2.cmdj("aflj"))            # evaluates JSONs and returns an object
print(r2.cmdj("ij")["core"]["format"])  # shows file format
r2.quit()

Structured commands (r2pipe2)

cmd2() accepts boolean trim and json options. trim=True strips output whitespace; json=True asks radare2 to embed the command's JSON output in the response's res field. cmd2j() defaults both options to True, and explicit False values override those defaults.

with r2pipe.open("-", flags=["-N"]) as r2:
    print(r2.cmd2("?e hello", trim=True).res)  # "hello"
    print(r2.cmd2("ij", json=True).res.core.file)
    print(r2.cmd2j("?e hello", json=False, trim=False).res)  # "hello\n"

Both methods accept callback=..., which receives the raw response string before Python parses the JSON. Callbacks are handled in Python and are never included in the request JSON. Synchronous call(), cmd(), cmdj(), and cmdJ() also support callbacks. Unknown r2pipe2 keywords, non-boolean flags, and callbacks that are neither callable nor None raise TypeError before execution. call() accepts only the optional callback keyword.

Asyncio

Import the async client to await commands inside an event loop:

import asyncio
from r2pipe.open_async import open as async_open

async def main():
    async with async_open("/bin/ls", flags=["-N"]) as r2:
        reply = await r2.cmd2j("ij")
        print(reply.res.core.file)
        print(await r2.cmd("afl"))

asyncio.run(main())

cmd, cmdj, cmdJ, call, cmd2, and cmd2j return awaitables inside the client's event loop. Outside a running loop, the async client keeps its existing blocking behavior. A client created before starting the event loop can be used inside it; once commands have run, use that same loop for the rest of the session. Embedded #!pipe and r2lang commands retain their blocking behavior.

Native ccall:// sessions also support these awaitable methods. Each session runs core creation, commands, and cleanup on one dedicated worker thread so native calls leave the event loop responsive.

Use async with or await r2.close() / await r2.quit() to clean up. Closing keeps the caller's event loop open. Commands on one client run in sequence, including commands submitted with asyncio.gather. Canceling a command that has already started lets its response finish draining before the next command runs; the command may still change radare2 state. Closing waits for these started commands and rejects commands still waiting to run. Callbacks receive the raw response before JSON parsing, as with blocking calls.

Metadata

Release files for r2pipe 2.1.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 r2pipe 2.1.0
File Size Uploaded Provenance
r2pipe-2.1.0.tar.gz 37.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for r2pipe 2.1.0
File Interpreter ABI Platform
r2pipe-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 57.5 kB

Release files / r2pipe-2.1.0.tar.gz

Download URL r2pipe-2.1.0.tar.gz
Size 37.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7dcfa14fc3436e0ec887b0397daf4c8d7882a0320a333fbdc6aa3797fa1a929a
BLAKE2b-256 checksum
How to use checksums
c43d4f7dceea20d987c6b2d693584e49991f97071a5b68b0d084aa5a43b70a23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.0

Release files / r2pipe-2.1.0-py3-none-any.whl

Download URL r2pipe-2.1.0-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b1902d6cfa41590f10c5f27baf504dc4e01911863066e658c5c717c14d207a6
BLAKE2b-256 checksum
How to use checksums
5a7679f4391b5e997fb8ee420e8c3fe46c7c06b4c91a5107846669d10c4f4f5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.0

Security for r2pipe 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files No provenance

0.4

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