Wetlands is a lightweight library to create conda environment and execute code inside them.
Project description
Wetlands
Wetlands is a lightweight Python library for managing Conda environments.
Wetlands can create Conda environments on demand, install dependencies, and execute arbitrary code within them. This makes it easy to build plugin systems or integrate external modules into an application without dependency conflicts, as each environment remains isolated.
For example, if your application needs to use both Stardist and Cellpose, installing them in the same environment may not work due to conflicting dependencies. With Wetlands, you can create a dedicated environment for each library and run them both as needed from your main script.
The name Wetlands comes from the tropical environments where anacondas thrive.
Appose Python is a great alternative to Wetlands. It even provides the ability to run Java environments (see Appose Java) and share memory between the Python world and the Java world. There are other minor differences between the two libraries. For example, Wetlands provides integrated debugging tools to attach VS Code or PyCharm to isolated environments for step-through debugging with breakpoints. See the Debugging guide for more information.
Documentation: https://arthursw.github.io/wetlands/latest/
Source Code: https://github.com/arthursw/wetlands/
✨ Features
- Automatic Environment Management: Create and configure environments on demand.
- Dependency Isolation: Install dependencies without conflicts.
- Embedded Execution: Run Python functions or scripts inside isolated environments.
- Integrated Debugging: Debug code running in isolated environments using VS Code or PyCharm with breakpoints and step-through execution.
- Micromamba: Wetlands uses a self-contained
micromambafor fast and lightweight Conda environment handling.
📦 Installation
To install Wetlands, simply use pip:
pip install wetlands
🚀 Usage Example
If the user doesn't have pixi or micromamba installed, Wetlands will download and set it up automatically.
from wetlands.environment_manager import EnvironmentManager
# Initialize the environment manager with a wetlands instance path
# The wetlands_instance_path will contain logs, debug information, and by default the conda installation
# Wetlands will use the existing Pixi or Micromamba installation if available;
# otherwise it will automatically download and install Pixi or Micromamba in a self-contained manner.
environment_manager = EnvironmentManager()
# Create and launch an isolated Conda environment named "numpy"
env = environment_manager.create("numpy", {"pip":["numpy==2.2.4"]})
env.launch()
# Import example_module in the environment, see example_module.py below
minimal_module = env.import_module("minimal_module.py")
# example_module is a proxy to example_module.py in the environment
array = [1,2,3]
result = minimal_module.sum(array)
print(f"Sum of {array} is {result}.")
# You can also run Python scripts directly using run_script()
# env.run_script("script.py", args=("arg1", "arg2"))
# Clean up and exit the environment
env.exit()
with example_module.py as follow:
def sum(x):
import numpy as np
return int(np.sum(x))
See the examples/ folder for more detailed examples.
🐛 Debugging
Wetlands includes tools to debug code running in isolated environments using VS Code or PyCharm. You can set breakpoints, step through code, and inspect variables in real-time.
Quick Debugging Example
# List all running environments and their debug ports
wetlands list
# Attach VS Code to an environment for debugging
wetlands debug -s /path/to/my/project -n my_env
# Or use PyCharm instead
wetlands debug -s /path/to/my/project -n my_env -ide pycharm
# Kill an environment when done
wetlands kill -n my_env
For detailed debugging instructions and workflows, see the Debugging guide.
🔗 Related Projects
🤖 Development
Use uv to easily manage the project.
Check & Format
Check for code errors with uv run ruff check and format the code with uv run ruff format.
Tests
Test wetlands with uv and ipdb: uv run pytest --pdb --pdbcls=IPython.terminal.debugger:TerminalPdb tests
Use --last-failed to only re-run the failures: uv run pytest --pdb --pdbcls=IPython.terminal.debugger:TerminalPdb --last-failed tests
Build and Publish
Build with uv build
Publish with uv publish dist/wetlands-VERSION_NAME*
Generate documentation
The Wetlands documentation is generated with mkdocs-material, mkdocstrings, mike and others.
Install the doc tools with uv pip install ".[docs]".
MkDocs includes a live preview server, so you can preview your changes as you write your documentation. The server will automatically rebuild the site upon saving. Start it with: uv run mkdocs serve.
mike is used to generate multiple versions of the docs. To create a new version, mike deploy [version] is used by Github Actions, just update .github/workflows/ci.yml.
The doc is automatically generated by Github Actions (see .github/workflows/ci.yml).
The script scripts/gen_ref_pages.py is used by mkdocs to generate the API reference automatically (see mkdocstrings recipes).
📋 Todo
- Use Pixi features and environment instead of creating one workspace per environment.
📜 License
This project was made by the SAIRPICO team at Inria in Rennes (Centre Inria de l'Université de Rennes) and is licensed under the MIT License.
The logo Wetland was made by Dan Hetteix from Noun Project (CC BY 3.0).
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 wetlands-0.4.11.tar.gz.
File metadata
- Download URL: wetlands-0.4.11.tar.gz
- Upload date:
- Size: 111.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff21178b55c74c07b74b11be6d86411f58193493d14ea61a77d38e208abc2339
|
|
| MD5 |
59ca98e1487333d0162356862f556312
|
|
| BLAKE2b-256 |
57f737f98fe55577afb4755cac96e642923688785b79f2066b710b4c3b9f3b38
|
File details
Details for the file wetlands-0.4.11-py3-none-any.whl.
File metadata
- Download URL: wetlands-0.4.11-py3-none-any.whl
- Upload date:
- Size: 52.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff9610c8d8d8a6d2540605e01216363dc7485dfd768dfe5b68218f1bcffd420c
|
|
| MD5 |
8be761663f0277384ea57929725a9901
|
|
| BLAKE2b-256 |
ee9a6bf1aa244f3d05cca1f1ea6857efe7c46775a889c881f351317355eabe73
|