flutter_colab 0.1.0 copy "flutter_colab: ^0.1.0" to clipboard
flutter_colab: ^0.1.0 copied to clipboard

A Dart/Flutter client for Google Colab by Chinmay Nagar. Execute code, manage files, and control Colab runtimes from desktop apps. No native config required.

flutter_colab #

A Dart and Flutter client for Google Colab sessions.

flutter_colab helps desktop Flutter apps:

  • Authenticate with Google OAuth
  • Assign and manage Colab runtimes
  • Open Jupyter sessions and execute Python code
  • Stream stdout/stderr/result output in real time
  • Upload, download, and list files in the Colab runtime

Features #

  • OAuth login and token refresh flow for desktop
  • Runtime assignment with accelerator and variant selection
  • Session creation and kernel readiness handling
  • Real-time execution stream (stdout, stderr, rich results, errors)
  • Convenience execute API for collected final results
  • File operations via Jupyter Contents API
  • Keep-alive support to reduce idle disconnects

Platform support #

The built-in auth implementation (DesktopAuth) targets desktop platforms:

  • macOS
  • Windows
  • Linux

Installation #

Add this to your pubspec.yaml:

dependencies:
	flutter_colab: ^0.1.0

Then run:

flutter pub get

Quick start #

import 'package:flutter_colab/flutter_colab.dart';

Future<void> runCodeOnColab() async {
	final client = ColabClient();

	try {
		await client.login();
		await client.connect(
			variant: RuntimeVariant.defaultVariant,
			accelerator: AcceleratorType.none,
		);
		await client.openSession();

		final result = await client.execute("print('Hello from Colab')");

		if (result.success) {
			if (result.stdout.isNotEmpty) {
				print(result.stdout);
			}
			if (result.result != null) {
				print(result.result!['text/plain']);
			}
		} else {
			print('Execution failed: ${result.error}');
		}
	} finally {
		await client.disconnect();
		client.close();
	}
}

OAuth credentials #

This package does not ship with hardcoded OAuth credentials.

Important: any shared/test credentials found online are unofficial and may stop working at any time. For production, always create your own OAuth client in your Google Cloud project.

The defaults below are an unofficial client and are not affiliated with Google. Use at your own risk.

Provide credentials in one of these ways:

  1. Pass a custom config at runtime:
const config = ColabConfig(
	clientId: 'YOUR_CLIENT_ID',
	clientSecret: 'YOUR_CLIENT_SECRET',
);

final client = ColabClient(config: config);
  1. Or use Dart defines when running your app:
flutter run \
	--dart-define=COLAB_CLIENT_ID=your_client_id \
	--dart-define=COLAB_CLIENT_SECRET=your_client_secret

Example format only (not real values):

COLAB_CLIENT_ID=your_google_oauth_client_id
COLAB_CLIENT_SECRET=your_google_oauth_client_secret

Do not commit client secrets to source control.

Real-time streaming output #

await for (final output in client.executeStream('for i in range(3): print(i)')) {
	switch (output) {
		case StdoutOutput(:final text):
			print('OUT: $text');
		case StderrOutput(:final text):
			print('ERR: $text');
		case ResultOutput(:final data):
			print('RESULT: ${data['text/plain']}');
		case DisplayDataOutput(:final data):
			print('DISPLAY: $data');
		case ErrorOutput(:final error):
			print('ERROR: $error');
	}
}

File operations #

await client.uploadFile('demo.txt', 'hello colab'.codeUnits);

final files = await client.listFiles(path: '');
print(files.map((f) => f['name']).toList());

final bytes = await client.downloadFile('demo.txt');
print(String.fromCharCodes(bytes));

Configuration #

You can customize auth/client behavior through ColabConfig:

const config = ColabConfig(
	clientId: 'YOUR_CLIENT_ID',
	clientSecret: 'YOUR_CLIENT_SECRET',
	redirectPort: 8085,
	executionTimeout: Duration(seconds: 60),
	keepAliveInterval: Duration(seconds: 60),
);

final client = ColabClient(config: config);

Example app #

A full Flutter desktop demo is included in example/lib/main.dart.

Run it with:

flutter run -d macos -t example/lib/main.dart

Use -d windows or -d linux on those platforms.

Repository #

https://github.com/NagarChinmay/flutter_colab

License #

MIT (see LICENSE).

0
likes
150
points
27
downloads

Documentation

API reference

Publisher

verified publisherchipnexa.in

Weekly Downloads

A Dart/Flutter client for Google Colab by Chinmay Nagar. Execute code, manage files, and control Colab runtimes from desktop apps. No native config required.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, http, shared_preferences, shelf, shelf_router, uuid, web_socket_channel

More

Packages that depend on flutter_colab