Skip to main content

tokenlog

Simplest token log system for your LLM, embedding model calls.

Installation

Get on pypi.

pip install tokenlog

How to use

Start with initializing the logger. Each logger with the same name is singleton.

import tokenlog

t_logger = tokenlog.getLogger('session_1', 'gpt-3.5-turbo') # write logger name and model name that you are using
q1 = t_logger.query('This is the query that you used in LLM') # log the query

t_logger.answer('This is an answer from LLM', q1) # log the answer

t_logger.get_token_usage() # get total token usage from all queries

t_logger.get_history() # get history of token usage

t_logger.clear() # clear all histories

Batch logging

You can log multiple queries and answers at once.

import tokenlog

t_logger = tokenlog.getLogger('session_2', 'gpt-3.5-turbo') # write logger name and model name that you are using
query_ids = t_logger.query_batch(['This is the query that you used in LLM', 'This is the second query'])
t_logger.query(['This is the first answer', 'This is the second answer'], query_ids)

Chat Support

We also support chat format logging. You can use the OpenAI type chat format.

import tokenlog

t_logger = tokenlog.getLogger('session_3', 'gpt-5')
chat1 = t_logger.query([
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"},
])
t_logger.chat([
    {"role": "assistant", "content": "The 2020 World Series was played at Globe Life Field in Arlington, Texas."}
], chat1)

Support Models

We support all OpenAI models with tiktoken and Huggingface models that support AutoTokenizer.

Use Case

This library used in AutoRAG project.

To-do

  • Add Handlers for exporting logs
  • Support more models

Metadata

Release files for tokenlog 0.0.3

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

Source distribution (sdist)

Source distribution for tokenlog 0.0.3
File Size Uploaded Provenance
tokenlog-0.0.3.tar.gz 82.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for tokenlog 0.0.3
File Interpreter ABI Platform
tokenlog-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 88.7 kB

Release files / tokenlog-0.0.3.tar.gz

Download URL tokenlog-0.0.3.tar.gz
Size 82.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c740befdb9ab39bfac36ef122c1f63a52b44e84929a7c08e282502f2abe2bdbb
BLAKE2b-256 checksum
How to use checksums
53cd2e931ee02aa73f5777f089eb8de99885051861e2ed164c0796f2610398b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release files / tokenlog-0.0.3-py3-none-any.whl

Download URL tokenlog-0.0.3-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e7f471b1d509b916848f17b729788cb6ff7aa83f5b27a0ab7060c72c3cbac51
BLAKE2b-256 checksum
How to use checksums
196fd6fe5b804ce96565449a7185bbab717158c93ff95eb75fe61436ac9b59a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Security for tokenlog 0.0.3

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.

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