Skip to main content
# `expylain`

`expylain` is a Python package for Jupyter notebooks that enables rapid
interactive exploration of random processes. It is designed for ease-of-use in
learning contexts.

## Example

`expylain` works by taking `Data` and defining `Step`s that work on the data.
Each `Step` is just a Python function that takes in data from the previous
`Data` or `Step`. `Data` and its `Steps` are grouped in a `Process`.

For example, to flip a coin that lands heads with probability `p`:

```python
from random import random

def flip(coin, p=0.5):
return coin[0] if random() < p else coin[1]

Process([
Data(['H', 'T']),
Step(flip),
])
```

**Output:**

```
Data: ['H', 'T']
|
flip |
v
'H'

[Rerun]
```

The real power of `expylain` results when using its built-in support for
interactive functions:

```python
Process([
Data(['H', 'T']),
# Specify a (start, end, step) for the arg p
Step(flip, p=(0, 1, 0.1)),
])
```

**Output:**

```
Data: ['H', 'T']
|
flip | p: 0 --- | ---- 1 [0.5]
|
v
'H'

[Rerun]
```

This allows you to interact and visualize random processes:

```python
from random import choices
from bqplot import pyplot as plt

def flip_n(coin, p=0.5, n=100):
return choices(coin, weights=[p, 1-p], k=n)

def plot_flips(flips):
heads, tails = flips.count('H'), flips.count('T')
plt.bar(['H', 'T'], [heads, tails])

Process([
Data(['H', 'T']),
Step(flip_n, p=(0, 1, 0.1), n=(50, 500, 50)),
Step(plot_flips),
])
```

**Output:**

```
Data: ['H', 'T']
|
flip_n | p: 0 --- | --- 1 [0.5]
| n: 50 --- | --- 500 [100]
|
v
['H', 'T', ..., 'H']
|
plot_flips|
v

<bar_chart>

[Rerun]
```

Processes can be composed, giving high expressivity. The `Repeat` constructor
allows the output of multiple runs of a process to become an input to a next
step:

```python
def count_heads(flips):
return flips.count('H')

heads_in_n_flips = Process([
Data(['H', 'T']),
Step(flip_n, p=(0, 1, 0.1), n=(50, 500, 50))
Step(count_heads)
],
name='heads_in_n_flips',
)

distribution_of_heads = Process([
Repeat(heads_in_n_flips, times=1000),
Step(plt.hist),
])
```

**Output:**

```
+-------------------------------------------+
| Data: ['H', 'T'] |
| | |
| flip_n | p: 0 --- | --- 1 [0.5] |
| | n: 50 --- | --- 500 [100] |
| | |
| v | heads_in_n_flips
| ['H', 'T', ..., 'H'] |
| | |
| count_heads | |
| v |
| 48 |
+-------------------------------------------+
|
Repeat(1000) |
v
[48, 49, ..., 50]
|
|
v
<histogram>

[Rerun]
```

## Getting Started

Run these commands in your terminal to install `expylain` and its Jupyter
extension:

```
pip install expylain
jupyter nbextension enable --py --sys-prefix expylain
```


Metadata

Release files for expylain 0.0.1

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

Built distribution (wheel)

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

Release files / expylain-0.0.1-py3-none-any.whl

Download URL expylain-0.0.1-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21184c3f48f8e0bdc745f2e95b140c792763c540a33c5a4a89c0da6b029b3c33
BLAKE2b-256 checksum
How to use checksums
65f11a80af397bb6084938633adc7ef77dbc54d938c343a89256e9f3a65d345f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for expylain 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

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