GithubHelp home page GithubHelp logo

asmeurer / mypython Goto Github PK

View Code? Open in Web Editor NEW
47.0 3.0 5.0 1.19 MB

A Python REPL the way I like it

Home Page: https://www.asmeurer.com/mypython/

License: Other

Python 100.00%
python repl prompt-toolkit

mypython's Introduction

mypython

A Python REPL the way I like it.

What? Why?

I was unsatisfied with all the existing Python interpreter options. None quite worked the way I liked them to, even after attempting to configure them (often a frustrating experience).

So instead I wrote my own. Turns out it's really easy.

prompt-toolkit is a nice framework for creating custom REPLs. It took under an hour to create a basic Python REPL, and only a few days to add most of the features I like to it. REPLs created with prompt-toolkit are really nice. They support advanced features like syntax highlighting, multiline editing, and popup tab completion without any additional work (unlike REPLs based on readline).

Features

  • Fancy emoji numbered prompts.
  • Multiline input, which "just works"
  • Keyboard shortcuts configured exactly the way I like them.
  • History search (M-Up/Down Arrow) can be used to combine multiple things from the history.
  • Up/down automatically go to the top/bottom of multiline inputs from the history. Up+Enter intelligently executes.
  • Outputs saved as _1, _2, etc.. Previous outputs saved in _, __, and ___.
  • Support for bracketed paste (pasting stuff in the terminal "just works" without the need for any %paste magic or a special "paste" mode).
  • prompts are stripped automatically from pasted text.
  • Emacs command editing keybindings.
  • Automatic syntax highlighting.
  • Automatic highlighting of errors via pyflakes.
  • On syntax error, the cursor is moved to the error.
  • Matching and mismatching parentheses highlighting.
  • Tracebacks for stuff defined interactively show the code line.
  • Tab completion using Jedi and dir().
  • Per-terminal history.
  • A nice theme (the same one I use in emacs, called "1am", based on XCode's "midnight").
  • stuff? shows the help for stuff. Works even if stuff is a complex expression. Does the right thing for NumPy ufuncs.
  • stuff?? shows the source for stuff. Works even if stuff was defined interactively.
  • %time and %timeit magic commands.
  • %doctest mode to emulate standard Python REPL (for copy-paste purposes).
  • %sympy magic (works like sympy.init_session().
  • %pyinstrument magic to run code with pyinstrument.
  • %line_profiler magic to run code with line_profiler.
  • %pudb magic to run code in PuDB.
  • Debugging functions defined interactively works.
  • Integration as a custom shell for PuDB.
  • SymPy objects automatically pretty print.
  • Shell integration with iTerm2.
  • GUI Matplotlib plots on macOS work correctly.

And some other stuff that I haven't implemented yet.

Most of this stuff either comes for free from prompt-toolkit or was really easy to implement, in some cases by modifying some code from other libraries (ptpython, ipython, sympy, the Python standard library).

Installation

I haven't packaged it yet. For now you can clone the repo and run ./bin/mypython.

It requires the following packages, which can be installed from conda-forge:

  • prompt_toolkit
  • pygments
  • iterm2_tools (on Mac)
  • parso
  • jedi
  • pyflakes
  • setproctitle

As well as some optional dependencies that are needed for some %magic commands:

  • pudb
  • pyinstrument
  • matplotlib
  • sympy

You can install them using the requirements.txt file.

Configuration

There is none. It's already configured the way I like it.

Features and bugs and stuff

I wrote this for me. You can request features, submit PRs, and report bugs, but be aware that I won't accept any PR unless it's a feature I want. I'm really not designing this to be used by other people.

Acknowledgments

Thanks to Jonathan Slenders for prompt-toolkit and ptpython (which I borrowed some of the more tricky things like Python multiline and Jedi completion from). Basically all the fancy stuff here is coming from prompt-toolkit. I just combined it together into a REPL that I like. Thanks to the IPython guys for figuring out the matplotlib eventloop stuff (which I could never do on my own), and for inspiring many of the features I've implemented.

License

MIT.

Licenses for code taken and modified from ptpython, IPython, prompt-toolkit, SymPy, and the Python standard library are at the top of the respective files.

mypython's People

Contributors

asmeurer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mypython's Issues

Add some pictures or video clips to your Readme

There are many REPL replacements and fixers out there, so it would be incredibly more helpful if you could add some screenshots, video clips or dynamic gifs on how this looks and how it's better than others.

Perhaps, more specifically, what are you adding or improving here, that is not already in ipython or bpython ones?

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.