Skip to main content

Umami Analytics Client for Python

Project description

Umami Analytics Client for Python

Client for privacy-preserving, open source Umami analytics platform based on httpx and pydantic.

umami-analytics is intended for adding custom data to your Umami instance (self-hosted or SaaS). Many umami events can supplied directly from HTML via their data-* attributes. However, some cannot. For example, if you have an event that is triggered in your app but doesn't have a clear HTML action you can add custom events. These will appear at the bottom of your Umami analtytics page for a website.

One example is a purchase-course event that happens deep inside the Python code rather than in HTML at Talk Python Training. This is what our events section looks like for a typical weekend day (US Pacific Time):

Focused on what you need, not what is offered

The Umami API is extensive and much of that is intended for their frontend code to be able to function. You probably don't want or need that. umami-analytics only covers the subset that most developers will need for common SaaS actions such as adding custom events. That said, PRs are weclome.

Core Features

  • Add a custom event to your Umami analtyics dashboard.
  • 🌐 List all websites with details that you have registered at Umami.
  • 🔀 Both sync and async programming models.
  • ⚒️ Structured data with Pydantic models for API responses.
  • 👩‍💻 Login / authenticate for either a self-hosted or SaaS hosted instance of Umami.
  • 🥇Set a default website for a simplified API going forward.

See the usage example below for the Python API around these features.

Async or sync API? You choose

🔀 Async is supported but not required for your Python code. For functions that access the network, there is a func() and func_async() variant that works with Python's async and await.

Installation

Just pip install umami-analytics

Usage

import umami

umami.set_url_base("https://umami.hostedbyyouorthem.com")
login = umami.login(username, password)

# Skip the need to pass the target website in subsequent calls.
umami.set_website_id('cc726914-8e68-4d1a-4be0-af4ca8933456')
umami.set_hostname('somedomain.com')

# List your websites
websites = umami.websites()

# Create a new event in the events section of the dashboards.
event_resp = umami.new_event(
    website_id=sit'a7cd-5d1a-2b33', # Only send if overriding default above
    event_name='Umami-Test',
    title='Umami-Test', # Defaults to event_name if omitted.
    hostname='somedomain.com', # Only send if overriding default above.
    url='/users/actions',
    custom_data={'client': 'umami-tester-v1'},
    referrer='https://some_url')

# Call after logging in to make sure the auth token is still valid.
umami.verify_token()

This code listing is very-very high fidelity psuedo code. If you want an actually executable example, see the example client in the repo.

Want to contribute?

See the API documentation for the remaining endpoints to be added. PRs are welcome. But please open an issue first to see if the proposed feature fits with the direction of this library.

Enjoy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

umami_analytics-0.1.10.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

umami_analytics-0.1.10-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file umami_analytics-0.1.10.tar.gz.

File metadata

  • Download URL: umami_analytics-0.1.10.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.26.0

File hashes

Hashes for umami_analytics-0.1.10.tar.gz
Algorithm Hash digest
SHA256 352939494530fb14aabe00d58e3d350b509044cc987238dd1e72896054261765
MD5 e5d44fa1fc8e6d597dceff8fd626a17a
BLAKE2b-256 5e449f68f35b9488b2a3c42684fcd476fa0255b643c88455ba918374917c2f02

See more details on using hashes here.

File details

Details for the file umami_analytics-0.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for umami_analytics-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 c018f2a6217a5c246e41b5f67d0dea620b5ac01c2945381bcc9fca6ed50b79e2
MD5 7dbe2d2d8d43c5dc0a724ffbe82c3a30
BLAKE2b-256 243d3e75bbbae5432e7f1f027a7730b90cd81546d67e705d35b60ec97036526a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page