Add CSV Inventory import to python client#55
Merged
Conversation
The import prevalidation requires the number of unmapped CSV columns to exactly equal the number of custom fields in the target template. The test used a zero-field template but left the 'Comment' column unmapped, so the server returned PREVALIDATION_ERROR. Map 'Comment' to the built-in 'description' field so no template field is required. Also document this column/template-field rule on import_samples_csv. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds Python client support for Inventory CSV import workflows by introducing parse/import methods on InventoryClient, an enum for supported record types, an example script, and integration tests to exercise the new endpoints.
Changes:
- Added
ImportRecordTypeand newInventoryClientmethods to parse CSVs and import samples/containers/subsamples via multipart endpoints. - Added integration tests covering parse + import flows and client-side validation guards.
- Added a runnable example script and documented the feature in the changelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| rspace_client/inv/inv.py | Adds CSV import enum + multipart parse/import methods and convenience wrappers for samples/containers/subsamples. |
| rspace_client/tests/invapi_test.py | Adds integration tests for CSV parse/import and validation error cases. |
| examples/import_inventory_csv.py | Adds a runnable example demonstrating parse + import for all supported record types. |
| CHANGELOG.md | Documents the new CSV import support under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…review) Addresses Copilot review on PR #55: the docstrings state exactly one column must map to 'name' (and, for subsamples, to 'parent sample global id'), but the validation only checked presence. Multiple mappings are silently resolved by the server (last wins), so fail fast client-side instead. Adds a generic _require_single_mapping helper enforcing a count of exactly one, used for 'name' across all import types and for 'parent sample global id' in import_subsamples_csv, plus tests for the duplicate-mapping cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Support importing Inventory CSV files (samples, subsamples, containers)
Closes #32
Summary
Adds client support for the Inventory API's CSV import endpoints, so users can bulk import samples, subsamples and containers from CSV files instead of building records one at a time. The client previously had no way to drive CSV import.
What's new
New
InventoryClientmethods:parse_csv_import_file(file, record_type)import_csv_files(import_settings, containers_file=, samples_file=, subsamples_file=)import_samples_csv(samples_file, field_mappings, template_id=, template_info=)import_containers_csv(containers_file, field_mappings)import_subsamples_csv(subsamples_file, field_mappings)Plus a new
ImportRecordTypeenum (SAMPLES,SUBSAMPLES,CONTAINERS).A
field_mappingsdict maps each CSV column name to an RSpace field name, for example"name","description","quantity","expiry date","identifier","import identifier","parent container import id","parent container global id","parent sample import id","parent sample global id". Map a column toNoneto ignore it.Usage
See the runnable
examples/import_inventory_csv.pyfor samples, containers, and subsamples.Scope and behaviour notes
ImportRecordTypeand in the changelog rather than silently omitted.ValueErrorearly (before any network call) when a required mapping is missing: samples/containers/subsamples must map a column to"name", samples require a template (template_idortemplate_info), and subsamples require a"parent sample global id"mapping.statusofPREVALIDATION_ERRORorREVERTED_ON_ERROR, so these methods return the result dict without raising. Callers should checkresult["status"].json.dumps, so field mappings and template info cannot break the request structure.Endpoints used
POST /api/inventory/v1/import/parseFile(multipartfile+recordType)POST /api/inventory/v1/import/importFiles(multipartcontainersFile/samplesFile/subSamplesFile+importSettings)Tests
Added integration tests in
rspace_client/tests/invapi_test.pyfollowing the existing pattern (skipped automatically without API credentials): parse, import for each record type, subsample import into a pre-existing sample, and the client-side validation guards.Changelog
Added an
Unreleasedentry.