openai / tiktoken

tiktoken is a fast BPE tokeniser for use with OpenAI's models.
MIT License
11.6k stars 783 forks source link

Adding a __version__ attribute #190

Open rasbt opened 11 months ago

rasbt commented 11 months ago

It would be nice to add a __version__ attribute similar to other Python projects, so that we can easily query the version for reproducibility reasons. I.e.,

import tiktoken
print(tiktoken.__version__)
hauntsaninja commented 11 months ago

Sure, I could consider adding this. Note you can use importlib.metadata.version("tiktoken")

rasbt commented 11 months ago

Thanks for the response. Yes, this works. I was just mentioning the additional .__version__ attribute since it is a common convention in the Python scientific computing ecosystem (SciPy, PyTorch, NumPy, matplotlib, ...).

Since you are using a .toml, it's actually probably best to use the following code you suggested itself

import importlib.metadata

__version__ = importlib.metadata.version("mypackage")

and just add it to the __init__.py

rasbt commented 11 months ago

I added a PR for your convenience here: #191

pamelafox commented 10 months ago

FYI- In the Flask community, we've been removing version from packages now that importlib is around. Maybe scientific packages are keeping it around, but web packages are moving away from it.