Skip to main content

Python SDK

The Python SDK bundles a couple of tools based on the Python libs:

If you are interested instead of creating your own tools using the above libraries, you are kindly referred to those repositories themselves.

Installation from PyPi

You can install these tools through pip:

pip install crownstone-sdk

Installation from source

You can install these tools through pip also locally by:

git clone https://github.com/crownstone/crownstone-python-sdk
cd crownstone-python-sdk
pip install .

Tool arguments

These tools are meant to be used as quick-access to common functionality. They are standalone binaries that work as is. Again, for examples on how to use the libraries, go to the above repositories.

The tool configuration can be done through files in this repository and name them exactly like this:

  • tool_config.json
    • You can find a template of this in the tools/config folder. Fill it with your settings in order for all tools to work.
  • key_file.json
    • You can choose to use a key_file.json in a different location on your computer if you don't want to put keys in a repository (even though tool_config.json is in .gitignore). You can configure your tool_config to do this.

It is also possible to use command line arguments which will override the values in any file:

  --help                   show this help message and exit
  --bleAdapterAddress [I]  bleAdapterAddress of the BLE chip you want to use (linux only). This is usually a mac address.
  --keyFile KEYFILE        the json file with key information
  --configFile CONFIGFILE  the json file with config information

Tool config

This is the tool config format. It is shown in config/tool_config.template.json.

Obtaining keys

Go to my.crownstone and copy the access token to your clipboard. Click of the Crownstone REST API explorer, and set your access tokes. Now you are able to make calls to the API.

To get your sphere keys go to the users/me tab, click the try it out button, and copy your ID from the response body. With this ID you can access your keys on the /users/{id}/keysV2 tab. Fill your ID into the form and the response body should display the keys and key types. These have to be formatted like shown bellow.

{
  "absolutePathToKeyFile": null,
  "keys": {
    "admin":              "adminKeyForCrown",
    "member":             "memberKeyForHome",
    "basic":              "basicKeyForOther",
    "serviceDataKey":     "MyServiceDataKey",
    "localizationKey":    "aLocalizationKey",
    "meshApplicationKey": "MyGoodMeshAppKey",
    "meshNetworkKey":     "MyGoodMeshNetKey"
  },
  "bleAdapterAddress": null
}

absolutePathToKeyFile

If this is defined, the keys are ignored. The tool will look for a key_file at that path instead.

keys

These are the keys that belong to your sphere. They are used to decrypt the advertisements and to encrypt the communication during connections.

bleAdapterAddress

The bleAdapterAddress of the BLE chip you want the library to use.

Key file

This is the format of the key_file.json. You can use it via the absolutePathToKeyFile config or via the keyFile command line argument.

{
  "admin":              "adminKeyForCrown",
  "member":             "memberKeyForHome",
  "basic":              "basicKeyForOther",
  "serviceDataKey":     "MyServiceDataKey",
  "localizationKey":    "aLocalizationKey",
  "meshApplicationKey": "MyGoodMeshAppKey",
  "meshNetworkKey":     "MyGoodMeshNetKey"
}

commandLine arguments

These arguments are available for all tools. A tool may have different arguments as well, those are listed as additional parameters below the tool.

command                       explanation
--bleAdapterAddress bleAdapterAddress of the BLE chip you want to use (linux only). This is usually a mac address.
--keyFile The json file with key information, expected values: admin, member, guest, basic, serviceDataKey, localizationKey, meshApplicationKey, and meshNetworkKey
--configFile The json all data required to configure the tools. See the template file or the definition above for more information.

Available tools

Currently, available tools are:

cs_scan_any_crownstone --verbose [--macFilter filter]

This will scan for any available BLE (Bluetooth Low Energy) device.

  • Parameters
    • verbose: Optionally show full advertisement, not just a single line summary.
    • macFilter(string): Optionally only filter for specific MAC address (e.g. AA:BB:CC:DD:EE:FF).
cs_scan_known_crownstone --verbose [--macFilter filter]

This will scan for any Crownstone in your sphere. This requires the keys you set to match those on the Crownstones.

  • Parameters
    • verbose: Optionally show full advertisement, not just a single line summary.
    • macFilter(string): Optionally only filter for specific MAC address (e.g. AA:BB:CC:DD:EE:FF).
cs_switch_crownstone [--bleAddress address] --switchTo state

This will switch a Crownstone in your sphere. This requires the keys you set to match those on the Crownstones.

  • Parameters
    • bleAddress(string): Optionally. The MAC address of the Crownstone that you want to switch (e.g. AA:BB:CC:DD:EE:FF). Required if you do not switch via broadcast.
    • switchTo(integer): Set the switch state. Between 0 and 100 is dimming (0 is off, 100 is fully on). Set to 255 to switch to what the "behaviour rules" on the Crownstones want it to be.
cs_upload_microapp --bleAddress address --file binaryFile

This will upload a microapp.

  • Parameters
    • bleAddress(string): Required MAC address of the Crownstone that you want to upload microapp to (e.g. AA:BB:CC:DD:EE:FF).
    • file(string): Required binary file (.bin) of the microapp to be uploaded.
cs_enable_microapp --bleAddress address

This will enable a microapp. Required if a microapp is not yet been enabled or has been disabled.

  • Parameters
    • bleAddress(string): Required MAC address of the Crownstone that you want to upload microapp to (e.g. AA:BB:CC:DD:EE:FF).

Metadata

Release files for crownstone-sdk 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crownstone-sdk 1.0.0
File Size Uploaded Provenance
crownstone-sdk-1.0.0.tar.gz 19.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for crownstone-sdk 1.0.0
File Interpreter ABI Platform
crownstone_sdk-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 55.4 kB

Release files / crownstone-sdk-1.0.0.tar.gz

Download URL crownstone-sdk-1.0.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5e7377bd748ee8366f7ee844520e7a630b8c49ba4c68347dff1d72ff69cd5540
BLAKE2b-256 checksum
How to use checksums
c773c060bb604663da7c38ebd933c7c1d44b67db35f73628bbcb464b1f9ce5d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.9

Release files / crownstone_sdk-1.0.0-py3-none-any.whl

Download URL crownstone_sdk-1.0.0-py3-none-any.whl
Size 35.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bdb471da688aea191aadd0ffffe975dc63d027fc91d93097ff11de36a0b4fbe4
BLAKE2b-256 checksum
How to use checksums
421438d1bd733049ab8f44ac10105a8e8474f2e42c990e230105702295950585
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.9

Security for crownstone-sdk 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page