Skip to main content

Developer utilities and AI engineering tools by Mohit Khare — code snippets, model helpers, and dev productivity.

Project description

mohitkhare

Developer utilities and AI engineering tools by Mohit Khare -- practical helpers for text processing, LLM token estimation, and everyday dev productivity.

Install

pip install mohitkhare

Text Utilities

from mohitkhare import slugify, truncate, chunk_text, reading_time

# URL-safe slugs
slugify("My Blog Post Title!")       # 'my-blog-post-title'
slugify("Cafe & Restaurant -- Paris") # 'cafe-restaurant-paris'

# Smart truncation
truncate("Long article text here...", 15)  # 'Long article...'

# Chunk text for LLM processing (splits on sentence boundaries)
chunks = chunk_text(long_document, max_chars=4000, overlap=200)

# Reading time estimate
reading_time("word " * 500)  # '2 min read'

LLM Token Estimation

Estimate token counts and API costs without importing heavy tokenizers.

from mohitkhare import estimate_tokens, estimate_cost

# Token estimation (character-based heuristic)
estimate_tokens("Hello, how are you?")                    # 5
estimate_tokens("Long prompt " * 100, model="claude")     # ~336

# Cost estimation
estimate_cost("A " * 10000, model="gpt-4o")               # '$0.0050'
estimate_cost("Short text", model="claude-haiku")          # '$0.0000'
estimate_cost("Output text", model="gpt-4o", is_output=True)

Supports: GPT-4o, GPT-4, GPT-3.5, Claude (Opus/Sonnet/Haiku), Gemini, Llama, Mistral.

Dev Productivity

from mohitkhare import timer, retry, flatten, chunk_list, dedupe

# Time function execution
@timer
def slow_function():
    ...  # prints "slow_function took 1.234s"

# Retry with exponential backoff
@retry(max_attempts=3, delay=1.0, backoff=2.0)
def flaky_api_call():
    ...

# Flatten nested lists
flatten([[1, 2], [3, [4, 5]]])  # [1, 2, 3, 4, 5]

# Chunk lists for batch processing
chunk_list(range(10), 3)  # [[0,1,2], [3,4,5], [6,7,8], [9]]

# Dedupe preserving order
dedupe([3, 1, 2, 1, 3])                # [3, 1, 2]
dedupe(["a", "A", "b"], key=str.lower)  # ['a', 'b']

Links

License

MIT

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

mohitkhare-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mohitkhare-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file mohitkhare-0.1.0.tar.gz.

File metadata

  • Download URL: mohitkhare-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mohitkhare-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a0b2430da5989e92644e054cd8e59dd9aad95e7266e6ccb59d3723ed98433ff6
MD5 4c9650ed67d83507719d7f6c9f45fc1f
BLAKE2b-256 e9d6e4dccf8b0806e28937628f6757effc3da032ec8b153b867cf24fe012ed3a

See more details on using hashes here.

File details

Details for the file mohitkhare-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mohitkhare-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mohitkhare-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5f0d1ecf7912c430a52f16028af004bb221bb84285d40f8202ed1a13508240a
MD5 0e3b62c03e9efcb62007a4f632948d56
BLAKE2b-256 d5c3c487bfb42646ffa955aa8bdd1e8e194fe623631cea89f2233dd3d304fccf

See more details on using hashes here.

Supported by

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