This repository was archived by the owner on Sep 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Pypi installable Client lib for common trainer functions #256
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| uses: pypa/gh-action-pypi-publish@v1.4.2 | ||
| with: | ||
| password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
| repository_url: https://test.pypi.org/legacy/ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably need the absolute path for 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 }} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably need the absolute path for 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.