Quick Start#

This 5-minute tutorial will get you started with bfabricPy by writing your first script.

Prerequisites#

Before starting, make sure you have:

  1. Installed bfabricPy: Follow Installation Guide

  2. Logged in: run bfabric-cli login, or see the Configuration Guide for the other options


Your First Script#

Create a file called my_first_script.py:

from bfabric import Bfabric

# Connect to B-Fabric (uses your config file)
client = Bfabric.connect()

print(f"Connected to: {client.config.base_url}")

# Query for recent workunits
results = client.read(endpoint="workunit", obj={}, max_results=5)

print(f"\nFound {len(results)} recent workunit(s):")
for workunit in results:
    print(f"  - ID: {workunit['id']}, Status: {workunit.get('status', 'N/A')}")

Run it:

python my_first_script.py

Expected output:

Connected to: https://fgcz-bfabric-test.uzh.ch/bfabric

Found 5 recent workunit(s):
  - ID: 321802, Status: FINISHED
  - ID: 321801, Status: FINISHED
  - ID: 321800, Status: FAILED
  - ID: 321799, Status: RUNNING
  - ID: 321798, Status: FINISHED

What Just Happened?#

Let’s break down the script:

from bfabric import Bfabric

Import the main Bfabric class.

client = Bfabric.connect()

Connect using your configuration from ~/.bfabricpy.yml.

results = client.read(endpoint="workunit", obj={}, max_results=5)

Query B-Fabric for workunits. Returns a ResultContainer object.

for workunit in results:
    print(workunit)

Iterate over results like a list.

Note: By default, queries raise an error automatically if they fail. See Error Handling to learn about error handling options.


Explore the API#

Use bfabric-cli api inspect to discover available endpoints, parameters, and data structures:

bfabric-cli api inspect resource
bfabric-cli api inspect workunit
bfabric-cli api inspect dataset

See API Inspection Guide for complete documentation on using the inspect command.


What’s Next?#

Now that you’ve seen the basics, explore further:

Want to…

Read this guide

Understand client authentication

Connecting

Query and retrieve data efficiently

Reading Data

Create, update, delete entities

Writing Data

Use typed entities with relationships

Working with Entities

Explore API endpoints

API Inspection Guide

See Also#