Skip to main content

A library for inspecting local LLM providers and tokenizers.

Project description

LocalGrid

A simple Python library to inspect and get metadata for local LLMs, like token limits and token counts.

I built this because I needed a way to get accurate info for local models without having to make any web calls. All the data and tokenizers are bundled directly into the package.

localgrid on PyPI

Supports Python >=3.8

Key Features

  • Fully Local: No internet connection needed after installation.
  • Accurate Token Counting: Uses the real tokenizer for a given model, not just a guess.
  • Bundled Tokenizers: All the necessary tokenizer files are included in the package.
  • Simple API: Just a few functions to get what you need.

Data Source

The model data (like context limits) was gathered by scraping and formatting information from Ollama and lm-studios public model library's. This data is saved in a JSON file (localgrid_cache.json) inside the package.

view the models

or just visit ollama and lm-studio

Installation

pip install localgrid

Quick Start & Usage

The library has three main functions you'll probably use.

1. get_context_limit

Gets the total context size (token limit) for a model.

from localgrid import get_context_limit

# Get the context limit for llama3.1:latest
limit = get_context_limit("llama3.1:latest")#ollama format

print(f"llama3.1:latest limit: {limit}")
# Output: llama3.1:latest limit: 131072

2. count_tokens

Counts the number of tokens in a string for a specific model. It loads the correct tokenizer to give you an accurate count.

from localgrid import count_tokens

text = "This is a test sentence for my model."
model = "google/gemma-3-12b"#lm-studio format

token_count = count_tokens(text, model)

print(f"The text has {token_count} tokens according to {model}.")
# The text has 9 tokens according to google/gemma-3-12b.

3. preload_tokenizers (optional async)

Due to the decision to keep this package fully offline capable there is a little delay when initially loading tokenizers from disk.

If you're using this in a server and want to avoid a tiny delay on the first call, you can preload the tokenizers into memory when your app starts.

import asyncio
from localgrid import preload_tokenizers

async def main():
    # Preloads all 25 base tokenizers
    await preload_tokenizers()
    
    # Or just preload specific ones
    await preload_tokenizers(families=["llama", "gemma"])

if __name__ == "__main__":
    asyncio.run(main())

Licensing & Included Tokenizers

All included tokenizer files are bundled with their original licenses (ex: LICENSE and tokenizer_config.json). You can find these within the installed package.

Note: Due to licensing restrictions, the following tokenizer families are not included in this package:

  • command-r
  • stablelm2
  • codestral

As a result they default to generic tokenizers

If someone knows more about me than this please let me know and I will add them ASAP

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

localgrid-0.1.1.tar.gz (65.6 MB view details)

Uploaded Source

Built Distribution

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

localgrid-0.1.1-py3-none-any.whl (67.1 MB view details)

Uploaded Python 3

File details

Details for the file localgrid-0.1.1.tar.gz.

File metadata

  • Download URL: localgrid-0.1.1.tar.gz
  • Upload date:
  • Size: 65.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.3

File hashes

Hashes for localgrid-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b8acea611e7fc8e0b2a2b53cef3f78ac9be3e35967499165a2aa7dd9da55d3cc
MD5 bba1ba07a2b3d98db0be0f908b2b8b0d
BLAKE2b-256 98b9f05db10d02d58ec54cdc2056e874eb437a8107e2f4a7ef5745fcb3745302

See more details on using hashes here.

File details

Details for the file localgrid-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: localgrid-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 67.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.3

File hashes

Hashes for localgrid-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bfbe6e6d0e848d10109d19d77b729d7235bba28880ed5002e2adafda98a6ba6f
MD5 15c19d9de488ae0a8b5288e3f6948bd4
BLAKE2b-256 aeb2763f7ea30f63ad9daaae1fee627bcefb77c29ece53aec9c20af759ee89dc

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