Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,44 @@ name: ci-build
on: [push]

jobs:
# run tests / lint / etc. before building container image?
# Test and build client library
test-client:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests pytest build

- name: Install client package in development mode
run: |
cd client
pip install -e .

- name: Run client tests
run: |
cd client
python -m pytest tests/ -v

- name: Build client package
run: |
cd client
python -m build

# Build and test webapp container
build-and-push:
runs-on: ubuntu-latest
needs: test-client
steps:
- name: Checkout main
uses: actions/checkout@v4
Expand Down
42 changes: 41 additions & 1 deletion .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,50 @@ on:
branches: [ main ]

jobs:
# run tests / lint / etc. before building container image?
# Test and build client library
test-client:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: 'main'

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests pytest build

- name: Install client package in development mode
run: |
cd client
pip install -e .

- name: Run client tests
run: |
cd client
python -m pytest tests/ -v

- name: Build client package
run: |
cd client
python -m build

- name: Publish dev distribution to Test PyPI
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also use Trusted Publisher to avoid needing a password/secret. Like v2 publish. Though notably, there were some permissions that were also needed.

Not a must have, of course.

uses: pypa/gh-action-pypi-publish@v1.4.2
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need the absolute path for dist here (in with):

          packages-dir: client/dist


# Build and test webapp container
build-and-push:
runs-on: ubuntu-latest
needs: test-client
steps:
- name: Checkout main
uses: actions/checkout@v4
Expand Down
45 changes: 44 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,53 @@ on:
tags: ["v*.*.*"]

jobs:
# run tests / lint / etc. before building container image?
# Test, build and publish client library
test-and-publish-client:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: "main"

- name: Release Tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests pytest build twine

- name: Install client package in development mode
run: |
cd client
pip install -e .

- name: Run client tests
run: |
cd client
python -m pytest tests/ -v

- name: Build client package
run: |
cd client
python -m build

- name: Publish production distribution to PyPI
if: startsWith(github.ref, 'refs/tags') && ! github.event.release.prerelease
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
password: ${{ secrets.PYPI_API_TOKEN }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need the absolute path for dist here (in with):

          packages-dir: client/dist


# Build and test webapp container
build-and-push:
runs-on: ubuntu-latest
needs: test-and-publish-client
steps:
- name: Checkout main
uses: actions/checkout@v4
Expand Down
88 changes: 88 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

---

# MedCATtrainer Client

A Python client for interacting with a MedCATTrainer web application instance. This package allows you to manage datasets, concept databases, vocabularies, model packs, users, projects, and more via Python code or the command line.

## Features

- Manage datasets, concept databases, vocabularies, and model packs
- Create and manage users and projects
- Retrieve and upload project annotations
- Command-line interface (CLI) for automation

## Installation

```sh
pip install mctclient
```

Or, if installing from source:

```sh
cd client
python -m build
pip install dist/*.whl
```

## Python Usage

```sh
export MCTRAINER_USERNAME=<username>
export MCTRAINER_PASSWORD=<password>
```

```python
from mctclient import MedCATTrainerSession, MCTDataset, MCTConceptDB, MCTVocab, MCTModelPack, MCTMetaTask, MCTRelTask, MCTUser, MCTProject

# Connect to your MedCATTrainer instance
session = MedCATTrainerSession(server="http://localhost:8001")

# List all projects
projects = session.get_projects()
for project in projects:
print(project)

# Create a new dataset
dataset = session.create_dataset(name="My Dataset", dataset_file="path/to/data.csv")

# Create a new user
user = session.create_user(username="newuser", password="password123")

# Create a new project
project = session.create_project(
name="My Project",
description="A new annotation project",
members=[user],
dataset=dataset
)
```

### MedCATTrainerSession Methods

- `create_project(name, description, members, dataset, cuis=[], cuis_file=None, concept_db=None, vocab=None, cdb_search_filter=None, modelpack=None, meta_tasks=[], rel_tasks=[])`
- `create_dataset(name, dataset_file)`
- `create_user(username, password)`
- `create_medcat_model(cdb, vocab)`
- `create_medcat_model_pack(model_pack)`
- `get_users()`
- `get_models()`
- `get_model_packs()`
- `get_meta_tasks()`
- `get_rel_tasks()`
- `get_projects()`
- `get_datasets()`
- `get_project_annos(projects)`

Each method returns the corresponding object or a list of objects.

## License

This project is licensed under the Apache 2.0 License.

## Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.


Empty file added client/__init__.py
Empty file.
Loading