Jupyter notebook wrapper for EOxElements web components
Project description
EOxElements Jupyter
A Python wrapper for using EOxElements web components inside Jupyter Notebooks.
Built on top of anywidget, this package provides a Pythonic API to visualize Earth Observation data using modern web standards (Custom Elements) directly in your notebook.
Useful Links:
- Demos & Docs: EOxElements Documentation
- Source: GitHub Repository
Features
- Simple Python API: CamelCase Python classes (e.g.,
EOxMap) map automatically to kebab-case HTML tags (<eox-map>). - Auto-generated: Wrappers are generated from the official
custom-elements.jsonmanifest, ensuring API parity. - Version Pinning: Manage specific versions of the underlying JavaScript libraries via a simple configuration file.
- Jupyter Integration: Works in JupyterLab, Jupyter Notebook, and VS Code.
Installation
pip install ipyeoxelements
Note: After installing, you may need to restart your Jupyter kernel/server for the widget extensions to load correctly.
Usage
For a comprehensive walkthrough, check out examples.ipynb included in this repository.
1. Chart (EOxChart)
Pass a Vega-Lite specification dictionary directly to the widget.
from ipyeoxelements import EOxChart
spec_data = {
"$schema": "[https://vega.github.io/schema/vega-lite/v5.json](https://vega.github.io/schema/vega-lite/v5.json)",
"description": "A simple bar chart with embedded data.",
"data": {
"values": [
{"a": "A", "b": 28}, {"a": "B", "b": 55}, {"a": "C", "b": 43},
{"a": "D", "b": 91}, {"a": "E", "b": 81}, {"a": "F", "b": 53},
{"a": "G", "b": 19}, {"a": "H", "b": 87}, {"a": "I", "b": 52},
],
},
"mark": {"type": "bar", "tooltip": True, "fill": "#004170"},
"encoding": {
"x": {"field": "a", "type": "ordinal"},
"y": {"field": "b", "type": "quantitative"},
},
}
# Layout can be passed as a simple dictionary
my_chart = EOxChart(spec=spec_data, layout={"height": "400px"})
display(my_chart)
2. Map (EOxMap)
Define layers using Python lists and dictionaries.
from ipyeoxelements import EOxMap
map_layers = [
{
"type": "STAC",
"properties": {
"id": "stacLayer",
},
"url": "[https://s3.us-west-2.amazonaws.com/sentinel-cogs/sentinel-s2-l2a-cogs/10/T/ES/2022/7/S2A_10TES_20220726_0_L2A/S2A_10TES_20220726_0_L2A.json](https://s3.us-west-2.amazonaws.com/sentinel-cogs/sentinel-s2-l2a-cogs/10/T/ES/2022/7/S2A_10TES_20220726_0_L2A/S2A_10TES_20220726_0_L2A.json)",
},
{
"type": "Tile",
"properties": {"id": "osm", "title": "OSM"},
"source": {"type": "OSM"},
}
]
map = EOxMap(
layers=map_layers,
zoom=7,
center=[-122, 46.5],
layout={"height": "400px"}
)
display(map)
3. Advanced Layout (EOxMap + EOxLayercontrol)
To combine widgets, use standard ipywidgets layout containers like HBox or VBox.
Important: You must link the Layer Control to the Map using the map's id and the controller's for_ argument.
from ipywidgets import HBox, Layout
from ipyeoxelements import EOxMap, EOxLayercontrol
MAP_ID = "my-unique-map-id"
# 1. Create Map
my_map = EOxMap(
id=MAP_ID,
layers=[{"type": "Tile", "source": {"type": "OSM"}}],
center=[16, 48],
zoom=5,
layout=Layout(flex="2", height="400px") # Take up 2/3 width
)
# 2. Create Control linked to Map
control = EOxLayercontrol(
for_=f"#{MAP_ID}", # Must match the Map ID selector
tools=["config"],
layout=Layout(flex="1", height="400px", overflow="auto") # Take up 1/3 width
)
# 3. Display side-by-side
display(HBox([my_map, control]))
Local Development
This package uses a Code Generator (generate.py) to create the Python wrappers based on a configuration file (elements_config.json).
1. Configuration
To add new elements, update versions, or add dependencies, edit elements_config.json:
{
"eox-map": {
"version": "latest",
"dependencies": [],
"extra_imports": ["dist/eox-map-advanced-layers-and-sources.js"]
}
}
Then run the generator to update ipyeoxelements/generated.py:
python generate.py
2. Development Environment
Option A: Jupyter inside Docker (Recommended)
This ensures a clean environment isolated from your system Python.
- Run Jupyter mounting your current directory to
/home/jovyan/work:docker run -p 8888:8888 -v "$(pwd):/home/jovyan/work" jupyter/base-notebook
- Open the link printed in the terminal to access JupyterLab.
- Open a Terminal inside JupyterLab.
- Install the package in Editable Mode:
cd work pip install -e . --break-system-packages
(Note:--break-system-packagesis safe here as it is a disposable container). - Open
examples.ipynband run the cells. If you make changes togenerate.py, run it, then Restart the Kernel to see changes.
Option B: VS Code
You can develop locally using VS Code's native Jupyter support.
- Create a virtual environment:
python -m venv .venv source .venv/bin/activate
- Install dependencies and the package in editable mode:
pip install -e . pip install ipykernel
- Open
examples.ipynbin VS Code. - Click Select Kernel (top right) -> Python Environments -> Select your
.venv. - Run the cells.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ipyeoxelements-1.0.0rc1.tar.gz.
File metadata
- Download URL: ipyeoxelements-1.0.0rc1.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8206b2e604c8f13da85b43563a2e6e3e441287f59a2d515b01403fd561bdee4e
|
|
| MD5 |
9dc97adf013d65d121e92ad6801e7352
|
|
| BLAKE2b-256 |
9778d6dfd119a054452f9d55e2344c2a1b424fec5aed50f6979271d7bab651d2
|
File details
Details for the file ipyeoxelements-1.0.0rc1-py3-none-any.whl.
File metadata
- Download URL: ipyeoxelements-1.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5edc34487e208dcead11c18ddbb15543e056c0aed3ff7e40a52a4e4b76a17662
|
|
| MD5 |
d2f65abf95aa9871f23ad034fb76009f
|
|
| BLAKE2b-256 |
fdb4521d496918811fd28fedfe7e9fca0357a40db2c7864fe3363d0f0b2b3abc
|