{"id":23996,"library":"lunary","title":"Lunary Python SDK","description":"Python SDK for Lunary, an open-source platform for managing, monitoring, and improving LLM chatbots. Current version 1.4.41, actively maintained with frequent releases.","status":"active","version":"1.4.41","language":"python","source_language":"en","source_url":"https://github.com/lunary-ai/lunary/tree/main/packages/python-sdk","tags":["llm","monitoring","observability","chatbots","generative-ai"],"install":[{"cmd":"pip install lunary","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Optional integration for OpenAI. If you want to use Lunary's OpenAI monitoring, install with lunary[openai].","package":"openai","optional":true}],"imports":[{"note":"Old import path from langchain integration, not the standalone SDK.","wrong":"from langchain.callbacks import LunaryCallbackHandler","symbol":"LunaryHandler","correct":"from lunary import LunaryHandler"},{"note":"","wrong":"","symbol":"callback","correct":"from lunary import callback"},{"note":"","wrong":"","symbol":"log_event","correct":"from lunary import log_event"}],"quickstart":{"code":"import os\nfrom lunary import LunaryHandler\n\n# Set your Lunary API key\nos.environ['LUNARY_PUBLIC_KEY'] = 'your-public-key'\n\nhandler = LunaryHandler(\n    public_key=os.environ.get('LUNARY_PUBLIC_KEY', ''),\n    # Optional: specify a different endpoint\n    # endpoint=\"https://api.lunary.ai\"\n)\n\n# Usage example: track a chat completion\nhandler.track_event(\"chat\", {\n    \"model\": \"gpt-3.5-turbo\",\n    \"messages\": [{\"role\": \"user\", \"content\": \"Hello\"}],\n    \"output\": \"Hi there!\"\n})","lang":"python","description":"Initialize LunaryHandler with your API key and track an event."},"warnings":[{"fix":"Use 'from lunary import LunaryHandler' instead of 'from langchain.callbacks import LunaryCallbackHandler'.","message":"Do NOT use the deprecated langchain callback import path. The correct import is from lunary import LunaryHandler.","severity":"gotcha","affected_versions":"<=1.4.41"},{"fix":"Set os.environ['LUNARY_PUBLIC_KEY'] = 'your-key'.","message":"The environment variable for API key is LUNARY_PUBLIC_KEY (not LUNARY_API_KEY). Some older docs may mention the wrong name.","severity":"gotcha","affected_versions":"<=1.4.41"},{"fix":"Switch to from lunary import log_event or use the @callback decorator.","message":"The 'track_event' method is part of the v1 API and may be deprecated in future versions. Use 'log_event' or the callback decorator instead.","severity":"deprecated","affected_versions":">=1.2.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'from lunary import LunaryHandler' instead.","cause":"Trying to use an old import path from langchain integration that is no longer supported.","error":"ImportError: cannot import name 'LunaryCallbackHandler' from 'langchain.callbacks'"},{"fix":"Ensure LUNARY_PUBLIC_KEY is set correctly. Check your Lunary dashboard for the correct public key.","cause":"Environment variable LUNARY_PUBLIC_KEY is not set or contains an invalid key.","error":"lunary.exceptions.AuthenticationError: Invalid API key"},{"fix":"Use 'from lunary import log_event' and call log_event() instead.","cause":"Using an outdated method name; the function might have been renamed or moved.","error":"AttributeError: module 'lunary' has no attribute 'track_event'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}