NRP Invenio repository python client
The NRP Python Client Library provides a comprehensive API for programmatically interacting with NRP and other Invenio RDM repositories. It enables you to build applications, scripts, and workflows that manage research data, files, and repository operations.
Overview
The library offers both synchronous and asynchronous clients, allowing you to choose the programming model that best fits your use case. Both clients provide high-level abstractions for working with:
- Records: Create, read, update, delete, search, and publish research data records
- Files: Upload, download, manage, and delete files attached to records
- Requests: Handle workflows, approvals, and record lifecycle operations
Key Features
- Dual API: Choose between sync and async clients based on your needs
- Type-safe: Full type annotations for better IDE support and code reliability
- Connection pooling: Efficient HTTP connection management
- Progress tracking: Built-in progress bar support for file operations
- Retry logic: Automatic retry on transient failures
- Multi-repository: Work with multiple repositories simultaneously
- Modern Python: Built for Python 3.12+ with modern patterns
When to Use
Sync Client - Best for:
- Simple scripts and automation tasks
- Command-line tools
- Straightforward data migration
- Learning and experimentation
Async Client - Best for:
- High-performance applications
- Concurrent operations across multiple repositories
- Web applications and APIs
- Large-scale data processing
CLI Tool - For interactive command-line use, consider the nrp-cmd CLI application instead.
Installation
pip install nrp-cmdQuick Examples
Synchronous Client
from nrp_cmd.sync_client import get_sync_client
# Connect to a repository
client = get_sync_client("https://your-repository.org")
# Create a new record
record = client.records.create({
"metadata": {
"title": "My Research Data",
"creators": [{"name": "John Doe"}],
"resource_type": {"id": "dataset"}
}
})
print(f"Created record: {record.id}")Asynchronous Client
import asyncio
from nrp_cmd.async_client import get_async_client
async def main():
# Connect to a repository
client = await get_async_client("https://your-repository.org")
# Create a new record
record = await client.records.create({
"metadata": {
"title": "My Research Data",
"creators": [{"name": "John Doe"}],
"resource_type": {"id": "dataset"}
}
})
print(f"Created record: {record.id}")
asyncio.run(main())Demo code
You can find the demo code for both synchronous and asynchronous clients in the nrp-cmd GitHub repository .
API Documentation and Examples
Comprehensive guides with practical examples for working with the client library:
Synchronous Client
- Sync Client Overview - Getting started with the synchronous API
- Records API - Create, read, update, delete, and search records
- Files API - Upload, download, and manage file attachments
- Requests API - Handle workflows, approvals, and lifecycle operations
Asynchronous Client
- Async Client Overview - Getting started with the async/await API
- Records API - Asynchronously manage records with full examples
- Files API - Concurrent file operations and streaming
- Requests API - Async workflow and approval management