Quick Start#
This 5-minute tutorial will get you started with bfabricPy by writing your first script.
Prerequisites#
Before starting, make sure you have:
Installed bfabricPy: Follow Installation Guide
Configured credentials: Follow Configuration Guide
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()
Create a client 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 |
|
Query and retrieve data efficiently |
|
Create, update, delete entities |
|
Use typed entities with relationships |
|
Explore API endpoints |
See Also#
Installation Guide - Installation options
Configuration Guide - Config file structure and options
API Inspection Guide - Discovering API endpoints and parameters
Creating a Client - Authentication methods
Troubleshooting - Common issues and solutions