Skip to main content

nucleus-python PyPI PyPI - Python Version

We tried to make it as simple as possible to report the data you need to analyze your app usage and improve it.

This module is compatible with Python 3+.

To start using this module, sign up and get an app ID on Nucleus.sh.

Installation

$ pip install nucleus-python

Basic usage

Add the following code to import Nucleus and init the analytics.

Don't use the import ... from syntax as you won't be able to set the module options like app_id.

import nucleus

nucleus.app_id = 'your app id'

nucleus.set_props({
	'version': '0.5.0', # Set app version (Nucleus cannot detect it)
	'userId': 'richard_hendrix'
})

nucleus.app_started()

Only use app_started() once per session, if you are using Nucleus in several files call app_started() the earliest possible.

Sign up and get a tracking ID for your app here.

Options

You can init Nucleus with options:

nucleus.report_interval = 20 # interval (in seconds) between server com
nucleus.disable_tracking = False # completely disable tracking
nucleus.debug = False # Show internal logs to help debug
nucleus.auto_user_id = False # Assign the user an ID

Identify users

You can track specific users actions on the 'User Explorer' section of your dashboard by assigning an user ID.

It can be any value as long as it is a string.

nucleus.set_user_id('someUniqueUserId')

Alternatively, set the auto_user_id option of the module to True to automatically assign the user an ID based on his username and hostname.

Modify automatic data

You can overwrite some properties or fill data that wasn't detected.

You have to do it before calling app_started() for this to work

It is a good idea to set your app version directly as Nucleus cannot detect it for the moment.

nucleus.set_props({
	'version': '0.5.0',
	'locale': 'en_US'
})

Track custom data

You can also add custom data along with the automatic data.

Those will be visible in your user dashboard if you previously set an user ID.

The module will remember past properties so you can use nucleus.set_props multiple times without overwriting past props.

Properties can either numbers, strings or booleans. Nested properties or arrays aren't supported at the moment.

nucleus.set_props({
	"age": 34,
	"name": 'Richard Hendricks',
	"job": 'CEO'
})

To overwrite past properties, set the second parameter to True.

nucleus.set_props({
	"age": 23
}, True)

Errors

To catch errors with Nucleus, simply add the tracking code to an exception and pass the exception as the unique parameter.

Nucleus will extract the relevant informations and show them in your dashboard.

try:
    my_app()
except Exception as e:
	nucleus.track_error(e)

Add this at the outermost level of your code to handle any otherwise uncaught exceptions before terminating.

The advantage of except Exception over the bare except is that there are a few exceptions that it wont catch, most obviously KeyboardInterrupt and SystemExit.

Events

After initializing Nucleus, you can send your own custom events.

nucleus.track("PLAYED_TRACK")

They are a couple event names that are reserved by Nucleus: init, error: and nucleus:.

You shouldn't report events containing these strings.

Tracking with data

You can add extra information to tracked events, as an object.

Properties can either numbers, strings or booleans.

Nested properties or arrays aren't supported at the moment.

Example:

nucleus.track("PLAYED_TRACK", data = {
	"trackName": 'My Awesome Song',
	"duration": 120
})

Toggle tracking

This will completely disable any communication with Nucleus' servers.

To opt-out your users from tracking:

nucleus.disable_tracking()

and to opt back in:

nucleus.enable_tracking()

This doesn't persist after restarts so you have to handle saving the setting.


Contact hello@nucleus.sh for any inquiry

Metadata

Release files for nucleus-python 0.3.0

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

Built distribution (wheel)

Table of built distributions (wheels) for nucleus-python 0.3.0
File Interpreter ABI Platform Actions
nucleus_python-0.3.0-py3-none-any.whl Python 3 none any Details for nucleus_python-0.3.0-py3-none-any.whl

Release files / nucleus_python-0.3.0-py3-none-any.whl

Download URL nucleus_python-0.3.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25aa367d8e7c1bbc3a923e24173a24bb9db014023a298d149b285d146321e9ae
BLAKE2b-256 checksum
How to use checksums
d737742306955d3288d487a13f113510d57e391c89e6df7bdebb448acf311852
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Security for nucleus-python 0.3.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