prygo

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 10 Imported by: 0

README

prygo

prygo - an interactive REPL for Go that allows you to drop into your code at any point.

This repository is an actively maintained continuation of Tristan Rice’s original project. The fork keeps pace with modern Go toolchains (Go 1.25+) and focuses on reliability in large modules:

  • Toolchain-aware temp modules – prygo mirrors your project’s go/toolchain directives inside scratch workspaces, so go run no longer fails with “go mod tidy” or toolchain mismatch errors.
  • Safer import handling – generated files automatically reference every requested package (including interfaces), preventing “unused import” panics when you drop into the REPL.
  • Improved module discovery – prygo detects the active module root (or uses PRYGO_MODULE_ROOT) so local development uses your checked-out sources without manual replace directives.
  • Up-to-date dependencies & CI – the module file, GitHub Actions, and tests are refreshed for current Go releases, and failing example binaries are opt-in only.

Tests GoDoc

prygo

Example

prygo Animated Example prygo Example

Usage

Install prygo

go install github.com/sottey/prygo@latest

Add the pry statement to the code

package main

import "github.com/sottey/prygo/pry"

func main() {
  a := 1
  pry.Pry()
}

Run the code as you would normally with the go command. prygo is just a wrapper.

# Run
prygo run readme.go

If you want completions to work properly, also install gocode if it is not installed in your system

go get -u github.com/nsf/gocode

More details are available in examples.md

How does it work?

prygo is built using a combination of meta programming as well as a massive amount of reflection. When you invoke the prygo command it looks at the Go files in the mentioned directories (or the current in cases such as prygo build) and processes them. Since Go is a compiled language there's no way to dynamically get in scope variables, and even if there was, unused imports would be automatically removed for optimization purposes. Thus, prygo has to find every instance of pry.Pry() and inject a large blob of code that contains references to all in scope variables and functions as well as those of the imported packages. When doing this it makes a copy of your file to .<filename>.gopry and modifies the <filename>.go then passes the command arguments to the standard go command. Once the command exits, it restores the files.

If the program unexpectedly fails there is a custom command prygo restore [files] that will move the files back. An alternative is to just remove the pry.Apply(...) line.

Examples & Tutorials

See examples.md for a guided tour covering installation, standalone REPL usage, common debugging workflows, and tips for first-time users.

Working Outside the Module Root

prygo writes temporary modules whenever it needs to run code in a scratch directory (for example, the standalone REPL). It inspects your project’s go.mod to copy the go/toolchain directives, so builds use the same toolchain as your main module. If prygo cannot automatically locate your module root—for instance when you run from a nested example directory—set PRYGO_MODULE_ROOT=/absolute/path/to/your/module before invoking prygo. That tells prygo exactly which go.mod to mirror and which local replace directives to apply.

Inspiration

prygo is greatly inspired by Pry REPL for Ruby.

License

prygo is licensed under the MIT license.

prygo was refactored and is maintained by sottey

The original go-pry was made by Tristan Rice.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
example
for-loop command
func-args command
goroutine command
goroutines command
maps command
math command
packagealiases command
readme command
playground
genmeta command
server command
pry
safebuffer
safebuffer is a goroutine safe bytes.Buffer.
safebuffer is a goroutine safe bytes.Buffer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL