A Python library and command-line interface for interacting with the Open Science Framework
npx @tessl/cli install tessl/pypi-osfclient@0.0.0A Python library and command-line interface for interacting with the Open Science Framework (OSF). OSFClient enables researchers and developers to programmatically upload, download, and manage large datasets and research files through both Python APIs and CLI commands, supporting scientific workflows and collaborative research projects.
pip install osfclientfrom osfclient import OSFFor version information:
from osfclient import __version__from osfclient import OSF
# Initialize with authentication
osf = OSF(username='your_username', password='your_password')
# Or use token authentication
osf = OSF(token='your_personal_access_token')
# Get a project
project = osf.project('project_id')
print(f"Project: {project.title}")
# Access default storage
storage = project.storage()
# List all files
for file in storage.files:
print(f"File: {file.path}, Size: {file.size}")
# Download a file
with open('local_file.txt', 'wb') as f:
remote_file = next(storage.files) # Get first file
remote_file.write_to(f)
# Upload a file
with open('local_upload.txt', 'rb') as f:
storage.create_file('remote_path.txt', f)Command-line usage:
# Set up project configuration
osf init
# List all files
osf ls
# Download all files
osf clone
# Download specific file
osf fetch remote/path.txt local/file.txt
# Upload file
osf upload local/file.txt remote/path.txtOSFClient is built around a hierarchical model structure:
This design mirrors the OSF platform's structure, providing intuitive navigation from projects down to individual files while supporting both programmatic access and command-line operations.
Core Python library functionality for programmatic access to OSF projects, including authentication, project management, and file operations.
class OSF:
def __init__(self, username=None, password=None, token=None): ...
def login(self, username=None, password=None, token=None): ...
def project(self, project_id): ...
def guid(self, guid): ...Project, storage, file, and folder management classes for navigating and manipulating OSF project structures.
class Project:
def storage(self, provider='osfstorage'): ...
@property
def storages(self): ...
class Storage:
def create_file(self, path, fp, force=False, update=False): ...
def create_folder(self, name, exist_ok=False): ...
@property
def files(self): ...Full-featured CLI for OSF operations including project setup, file listing, downloading, uploading, and URL generation.
osf init # Set up project configuration
osf clone [output] # Download all files
osf fetch <remote> [local] # Download specific file
osf list # List all files
osf upload <source> <destination> # Upload file or directory
osf remove <target> # Remove file
osf geturl <remote> # Get download URLUtility functions for path handling, file operations, and custom exception classes for error handling.
def norm_remote_path(path): ...
def split_storage(path, default='osfstorage'): ...
def checksum(file_path, hash_type='md5', block_size=65536): ...
class OSFException(Exception): ...
class UnauthorizedException(OSFException): ...