CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ipython

IPython: Productive Interactive Computing - An advanced interactive computing environment and command shell for Python.

86

1.08x
Overview
Eval results
Files

core-shell.mddocs/

Core Shell Functions

Primary entry points for starting IPython sessions, embedding interactive shells in existing code for debugging, and managing the current IPython instance. These functions provide the foundation for IPython's interactive computing capabilities.

Capabilities

Starting IPython Sessions

Launch a complete IPython session with full initialization, configuration loading, and startup file execution.

def start_ipython(argv=None, **kwargs):
    """
    Launch a normal IPython instance (as opposed to embedded).
    
    IPython.embed() puts a shell in a particular calling scope,
    such as a function or method for debugging purposes,
    which is often not desirable.
    
    start_ipython() does full, regular IPython initialization,
    including loading startup files, configuration, etc.
    much of which is skipped by embed().
    
    Parameters:
    - argv: list or None, optional - Command-line options. If None, 
            IPython will parse from sys.argv. Pass [] to prevent parsing.
    - user_ns: dict, optional - Initialize IPython user namespace
    - **kwargs: various, optional - Additional Application constructor args,
               such as 'config' (traitlets Config object)
    
    Returns:
    TerminalIPythonApp instance
    """

Usage example:

import IPython

# Start with default configuration
IPython.start_ipython()

# Start without command-line parsing
IPython.start_ipython(argv=[])

# Start with custom user namespace
IPython.start_ipython(user_ns={'custom_var': 42})

# Start with configuration
from traitlets.config import Config
c = Config()
c.TerminalInteractiveShell.colors = 'Linux'
IPython.start_ipython(config=c)

Embedding IPython Shells

Embed an IPython shell within existing code for interactive debugging and exploration.

def embed(header='', compile_flags=None, **kwargs):
    """
    Call this to embed IPython at the current point in your program.
    
    The first invocation of this will create an InteractiveShellEmbed
    instance and then call it. Consecutive calls just call the already
    created instance.
    
    Parameters:
    - header: str, optional - Custom header message to display
    - compile_flags: int, optional - Python compile flags  
    - **kwargs: various, optional - Additional arguments passed to 
               InteractiveShellEmbed constructor
    
    Returns:
    None
    """

Usage example:

import IPython

def debug_function(data):
    processed = []
    for item in data:
        # Drop into IPython for debugging
        IPython.embed(header="Debug point - inspect 'item' and 'processed'")
        result = complex_processing(item)
        processed.append(result)
    return processed

# When called, this will pause execution and open IPython shell
debug_function([1, 2, 3, 4, 5])

Getting Current IPython Instance

Retrieve the currently running IPython instance to programmatically interact with the shell.

def get_ipython():
    """
    Get the currently running InteractiveShell instance.
    
    This function is meant for use within IPython code or code that
    runs within an IPython session. It provides access to the current
    shell instance for programmatic interaction.
    
    Returns:
    InteractiveShell instance or None if not running in IPython
    """

Usage example:

import IPython

# Check if running in IPython
ipython = IPython.get_ipython()
if ipython is not None:
    # Execute code programmatically
    ipython.run_cell("x = 42")
    
    # Access shell features
    ipython.magic('ls')  # Run magic command
    
    # Get user namespace
    user_vars = ipython.user_ns
    print(f"Available variables: {list(user_vars.keys())}")
    
    # Run code with custom namespace
    result = ipython.run_cell("print(f'x = {x}')", store_history=False)
else:
    print("Not running in IPython")

Kernel Embedding (Deprecated)

Legacy function for embedding IPython kernels (deprecated in favor of ipykernel).

def embed_kernel(module=None, local_ns=None, **kwargs):
    """
    Embed and start an IPython kernel in a given scope.
    
    This is a deprecated alias for ipykernel.embed.embed_kernel(),
    to be removed in the future. Import directly from ipykernel.embed.
    
    Parameters:
    - module: types.ModuleType, optional - Module to load into IPython globals
    - local_ns: dict, optional - Namespace to load into IPython user namespace  
    - **kwargs: various, optional - Arguments for IPKernelApp constructor
    
    Returns:
    None
    """

Types

class InteractiveShell:
    """
    Core interactive shell implementation providing execution environment,
    history management, completion, and object introspection.
    """
    
    def run_cell(self, raw_cell, store_history=True, silent=False, shell_futures=True):
        """
        Execute a code cell.
        
        Parameters:
        - raw_cell: str - Code to execute
        - store_history: bool - Whether to store in history
        - silent: bool - Whether to suppress output
        - shell_futures: bool - Whether to return ExecutionResult
        
        Returns:
        ExecutionResult object
        """
    
    def complete(self, text, line=None, cursor_pos=None):
        """
        Perform tab completion on text.
        
        Parameters:
        - text: str - Text to complete
        - line: str, optional - Full line of text
        - cursor_pos: int, optional - Cursor position
        
        Returns:
        tuple: (text, matches) where matches is list of completions
        """
    
    def object_inspect(self, oname, detail_level=0):
        """
        Get information about an object.
        
        Parameters:
        - oname: str - Object name
        - detail_level: int - Level of detail (0 or 1)
        
        Returns:
        dict: Object information
        """

class TerminalInteractiveShell(InteractiveShell):
    """
    Terminal-based interactive shell with advanced terminal features
    including syntax highlighting, keyboard shortcuts, and history.
    """
    
    def __init__(self, **kwargs):
        """Initialize terminal shell with configuration."""

Install with Tessl CLI

npx tessl i tessl/pypi-ipython

docs

configuration-utilities.md

core-shell.md

display-system.md

extension-system.md

index.md

magic-system.md

terminal-interface.md

tile.json