Skip to main content

Auto-await coroutine results (calls, subscripts, item-assignment) in the IPython REPL.

Project description

ipython-smart-await

Auto-await coroutine results in the IPython REPL — drive a pure-async API without typing await everywhere.

When loaded, the extension rewrites each input cell so that expressions which evaluate to a coroutine are awaited automatically on IPython's loop runner.

Install

pip install ipython-smart-await

Usage

%load_ext smart_await

Then, given some async API bound to p:

p.get_pid()          # -> awaited automatically (no `await` needed)
a[0]                 # -> awaited if `a.__getitem__` returns a coroutine
a[0] = 7             # -> routed to `a.setindex(0, 7)` (awaited) when `a` has an async `setindex`

Opting out

Wrap a call in ...( ) to get the raw, un-awaited value:

coro = ...(p.get_pid())   # `coro` is the coroutine itself

Cells that already use await / async constructs are left untouched.

How it works

The extension installs an ast transformer (an IPython AST transformer) that wraps:

  • calls (foo()) and subscript reads (a[0]) in a helper that awaits the result only if it is a coroutine (non-coroutines pass through unchanged);
  • single-target subscript assignment (a[0] = v) into a call that routes to an async setindex(key, value) when the target exposes one, otherwise a normal item assignment — so dicts, lists, numpy arrays, etc. are unaffected.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipython_smart_await-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipython_smart_await-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file ipython_smart_await-0.1.0.tar.gz.

File metadata

  • Download URL: ipython_smart_await-0.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ipython_smart_await-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ba280c96d64ad78e57b8038027b6468c2ab2293932344bf12b723c265a9894df
MD5 0794c4eed722705e6e81f4f0295cea4f
BLAKE2b-256 ebe78cda89abc405abe45e4a406f6e44b6b77fd2546871cfcb80f753eea27119

See more details on using hashes here.

Provenance

The following attestation bundles were made for ipython_smart_await-0.1.0.tar.gz:

Publisher: release.yml on doronz88/ipython-smart-await

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ipython_smart_await-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ipython_smart_await-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 916fc2b82d8e604a9cc349fdb7f0029fbf1e50c4d334dc992c2e772bd4d94425
MD5 4e7f9a5c25d6774fc412739094330354
BLAKE2b-256 4ee9eb3b099ce5163854794cef5f828f5d7bbf235de51fe52b0c08f2748ae142

See more details on using hashes here.

Provenance

The following attestation bundles were made for ipython_smart_await-0.1.0-py3-none-any.whl:

Publisher: release.yml on doronz88/ipython-smart-await

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page