A Python library for interacting with the Measurely API
Project description
Measurely-py
Measurely-py is a lightweight Python library for interacting with the Measurely API, enabling developers to manage and track custom metrics programmatically using Python.
Installation
To use the Measurely package in your Python project, you can install it using pip:
pip install measurely-py
Usage
1. Initialize the Measurely package
Before you can send any metrics to Measurely, you need to initialize the package with your API key. The init method accepts your API key as a string and sets it for use in subsequent API calls.
from measurely import Measurely
# Initialize the Measurely package with your API key
Measurely.init("YOUR_API_KEY")
2. Send a Metric (Capture)
The capture method is used to send metric data to Measurely. You need to pass the metric identifier (which is a unique name or ID for the metric) and the metric value you want to track.
Example of sending a metric
from measurely import Measurely, CapturePayload
# Initialize the Measurely package with your API key
Measurely.init("YOUR_API_KEY")
# Create a metric payload
payload = CapturePayload(value=42)
# Capture the metric and get the result
result = Measurely.capture("example_metric", payload)
# Handle the result
if result["success"]:
print("Metric captured successfully!")
else:
print(f"Error capturing metric: {result['message']}")
3. Error Handling
The capture method returns a CaptureResult dictionary that contains two fields:
success(bool): Indicates if the API call was successful.message(str): Contains the response message from the server, which could either be a success message or an error message.
API Reference
init(NEW_API_KEY: str)
- Description: Initializes the Measurely package with your API key.
- Parameters:
NEW_API_KEY: The API key provided by Measurely.
- Returns: None.
capture(metric_identifier: str, payload: CapturePayload) -> CaptureResult
- Description: Sends a metric value to Measurely for tracking.
- Parameters:
metric_identifier: The unique identifier for the metric you are capturing.payload: ACapturePayloadobject that contains the metric value to be recorded.
- Returns: A
CaptureResultdictionary that contains the success status and response message.
Types
CapturePayload
from typing import TypedDict
class CapturePayload(TypedDict):
value: int # The metric value to be recorded.
- Description: This class defines the data payload that is sent to the Measurely API when capturing a metric.
- Fields:
value(int): The metric value that you want to track.
CaptureResult
class CaptureResult(TypedDict):
success: bool # Indicates if the API call was successful
message: str # Contains the server's response or an error message
- Description: This class represents the result of the API call to capture a metric.
- Fields:
success(bool): Indicates if the metric capture was successful.message(str): Contains the server's response or an error message.
Contributing
Contributions are welcome! Please open an issue or submit a pull request to improve the library.
License
This library is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file measurely_py-0.1.6-py3-none-any.whl.
File metadata
- Download URL: measurely_py-0.1.6-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c899c107f1742e8915dfcad56011f4d90b9f0b9e45e499aa7034167e0137e1c4
|
|
| MD5 |
85e86ba6f7415dcd44c56f182d02513b
|
|
| BLAKE2b-256 |
85e0557e54b3606737c6681f1c8debb5a7c37a00ddcf8c4b55ae530e9a96ca3c
|
Provenance
The following attestation bundles were made for measurely_py-0.1.6-py3-none-any.whl:
Publisher:
publish.yml on Measurely-dev/measurely-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
measurely_py-0.1.6-py3-none-any.whl -
Subject digest:
c899c107f1742e8915dfcad56011f4d90b9f0b9e45e499aa7034167e0137e1c4 - Sigstore transparency entry: 158419634
- Sigstore integration time:
-
Permalink:
Measurely-dev/measurely-py@dc0cd0d72c88db0ae73356d5baed200059f7d820 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/Measurely-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dc0cd0d72c88db0ae73356d5baed200059f7d820 -
Trigger Event:
release
-
Statement type: