Python
Install the bimworks package from the private Python index with uv, Poetry or pip, pinned to that index, and check that it imports.
For Python developers. The Python SDK is one of the OpenAPI SDKs (SDKs): it is generated from the OpenAPI document, like the PHP SDK, and is published on the private index https://pypi.bim.works/simple/. Your company portal has the credentials, or ask support@bimbase.nl.
Before you start#
- Python 3 and one of uv, Poetry or pip.
- Credentials for
https://pypi.bim.works.
1. Pin the package to the BIM.works index#
The client depends on public packages (pydantic, urllib3 and a few more), so pypi.org stays configured as well. Your tool must take bimworks itself from the BIM.works index only: a tool that merges what both indexes offer installs whichever has the highest version, and a look-alike package on another index would then win. Each of the three setups below pins the package; never use a bare --extra-index-url for it.
uv#
[project]
dependencies = ["bimworks==3.0.0"]
[[tool.uv.index]]
name = "bimworks"
url = "https://pypi.bim.works/simple/"
explicit = true
[tool.uv.sources]
bimworks = { index = "bimworks" }explicit = true means only packages that name the index come from it. Give uv the credentials in the environment (or in ~/.netrc):
export UV_INDEX_BIMWORKS_USERNAME='[your username]'
export UV_INDEX_BIMWORKS_PASSWORD='[your password]'
uv syncuv.lock records the file's address and hash; commit it.
Poetry#
[[tool.poetry.source]]
name = "bimworks"
url = "https://pypi.bim.works/simple/"
priority = "explicit"
[tool.poetry.dependencies]
bimworks = { version = "3.0.0", source = "bimworks" }poetry config http-basic.bimworks '[your username]' '[your password]'pip#
pip cannot pin one package to one index. Use a requirements file in which every line carries the hash of the file it allows, made against the BIM.works index (for example with pip-compile --generate-hashes from pip-tools), so that any other file is refused. Keep the credentials in ~/.netrc rather than in the index address:
machine pypi.bim.works
login [your username]
password [your password]pip install --require-hashes --index-url https://pypi.bim.works/simple/ --extra-index-url https://pypi.org/simple/ -r requirements.txt2. Pick the version#
Use the version that matches your BIM.works server (the version pill at the top of this page is the server's), written the Python way: 3.0.0-b.120 is 3.0.0b120. pip and uv skip pre-releases unless you name the exact version or allow them (pip install --pre, uv add --prerelease allow); Poetry needs allow-prereleases = true on the dependency.
Check#
python -c "import bimworks; print(bimworks.__version__)"It prints the version you installed. Then run the program below: it logs in with your API token and prints the UUID of your root node. Every example of the Python SDK has these four steps (reference/sdk/python#example-shape).
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))Next: Log in with an API token.