Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 9932d34

Browse files
authored
Merge pull request #256 from CogStack/trainer-client
Pypi installable Client lib for common trainer functions
2 parents 0b5d871 + 18df430 commit 9932d34

File tree

11 files changed

+1467
-4
lines changed

11 files changed

+1467
-4
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,44 @@ name: ci-build
33
on: [push]
44

55
jobs:
6-
# run tests / lint / etc. before building container image?
6+
# Test and build client library
7+
test-client:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout main
11+
uses: actions/checkout@v4
12+
with:
13+
ref: ${{ github.ref }}
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.10'
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install requests pytest build
24+
25+
- name: Install client package in development mode
26+
run: |
27+
cd client
28+
pip install -e .
29+
30+
- name: Run client tests
31+
run: |
32+
cd client
33+
python -m pytest tests/ -v
34+
35+
- name: Build client package
36+
run: |
37+
cd client
38+
python -m build
739
40+
# Build and test webapp container
841
build-and-push:
942
runs-on: ubuntu-latest
43+
needs: test-client
1044
steps:
1145
- name: Checkout main
1246
uses: actions/checkout@v4

.github/workflows/qa.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,50 @@ on:
55
branches: [ main ]
66

77
jobs:
8-
# run tests / lint / etc. before building container image?
8+
# Test and build client library
9+
test-client:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout main
13+
uses: actions/checkout@v4
14+
with:
15+
ref: 'main'
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.10'
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install requests pytest build
26+
27+
- name: Install client package in development mode
28+
run: |
29+
cd client
30+
pip install -e .
31+
32+
- name: Run client tests
33+
run: |
34+
cd client
35+
python -m pytest tests/ -v
36+
37+
- name: Build client package
38+
run: |
39+
cd client
40+
python -m build
41+
42+
- name: Publish dev distribution to Test PyPI
43+
uses: pypa/[email protected]
44+
with:
45+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
46+
repository_url: https://test.pypi.org/legacy/
947

48+
# Build and test webapp container
1049
build-and-push:
1150
runs-on: ubuntu-latest
51+
needs: test-client
1252
steps:
1353
- name: Checkout main
1454
uses: actions/checkout@v4

.github/workflows/release.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,53 @@ on:
55
tags: ["v*.*.*"]
66

77
jobs:
8-
# run tests / lint / etc. before building container image?
8+
# Test, build and publish client library
9+
test-and-publish-client:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout main
13+
uses: actions/checkout@v4
14+
with:
15+
ref: "main"
16+
17+
- name: Release Tag
18+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: '3.10'
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install requests pytest build twine
29+
30+
- name: Install client package in development mode
31+
run: |
32+
cd client
33+
pip install -e .
34+
35+
- name: Run client tests
36+
run: |
37+
cd client
38+
python -m pytest tests/ -v
39+
40+
- name: Build client package
41+
run: |
42+
cd client
43+
python -m build
44+
45+
- name: Publish production distribution to PyPI
46+
if: startsWith(github.ref, 'refs/tags') && ! github.event.release.prerelease
47+
uses: pypa/[email protected]
48+
with:
49+
password: ${{ secrets.PYPI_API_TOKEN }}
950

51+
# Build and test webapp container
1052
build-and-push:
1153
runs-on: ubuntu-latest
54+
needs: test-and-publish-client
1255
steps:
1356
- name: Checkout main
1457
uses: actions/checkout@v4

client/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
---
3+
4+
# MedCATtrainer Client
5+
6+
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.
7+
8+
## Features
9+
10+
- Manage datasets, concept databases, vocabularies, and model packs
11+
- Create and manage users and projects
12+
- Retrieve and upload project annotations
13+
- Command-line interface (CLI) for automation
14+
15+
## Installation
16+
17+
```sh
18+
pip install mctclient
19+
```
20+
21+
Or, if installing from source:
22+
23+
```sh
24+
cd client
25+
python -m build
26+
pip install dist/*.whl
27+
```
28+
29+
## Python Usage
30+
31+
```sh
32+
export MCTRAINER_USERNAME=<username>
33+
export MCTRAINER_PASSWORD=<password>
34+
```
35+
36+
```python
37+
from mctclient import MedCATTrainerSession, MCTDataset, MCTConceptDB, MCTVocab, MCTModelPack, MCTMetaTask, MCTRelTask, MCTUser, MCTProject
38+
39+
# Connect to your MedCATTrainer instance
40+
session = MedCATTrainerSession(server="http://localhost:8001")
41+
42+
# List all projects
43+
projects = session.get_projects()
44+
for project in projects:
45+
print(project)
46+
47+
# Create a new dataset
48+
dataset = session.create_dataset(name="My Dataset", dataset_file="path/to/data.csv")
49+
50+
# Create a new user
51+
user = session.create_user(username="newuser", password="password123")
52+
53+
# Create a new project
54+
project = session.create_project(
55+
name="My Project",
56+
description="A new annotation project",
57+
members=[user],
58+
dataset=dataset
59+
)
60+
```
61+
62+
### MedCATTrainerSession Methods
63+
64+
- `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=[])`
65+
- `create_dataset(name, dataset_file)`
66+
- `create_user(username, password)`
67+
- `create_medcat_model(cdb, vocab)`
68+
- `create_medcat_model_pack(model_pack)`
69+
- `get_users()`
70+
- `get_models()`
71+
- `get_model_packs()`
72+
- `get_meta_tasks()`
73+
- `get_rel_tasks()`
74+
- `get_projects()`
75+
- `get_datasets()`
76+
- `get_project_annos(projects)`
77+
78+
Each method returns the corresponding object or a list of objects.
79+
80+
## License
81+
82+
This project is licensed under the Apache 2.0 License.
83+
84+
## Contributing
85+
86+
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
87+
88+

client/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)