{"library":"logfire-api","code":"import os\nimport logfire_api as logfire\n\n# Simulate Logfire being installed (or not) for demonstration\n# In a real scenario, `logfire` would either be in your environment or not.\n# For this example, we'll configure a mock for `logfire.configure` if `logfire` is not installed.\n# In a production environment, users would `pip install logfire` and configure it.\n\ntry:\n    import logfire as _actual_logfire\n    logfire_installed = True\nexcept ImportError:\n    logfire_installed = False\n\nif not logfire_installed:\n    print(\"Logfire (the full SDK) is NOT installed. `logfire_api` will act as a no-op.\")\nelse:\n    print(\"Logfire (the full SDK) IS installed. `logfire_api` will delegate to it.\")\n\n# Configure Logfire (this would typically be done by the end-user of a library using logfire-api)\n# For logfire-api, library authors usually *don't* call configure().\n# The actual `logfire.configure()` would typically read LOGFIRE_TOKEN or other env vars.\nif logfire_installed:\n    # Only configure if the actual logfire SDK is present, otherwise it's a no-op by design\n    os.environ['LOGFIRE_TOKEN'] = os.environ.get('LOGFIRE_TOKEN', 'your-logfire-write-token') # Replace with a real token in production\n    logfire.configure(service_name='my-shimmed-app')\n    print(\"Logfire (actual SDK) configured.\")\nelse:\n    print(\"Skipping logfire.configure() as the actual SDK is not installed.\")\n\n@logfire.instrument(\"my_function\")\ndef my_function(name: str):\n    logfire.info(\"Hello from {name}!\", name=name)\n    with logfire.span(\"inner_operation\"):\n        logfire.debug(\"Performing an inner operation.\")\n    return f\"Processed {name}\"\n\nresult = my_function(\"World\")\nprint(f\"Function returned: {result}\")\n\n# To see output in Logfire, ensure LOGFIRE_TOKEN is set and 'logfire' is installed.\n# The above `logfire.configure()` will only run if `logfire` is installed.\n# Otherwise, all logfire calls above will effectively do nothing.","lang":"python","description":"This quickstart demonstrates how to use `logfire_api` as a shim. When `logfire` (the full SDK) is installed and configured by the end-user, `logfire_api` calls will be delegated to the actual Logfire SDK. If `logfire` is not installed, `logfire_api` methods will gracefully act as no-ops. Library authors typically `import logfire_api as logfire` and use its API, leaving the `logfire.configure()` call to their users. To send data to the Logfire platform, the `LOGFIRE_TOKEN` environment variable must be set.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}