Skip to main content

IPyWalrus

IPyWalrus is a simple IPython (Jupyter) extension which enables you to use the walrus operator (PEP 572 - Assignment Expressions) := for usual assignments in IPython or Jupyter.

This part of the PEP:

There are a few places where assignment expressions are not allowed, in order to avoid ambiguities or user confusion:

Unparenthesized assignment expressions are prohibited at the top level of an expression statement. Example:

y := f(x)  # INVALID
(y := f(x))  # Valid, though not recommended

This rule is included to simplify the choice for the user between an assignment statement and an assignment expression -- there is no syntactic position where both are valid.

is completely valid but my IPython sessions of Jupyter notebooks are full of cells like this one:

standard

and because it does not work in pure Python

error

I've prepared a small extension which makes it work:

ipywalrus

Usage

Install the extension from pip or download the ipywalrus.py and put it somewhere in PYTHONPATH:

# pip install ipywalrus

and load it in IPython or Jupyter

%load_ext ipywalrus

If you want to enable this extension permamently, create a default profile (if you don't have one already) ipython profile create and then add ipywalrus to the list of extensions in ~/.ipython/profile_default/ipython_config.py.

License

MIT

Release files for ipywalrus 0.2

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

Source distribution (sdist)

Source distribution for ipywalrus 0.2
File Size Uploaded
ipywalrus-0.2.tar.gz 2.8 kB Details

Built distribution (wheel)

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

Total release size: 6.3 kB

Release files / ipywalrus-0.2.tar.gz

Download URL ipywalrus-0.2.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
267761ccacbc742916933d7e8ce79d0f6628636c1bcbd2a2b9c92ac38d4441b5
BLAKE2b-256 checksum
How to use checksums
2f14405c2d62ebc158a32a3e21c7f1d987360e1e258d9535e6844931f35ebf84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.2 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.6

Release files / ipywalrus-0.2-py3-none-any.whl

Download URL ipywalrus-0.2-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cd3ac89123d27eeaebf1f8e126dae174e6ec9ae6d5ec0e965ce44f1b61229b7
BLAKE2b-256 checksum
How to use checksums
ee7164e1ed8abd6eb981aa8ededbac196bccef287e730997179b617a1dcf4df9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.2 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.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