Python
- Add and update Customers
- Assign and update Product Plans to Customers
- Send meter events
- In asynchronous batches for high throughput (with optional flush on demand)
- Or synchronously
- Using the Amberflo API or the Amberflo supplied AWS S3 bucket
- Query usage
- Fine grained logging control
- Install the SDK pip install amberflo-metering-python
- Create a customer
4. Ingest meter events
5. Query usage
Amberflo.io libraries are built to support high throughput environments. That means you can safely send hundreds of meter records per second. For example, you can chose to deploy it on a web server that is serving hundreds of requests per second.
However, every call does not result in a HTTP request, but is queued in memory instead. Messages are batched and flushed in the background, allowing for much faster operation. The size of batch and rate of flush can be customized.
Flush on demand: For example, at the end of your program, you'll want to flush to make sure there's nothing left in the queue. Calling this method will block the calling thread until there are no messages left in the queue. So, you'll want to use it as part of your cleanup scripts and avoid using it as part of the request lifecycle.
Error handling: The SDK allows you to set up a on_error callback function for handling errors when trying to send a batch.
Here is a complete example, showing the default values of all options:
If the module detects that it can't flush faster than it's receiving messages, it'll simply stop accepting new messages. This allows your program to continually run without ever crashing due to a backed up metering queue.
The SDK provides a metering.ingest.IngestS3Client so you can send your meter records to us via the S3 bucket.
Use of this feature is enabled if you install the library with the s3 option:
pip install amberflo-metering-python[s3]
Just pass the S3 bucket credentials to the factory function:
General documentation on how to use Amberflo is available at Product Walktrough.
The full REST API documentation is available at API Reference.
Code samples covering different scenarios are available here.
Ingest
Customer
Usage
Exceptions
amberflo-metering-python uses the standard Python logging framework. By default, logging is and set at the WARNING level.
The following loggers are used:
- metering.ingest.producer
- metering.ingest.s3_client
- metering.ingest.consumer
- metering.session.ingest_session
- metering.session.api_session