Python SDK

The Python SDK generated from the OpenAPI document (bimworks on the BIM.works Python index) — the package, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.

The Python SDK is generated from the OpenAPI document: one API class per group of operations, one method per operation, and a pydantic model per request and response. It talks HTTPS through urllib3.

Package#

Package bimworks on https://pypi.bim.works/simple/, version equal to your BIM.works server in its Python spelling (3.0.0b120) (Python)
Python 3.9 or later
Module bimworks: every API class and model is importable from it (bimworks.IFCApi, bimworks.QueryRequest)
Dependencies pydantic 2, urllib3 2, python-dateutil and typing-extensions, from pypi.org

Connect and log in#

An ApiClient holds a Configuration with the address of your instance's OpenAPI root (BIM_WORKS_ADDRESS/openapi); every API class is made from it. The login, LoginWithApiToken with your API token, answers an AuthResult, a wrapper whose actual_instance is the Auth object; its var_base64 (the JSON's base64) is the auth token. Setting it as the configuration's access_token makes every later call send it.

import json

import bimworks

# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
    bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64

# 2. The request
# (GetRootNodeUuid takes no request)

# 3. The call
result = bimworks.FsApi(client).get_root_node_uuid()

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

Every example in four steps#

Every example on these pages and on the operation pages of the API part is a complete script in the same four steps (reference/sdk#example-shape):

  1. Connect — the client, logged in as above. An operation that needs no login (the logins, GetApplicationVersion) skips the login.
  2. The request — Model.from_json(json) makes the request from the JSON with the wire names that the operation's page shows, in a raw string, so nothing in it is escaped. Multipart operations take their form fields as keyword arguments instead; a file is its path.
  3. The call — bimworks.Api(client).method(request).
  4. The result — client.sanitize_for_serialization(result), which gives the wire names, printed as JSON; a file is written to disk, and a call without a result prints Done.

So the same JSON goes into every language, and copying an example is enough once the package is installed. With several calls, keep one client and repeat steps 2 to 4.

Classes#

ClassGroupMethods
ActionsApiActionsadd_action, delete_action, get_action, list_actions, undelete_action, update_action
LinkedDataApiLinked dataadd_link_targets, confirm_link_match, delete_linked_data, download_linked_data, end_link, get_linked_data, get_linked_data_counts, get_linked_data_policy, link_data, list_linked_data, reattach_link, replace_linked_data, restore_linked_data, unlink_data, update_linked_data
ModelApiModeladd_model_with_url, augment_bcf, download, download_ifc_xml, export_geometry, export_vector_svg, get_checkin, get_validation_report, lookup_model_hashes, render, schema_conversion_report, upload_model
AccountApiAccountchange_password, get_settings, list_reference_values, logout, register, request_password_reset, request_validation_email, save_settings, sign_out_other_sessions, validate_email_address
IFCApiIFC - Industry Foundation Classescheck, commit_transaction, compare_models, compare_objects, delete_compare_pair_override, export_compare_result, get_compare_bul, get_compare_result, get_match_candidates, get_object_history, get_version_changes, list_building_storeys, list_compare_pair_overrides, map_qids, parse_query, query, record_upload_as_transaction, resolve_bvl, set_compare_pair_override, text_search, upgrade_syntax
GISApiGIS - Geographic Information Systemscopy_geo_reference, export_city_gml3, extract_geo_reference, generate3_d_tiles_url, get_geo_reference, set_geo_reference
AuthApiAuth - Authenticationcreate_anonymous_token, create_api_token, create_nodes_token, create_recursive_node_token, create_versions_token, delete_api_token, get_session, list_api_tokens, login_anonymous, login_with_anonymous_token, login_with_api_token, login_with_username_password, update_api_token
FsApiFs - FileSystemcreate_node, delete_node, delete_node_error, delete_version, download_as_zip, get_node, get_root_node_uuid, get_version, list_node_errors, list_nodes, list_nodes_recursive, list_versions, move_node, undelete_node, update_node, update_version
WorkspacesApiWorkspacescreate_workspace, delete_workspace, list_workspaces, publish_workspace, update_workspace
InfoApiInfoget_application_version
ViewerApiViewerget_geometry_meta_data
AdminApiAdminlist_account_user_features, list_accounts, list_organizations
AIApiAI - Artificial Intelligencetext_to_action
VersionsApiVersionsversion
ModelsRequests and responses289 model classes

A model's attributes are snake_case Python names; from_json, from_dict, to_dict and to_json read and write the wire names. Build a request with from_json rather than from a dict passed to the method: only from_json picks a model identifier's subclass by its type, and with a dict the identifier loses its uuid. A key the model does not have is dropped, so use the names on the models page.

Errors#

A call that the server answers with an error status raises bimworks.ApiException, or one of its subclasses in bimworks.exceptions (BadRequestException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException): status is the HTTP status and body the server's error (Errors).

Python#
try:
    bimworks.IFCApi(client).query(request)
except bimworks.ApiException as e:
    print(e.status, e.body)

Files#

  • Downloads return bytes, the whole file in memory. For a large file, the …_without_preload_content variant of a method (download_without_preload_content) returns the HTTP response to stream from; it does not raise on an error status, so check status yourself.
  • Uploads take a path (or bytes); the SDK reads the whole file into memory.

Pages#

  • Java SDKThe Java SDK generated from the OpenAPI document (Maven nl.bimbase.bimworks:sdk) — the artifact, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
  • .NET SDKThe .NET SDK generated from the OpenAPI document (NuGet BIMworks.Sdk) — the package, connecting and logging in, the four steps of every example, the API classes and models, responses and errors, files and uploads.
  • TypeScript SDKThe TypeScript and JavaScript SDK generated from the OpenAPI document (npm @bimworks/sdk) — installation, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
  • PHP SDKThe PHP SDK generated from the OpenAPI document (Composer bimbase/bimworks) — the package, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
  • Python SDKThe Python SDK generated from the OpenAPI document (bimworks on the BIM.works Python index) — the package, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.