
Research
/Security News
Fake imToken Chrome Extension Steals Seed Phrases via Phishing Redirects
Mixed-script homoglyphs and a lookalike domain mimic imToken’s import flow to capture mnemonics and private keys.
danai
Advanced tools
Danai is a comprehensive utility package designed to streamline interactions with OpenAI models. It offers a suite of tools for various tasks including token counting, pricing calculations, quick queries, directory summarisation, and JSON response management.
Danai simplifies the process of moving between different output types – particularly with structured data – and assists with managing and analysing token usage and costs associated with OpenAI's powerful language models.
To install Danai, use pip:
pip install danai
Count tokens in a text file:
from danai import tokencount_file
token_count = tokencount_file("path/to/textfile.txt", model="gpt-4o")
print(f"Token count: {token_count}")
Count tokens in a text string:
from danai import tokencount_text
text = "Your text here"
token_count = tokencount_text(text, model="gpt-4o")
print(f"Token count: {token_count}")
Calculate the cost of tokens generated by an OpenAI model:
from danai import pricecheck
response = ... # Your OpenAI API response object
cost_details = pricecheck(response)
print(cost_details)
Generate a quick response from an OpenAI model and print it:
from danai import quickprint
prompt = "Your prompt here"
quickprint(prompt, model="gpt-4o-mini")
Print the contents of a directory while ignoring certain files and directories:
from danai import print_directory_contents
print_directory_contents(
directory="path/to/directory",
output_dir="path/to/output",
ignore_dirs=[".git", "__pycache__"],
ignore_files=[".DS_Store"],
ignore_extensions=[".pyc"]
)
Generate a directory tree:
from danai import print_directory_tree
print_directory_tree(
directory="path/to/directory",
output_dir="path/to/output",
ignore_dirs=[".git", "__pycache__"]
)
Join summaries of directory contents and tree:
from danai import join_summaries
join_summaries(output_directory="path/to/output")
Save an OpenAI API response as a JSON file:
from danai import jsonsave
response = ... # Your OpenAI API response object
jsonsave(response, filename="response", directory="outputs", overwrite=False, pretty=True, price=True)
Danai provides several command-line interface (CLI) tools for convenience:
To count tokens in a text file using the CLI:
tcount path/to/textfile.txt --model gpt-4o
To print setup information using the CLI:
danai printsetup
OPENAI_API_KEY is set as an environment variable. This key is necessary for authenticating with the OpenAI API.To set the OPENAI_API_KEY environment variable on a Mac, you can add the following line to your .bash_profile or .zshrc file:
export OPENAI_API_KEY="your_openai_api_key"
Then, reload your profile:
source ~/.bash_profile # or source ~/.zshrc
We welcome contributions from the community! If you would like to contribute to Danai, please follow these steps:
Please ensure that your code adheres to the project's coding standards and includes appropriate tests.
This project is licensed under the MIT License. See the LICENSE file for details.
Aidan Coughlan - dev@farfromavocados.com
FAQs
A utility package for simplifying interactions with OpenAI models.
We found that danai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Mixed-script homoglyphs and a lookalike domain mimic imToken’s import flow to capture mnemonics and private keys.

Security News
Latio’s 2026 report recognizes Socket as a Supply Chain Innovator and highlights our work in 0-day malware detection, SCA, and auto-patching.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.