Skip to main content

A set of tools to run nanohub web apis

Project description

Nanohub remote

Stats

Latest Release
PyPI Downloads
Nanohub Tutorial
A set of tools/apps to run on nanohub

Installation

pip install nanohub-remote

Usage

Basic Authentication

import nanohubremote as nr

# Option 1: OAuth Password Grant (requires web application)
auth_data = {
  'client_id': 'XXXXXXXX',
  'client_secret': 'XXXXXXXX',
  'grant_type': 'password',
  'username': 'your_username',
  'password': 'your_password'
}

# Option 2: Personal Access Token (recommended)
auth_data = {
  'grant_type': 'personal_token',
  'token': 'your_personal_token'
}

# to get username and password, register on nanohub.org (https://nanohub.org/register/)
# to get client id and secret, create a web application (https://nanohub.org/developer/api/applications/new), use "https://127.0.0.1" as Redirect URL
# to get a personal token, go to https://nanohub.org/developer/api/tokens

# Create a session
session = nr.Session(auth_data)

# Or use as a context manager (recommended - automatically cleans up resources)
with nr.Session(auth_data) as session:
    # Your code here
    pass

Session Configuration

The Session class supports advanced configuration options:

session = nr.Session(
    auth_data,
    url="https://nanohub.org/api",  # Custom API URL
    timeout=10,                       # Request timeout in seconds (default: 5)
    max_retries=5,                    # Maximum retries for failed requests (default: 3)
    pool_connections=20,              # Connection pool size (default: 10)
    pool_maxsize=20                   # Max pool size (default: 10)
)

HTTP Methods

The Session class provides methods for all standard HTTP verbs:

with nr.Session(auth_data) as session:
    # GET request
    response = session.requestGet('tools/list')
    tools = response.json()

    # POST request with form data
    response = session.requestPost('endpoint', data={'key': 'value'})

    # POST request with JSON
    response = session.requestPost('endpoint', json={'key': 'value'})

    # PUT request
    response = session.requestPut('resource/123', json={'status': 'updated'})

    # DELETE request
    response = session.requestDelete('resource/123')

    # PATCH request
    response = session.requestPatch('resource/123', json={'field': 'new_value'})

Features

  • Connection Pooling: Reuses HTTP connections for better performance
  • Automatic Retries: Automatically retries failed requests (configurable)
  • Token Management: Handles OAuth token refresh automatically
  • Context Manager: Use with statement for automatic resource cleanup
  • Persistent Headers: Headers are maintained across all requests

Development

Running Tests

# Install development dependencies
pip install -r requirements-dev.txt

# Run all tests
pytest

# Run with coverage
pytest --cov=nanohubremote --cov-report=html

# Run specific test file
pytest tests/test_session.py

See tests/README.md for detailed testing documentation.

Available Nanohub Points

Tools

TOOLNAME = '' # valid Nanoohub tool name e.g. pntoy
tool = nr.Tool(auth_data)

# Get Available input parameters
params = tool.getToolParameters(TOOLNAME)

# Submit a simulation experiment
job_id = tool.submitTool(params)

# Check Status
status = tool.checkStatus(job_id['job_id'])

# Get Results
results = tool.getResults(job_id['job_id'])

# Submit an wait for results
results = tool.submitTool(params, wait_results=True)

Sim2Ls

TOOLNAME = '' # valid Nanoohub tool name e.g. pntoy
s2l = nr.Sim2L(auth_data)

# Get Available input parameters
params = s2l.getToolParameters(TOOLNAME)

# Submit a simulation experiment
job_id = s2l.submitTool(params)

# Check Status
status = s2l.checkStatus(job_id['job_id'])

# Get Results
results = s2l.getResults(job_id['job_id'])

# Submit an wait for results
results = s2l.submitTool(params, wait_results=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanohub_remote-0.2.1.tar.gz (510.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nanohub_remote-0.2.1-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file nanohub_remote-0.2.1.tar.gz.

File metadata

  • Download URL: nanohub_remote-0.2.1.tar.gz
  • Upload date:
  • Size: 510.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for nanohub_remote-0.2.1.tar.gz
Algorithm Hash digest
SHA256 311af2703cab8593064cfee4d18c05a0c22f9eb7ebc0927e476adfea4fb21068
MD5 f42f501288a75af3661e7a74c15cfddd
BLAKE2b-256 5b47db0c4a9ae35a6573e5b38d4cb5c1cf62c1752029552318d2029a7bc91c29

See more details on using hashes here.

File details

Details for the file nanohub_remote-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: nanohub_remote-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for nanohub_remote-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00d5e1c61a310e1601f9bc2cda1ab6124d7508483d267c0552d5ec99b2c84bfd
MD5 c6af22b971c15ff725279cecd7703dd5
BLAKE2b-256 ea871b5b51f542db97dc85475d6354a2b57bcaacbda4ef6c256b5c8095af8db3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page