PharmaDS 2026 Short Course: Python for Clinical Development with AI Applications
2026-03-23
Three parts of this short course:
Python environment setup (Yuting)
Use uv to create and manage reproducible Python projects. Develop and collaborate in GitHub Codespaces or Visual Studio Code.
Python packages for clinical reporting (Yilong)
Take a guided tour of using Python for TLF creation commonly used in clinical trials and CSR project management.
AI Applications (Eric)
Explore how AI tools can be applied to clinical data analysis and trial design from a statistician’s perspective.
Note
Interested in R? check https://r4csr.org/
The views and opinions expressed in this presentation are those of the individual presenters and do not represent those of their affiliated organizations or institutions.
Note
The toolchain, process, and formats may be different in different organizations. We only provide one common way to address them.
PharmaDS Conference 2026 organizers
Authors of the open source book Python for Clinical Study Reports and Submissions: Yilong Zhang and Nan Xiao
Two recommended options:
GitHub Codespaces
VS Code
Getting started:
. (period) to open VS Code in the browser, orWhat you get:
.devcontainer/devcontainer.json, such as uv, specific VS Code extensions, and any command-line toolsFree tier:
Installation
Additional Recommended Extensions
Python projects rely heavily on rapidly evolving open-source libraries that often have conflicting version requirements.
In contrast, R often uses a single global library for all projects
Python package and project managers are essential because they prevent version conflicts by isolating each project’s specific dependencies into its own dedicated environment.
Key goal: Ensure reproducibility across different machines/platforms and over time, which is critical for regulatory submissions!
Package & Dependency Management
Environment Management
Project Workflow & Automation
Python package building & distribution
uv is a modern Python package and project manager written in Rust.
All-in-One tool that handles Python environments, package dependencies, project maintenance, builds and publishing in a single workflow.
Replaces scattered toolchain:
pip + venv + pyenv + pip-tools + setuptools + poetry…Additional benefits:
pyproject.toml as the single source of truth, which prevents conflicting information scattered across multiple filesuv.lock for to ensure reproducible and deterministic environmentsNote
Skip if using GitHub Codespaces: uv is pre-installed there.
macOS/Linux:
Windows:
Verify:
More installation options here.
Create a new project
Check the created files:
Create the first commit:
Pin Python version
List installed packages (empty at this point)
Add dependencies
Add dev dependencies
Manually edit pyproject.toml to add additional dependencies or dev-dependencies sections, e.g. dependencies = ["scikit-learn", "seaborn","dash"], then try the following commands -
Resolves dependencies:
Sync environment:
Revise the main.py file to test the installed packages, e.g.
Try running the two commands below -
Activate the virtual environment installed by uv
Deactivate the virtual environment when you are done
Update uv itself
Upgrade packages and sync environment
Uninstall packages
For more details, refer to the uv official guide
Conda
Poetry
Ruff - Code formatting and linting
uv run ruff format . # spacing, line breaks, and indentation etc.
uv run ruff format --check . # check whether the code is properly formatted without making changes
uv run ruff check . # check for linting issues (e.g., unused imports, naming conventions, potential bugs) without making changes
uv run ruff check --fix . # Try to automatically fix linting issues where possibleAdd this function to main.py and run ruff to see the formatting and linting suggestions
mypy - Type checking
Add the following code to main.py and run mypy to see the type checking errors
def fun_add(a: int, b: int) -> int:
output = a + b
print("Results:", output)
return output
def fun_concat(s1: str, s2: str) -> str:
output = s1 + s2
print("Results:", output)
return output
def main():
pass
if __name__ == "__main__":
main()
fun_add(1, 2) # correct usage
fun_add(1, "2") # type error, mypy will catch this
fun_concat("Hello, ", "world!") # correct usage
fun_concat("Hello, ", 5) # type error, mypy will catch thispytest - Testing framework
Save the code below to run_pytests.py
Run the following terminal commands to see how pytest works with uv
quarto - Documentation and report generation
Alternative tools:
Virtual environments are mandatory in Python
Dependency locking
uv.lock pins exact versionsrenv.lock.python-version file
3.14.0)Pre-configured GitHub Codespaces:
What’s pre-installed:
uvpolars, plotnine, rtflite, and other clinical reporting related packagesWorkflow inside Codespaces:
eBook: Python for Clinical Study Reports and Submission: pycsr.org
Regulatory:
Technical:
Optional hands-on exercise: Repeat the quick start steps to create a new project and install dependencies with uv in an empty GitHub Codespaces or on your own laptop.
conda create -n myenv python=3.14
conda activate myenv
conda install numpy pandas matplotlib
conda install -c conda-forge polars plotnine
pip install rtflite
conda list
conda update numpy
conda remove matplotlib
conda env export > environment.yml
conda deactivate
conda info --envs // conda env list
conda env remove --name myenvNote
In miniforge, you can swap conda for mamba for faster speed, e.g. mamba install pandas
For modern projects, uv is heavily recommended for its efficiency, while pip remains the standard for basic needs.