JupyterLabApiClient 1.0.1
dotnet add package JupyterLabApiClient --version 1.0.1
NuGet\Install-Package JupyterLabApiClient -Version 1.0.1
<PackageReference Include="JupyterLabApiClient" Version="1.0.1" />
<PackageVersion Include="JupyterLabApiClient" Version="1.0.1" />
<PackageReference Include="JupyterLabApiClient" />
paket add JupyterLabApiClient --version 1.0.1
#r "nuget: JupyterLabApiClient, 1.0.1"
#:package JupyterLabApiClient@1.0.1
#addin nuget:?package=JupyterLabApiClient&version=1.0.1
#tool nuget:?package=JupyterLabApiClient&version=1.0.1
JupyterLab API Client
A comprehensive, type-safe C# wrapper for the JupyterLab Server API with robust authentication, complete test coverage, and professional packaging.
๐ฆ Installation
From NuGet (Recommended)
# 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
Start JupyterLab Server:
pip install jupyterlab jupyter lab --allow-root --ip=0.0.0.0 --port=8888 --no-browserGet Token: Copy token from JupyterLab startup logs or run:
jupyter server listUpdate Test Configuration: Edit
test-config.jsonwith your server detailsRun 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
- Fork the repository
- Create a feature branch
- Make changes with tests
- Ensure all tests pass
- Submit a pull request
๐ License
MIT License - see LICENSE file for details.
๐ Related Links
| Product | Versions 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. |
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.9)
- Microsoft.Extensions.DependencyInjection (>= 9.0.9)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.10)
- Microsoft.Extensions.Http (>= 9.0.9)
- Microsoft.Extensions.Http.Polly (>= 8.0.10)
- Microsoft.Extensions.Logging (>= 9.0.9)
- Microsoft.Extensions.Options (>= 9.0.9)
- Polly (>= 7.2.4)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.9)
- Microsoft.Extensions.DependencyInjection (>= 9.0.9)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.10)
- Microsoft.Extensions.Http (>= 9.0.9)
- Microsoft.Extensions.Http.Polly (>= 8.0.10)
- Microsoft.Extensions.Logging (>= 9.0.9)
- Microsoft.Extensions.Options (>= 9.0.9)
- Polly (>= 7.2.4)
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
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