JupyterLabApiClient 1.0.1

dotnet add package JupyterLabApiClient --version 1.0.1
                    
NuGet\Install-Package JupyterLabApiClient -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JupyterLabApiClient" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JupyterLabApiClient" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="JupyterLabApiClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JupyterLabApiClient --version 1.0.1
                    
#r "nuget: JupyterLabApiClient, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JupyterLabApiClient@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JupyterLabApiClient&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=JupyterLabApiClient&version=1.0.1
                    
Install as a Cake Tool

JupyterLab API Client

A comprehensive, type-safe C# wrapper for the JupyterLab Server API with robust authentication, complete test coverage, and professional packaging.

Build Status NuGet Version Code Coverage License: MIT

๐Ÿ“ฆ Installation

# Install via Package Manager
Install-Package JupyterLabApiClient

# Install via .NET CLI
dotnet add package JupyterLabApiClient

# Install via PackageReference
<PackageReference Include="JupyterLabApiClient" Version="1.0.0" />

From Source

git clone https://github.com/saeedmaghdam/jupyterlab-wrapper.git
cd jupyterlab-wrapper
dotnet build JupyterLabApiClient.sln
dotnet pack --configuration Release

๐Ÿ Quick Start

1. Basic Setup with Dependency Injection

using JupyterLabApiClient.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var host = Host.CreateDefaultBuilder()
    .ConfigureServices(services =>
    {
        services.AddJupyterLabClient(options =>
        {
            options.BaseUrl = "http://localhost:8888";
            options.Token = "your-jupyter-token-here";
            options.ValidateSslCertificate = false; // For local development
            options.Timeout = TimeSpan.FromSeconds(30);
        });
    })
    .Build();

var client = host.Services.GetRequiredService<IJupyterLabClient>();

2. Test Connection and Get Server Info

// Test connection
bool isConnected = await client.TestConnectionAsync();
if (!isConnected)
{
    Console.WriteLine("Could not connect to JupyterLab server");
    return;
}

// Get server information
var serverInfo = await client.GetServerInfoAsync();
Console.WriteLine($"JupyterLab Version: {serverInfo.Version}");

// Get server status
var status = await client.GetServerStatusAsync();
Console.WriteLine($"Active Connections: {status.Connections}");
Console.WriteLine($"Running Kernels: {status.Kernels}");

3. Get Current User Information

var userInfo = await client.GetCurrentUserAsync();
Console.WriteLine($"saeedmaghdam: {userInfo.Identity.saeedmaghdam}");
Console.WriteLine($"Display Name: {userInfo.Identity.DisplayName}");

// Check permissions
foreach (var permission in userInfo.Permissions)
{
    Console.WriteLine($"{permission.Key}: [{string.Join(", ", permission.Value)}]");
}

โš™๏ธ Configuration

Options Pattern Configuration

public class JupyterLabOptions
{
    public string BaseUrl { get; set; } = string.Empty;
    public string Token { get; set; } = string.Empty;
    public TimeSpan Timeout { get; set; } = TimeSpan.FromMinutes(5);
    public int MaxRetryAttempts { get; set; } = 3;
    public TimeSpan RetryDelay { get; set; } = TimeSpan.FromSeconds(1);
    public bool ValidateSslCertificate { get; set; } = true;
    public Dictionary<string, string> AdditionalHeaders { get; set; } = new();
    public bool EnableDetailedLogging { get; set; } = false;
}

Configuration from appsettings.json

{
  "JupyterLab": {
    "BaseUrl": "https://your-jupyter-server.com",
    "Token": "your-long-secure-token",
    "Timeout": "00:05:00",
    "MaxRetryAttempts": 3,
    "ValidateSslCertificate": true,
    "AdditionalHeaders": {
      "User-Agent": "MyApp/1.0"
    },
    "EnableDetailedLogging": false
  }
}
// In Program.cs
services.AddJupyterLabClient(
    configuration.GetSection(JupyterLabOptions.SectionName)
);

๐Ÿ” Authentication

The client supports token-based authentication (Bearer tokens). Get your token from JupyterLab:

# Start JupyterLab and get token from URL
jupyter lab

# Or list running servers to get token
jupyter server list

Custom Token Provider

public class CustomTokenProvider : ITokenProvider
{
    public async Task<string> GetTokenAsync(CancellationToken cancellationToken = default)
    {
        // Custom token retrieval logic
        return await GetTokenFromSomewhereAsync();
    }
    
    public async Task<bool> IsTokenValidAsync(CancellationToken cancellationToken = default)
    {
        // Custom token validation logic
        return await ValidateTokenAsync();
    }
    
    public async Task<string?> RefreshTokenAsync(CancellationToken cancellationToken = default)
    {
        // Custom token refresh logic (if supported)
        return await RefreshTokenAsync();
    }
}

// Register custom token provider
services.AddJupyterLabClient<CustomTokenProvider>(
    options => { /* configure */ },
    serviceProvider => new CustomTokenProvider()
);

๐Ÿงช Examples and Samples

The repository includes comprehensive examples demonstrating various usage patterns:

Console Application (samples/ConsoleApp/)

A complete console application showing:

  • Configuration loading from appsettings.json
  • Dependency injection setup
  • Basic API operations (connection, server info, user data)
  • Error handling and logging
  • Interactive demonstrations
cd samples/ConsoleApp
dotnet run

Web API Application (samples/WebApp/)

An ASP.NET Core web application featuring:

  • RESTful API endpoints with Swagger documentation
  • Health checks and monitoring endpoints
  • Dashboard API combining multiple data sources
  • Async operations and parallel processing
  • Production-ready error handling
cd samples/WebApp
dotnet run
# Open https://localhost:5001 for Swagger UI

Quick Start Example

# Update token in appsettings.json first, then:
cd src/JupyterLabApiClient.Examples.ConsoleApp
dotnet run

๐Ÿ—๏ธ Project Structure

src/
โ”œโ”€โ”€ JupyterLabApiClient/           # Main library
โ”‚   โ”œโ”€โ”€ Client/                    # Core client implementation
โ”‚   โ”œโ”€โ”€ Configuration/             # Options and DI setup  
โ”‚   โ”œโ”€โ”€ Authentication/            # Token providers and handlers
โ”‚   โ”œโ”€โ”€ Models/                    # Request/response DTOs
โ”‚   โ”œโ”€โ”€ Exceptions/                # Custom exceptions
โ”‚   โ””โ”€โ”€ Utils/                     # Utility helpers
โ”œโ”€โ”€ JupyterLabApiClient.Tests/     # Unit and integration tests
โ””โ”€โ”€ JupyterLabApiClient.Examples.ConsoleApp/  # Legacy example

samples/
โ”œโ”€โ”€ ConsoleApp/                    # Console application example
โ”‚   โ”œโ”€โ”€ Program.cs                 # Main application with DI
โ”‚   โ”œโ”€โ”€ appsettings.json          # Configuration example
โ”‚   โ””โ”€โ”€ README.md                  # Setup instructions
โ””โ”€โ”€ WebApp/                        # Web API application example
    โ”œโ”€โ”€ Controllers/               # API controllers
    โ”œโ”€โ”€ Program.cs                 # Web application setup
    โ”œโ”€โ”€ appsettings.json          # Web configuration
    โ””โ”€โ”€ README.md                  # API documentation

.github/workflows/                 # CI/CD automation
โ”œโ”€โ”€ ci.yml                        # Main build and test pipeline
โ”œโ”€โ”€ dependency-update.yml         # Automated dependency updates
โ””โ”€โ”€ release.yml                   # Release automation

packages/                          # Generated NuGet packages
โ””โ”€โ”€ JupyterLabApiClient.1.0.0.nupkg

๐Ÿ”ง Development

Prerequisites

  • .NET 6.0 or .NET 8.0 SDK
  • JupyterLab server for testing
  • Git for source control

Build and Test

# Clone repository
git clone https://github.com/saeedmaghdam/jupyterlab-wrapper.git
cd jupyterlab-wrapper

# Restore dependencies
dotnet restore

# Build solution
dotnet build JupyterLabApiClient.sln --configuration Release

# Run all tests
dotnet test JupyterLabApiClient.sln --configuration Release

# Generate test coverage report
dotnet test --collect:"XPlat Code Coverage" --results-directory ./coverage

# Pack NuGet packages
dotnet pack --configuration Release --output ./packages

Local Development Setup

  1. Start JupyterLab Server:

    pip install jupyterlab
    jupyter lab --allow-root --ip=0.0.0.0 --port=8888 --no-browser
    
  2. Get Token: Copy token from JupyterLab startup logs or run:

    jupyter server list
    
  3. Update Test Configuration: Edit test-config.json with your server details

  4. Run Example Application:

    cd src/JupyterLabApiClient.Examples.ConsoleApp
    dotnet run
    

Test Coverage

The project maintains comprehensive test coverage across all components:

  • Configuration Tests: Options validation, dependency injection setup
  • Authentication Tests: Token providers, retry mechanisms, security
  • Core Client Tests: API communication, error handling, timeouts
  • Integration Tests: End-to-end scenarios with live JupyterLab server
  • Utility Tests: Path handling, JSON serialization, extensions

Current Coverage: 182/182 tests passing (100% success rate)

CI/CD Pipeline

The project uses GitHub Actions for automated testing and publishing:

  • Continuous Integration: Automated testing on multiple .NET versions
  • Code Quality: CodeQL security analysis and code coverage reporting
  • Dependency Management: Automated dependency updates via Dependabot
  • Release Automation: Automated NuGet publishing on version tags
  • Documentation: Automated API documentation generation

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make changes with tests
  4. Ensure all tests pass
  5. Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 180 9/30/2025
1.0.0 166 9/29/2025

v1.0.1 - Critical Bug Fixes
     โ€ข Fixed HttpClient base address mismatch between JupyterLabClient and BaseService
     โ€ข Resolved circular dependency causing application freezing during startup
     โ€ข Fixed JSON deserialization error in GetCurrentUserAsync with Permissions model
     โ€ข Improved dependency injection configuration with shared HttpClient approach
     
     v1.0.0 - Initial release
     โ€ข Complete JupyterLab Server API wrapper
     โ€ข Authentication and security features
     โ€ข Resilience patterns (retry, circuit breaker, timeout)
     โ€ข HTTP response caching
     โ€ข Rate limiting capabilities
     โ€ข Comprehensive configuration options
     โ€ข Full test coverage