Installation & Setup¶
This guide covers everything you need to install and start using CANFAR Science Platform servers worldwide.
New to Canfar?
If you want to jump right in with a hands-on tutorial, check out our 5-Minute Quick Start guide first!
Prerequisites¶
Before you can use canfar, you need:
- Python 3.10+ installed on your system
- A Science Platform account - For CANFAR, request an account with CADC
Installation¶
Install canfar using pip
:
pip install canfar --upgrade
Virtual Environments
We recommend using a virtual environment to avoid conflicts with other packages:
python -m venv canfar-env
source canfar-env/bin/activate # On Windows: canfar-env\Scripts\activate
pip install canfar
Authentication Setup¶
Canfar uses an authentication context system to manage connections to multiple Science Platform servers. The easiest way to get started is with the CLI login command.
Quick Authentication¶
To authenticate with a Science Platform server:
canfar auth login
This command will:
- Discover available servers worldwide
- Guide you through server selection
- Handle the authentication process (X.509 or OIDC)
- Save your credentials for future use
Example Login Flow
$ canfar auth login
Starting Science Platform Login
Discovery completed in 2.1s (5/18 active)
Select a Canfar Server:
ยป ๐ข CANFAR CADC
๐ข Canada SRCnet
๐ข UK-CAM SRCnet
X509 Certificate Authentication
Username: your-username
Password: ***********
โ Login completed successfully!
Using Canfar Programmatically¶
Once authenticated via CLI, you can use Canfar in your Python code:
from canfar.session import Session
from canfar.images import Images
# Uses your active authentication context
session = Session()
images = Images()
# List available images
container_images = images.fetch()
print(f"Found {len(container_images)} container images")
# Create a notebook session
session_info = session.create(
kind="notebook",
image="images.canfar.net/skaha/base-notebook:latest",
name="my-analysis",
cores=2,
ram=4
)
print(f"Created session: {session_info.id}")
Private Container Images¶
To access private container images from registries like CANFAR Harbor, provide registry credentials:
from canfar.models import ContainerRegistry
from canfar.session import Session
# Configure registry access
registry = ContainerRegistry(
username="your-username",
password="**************"
)
# Use with session
session = Session(registry=registry)
# Now you can use private images
session_info = session.create(
kind="notebook",
image="images.canfar.net/private/my-image:latest",
cores=1,
ram=2
)
Registry Credentials
The registry credentials are base64 encoded and passed to the server via the X-Skaha-Registry-Auth
header.
Next Steps¶
Now that you have canfar installed and configured:
- Try our 5-Minute Quick Start for a hands-on introduction to creating and managing sessions.
- Learn about Authentication Contexts for managing multiple servers and advanced authentication scenarios.
- Explore Basic Examples and Advanced Examples for common use cases.
- Check out the Python API Reference for detailed documentation of all available methods.
- Refer to the FAQ for answers to common questions.
Getting Help
- ๐ฌ Community Discussions
- ๐ Report Issues