{"id":7869,"library":"writer-sdk","title":"Writer SDK for Python","description":"The writer-sdk is the official Python library for the Writer API, providing programmatic access to Writer's generative AI capabilities. It enables Python 3.9+ applications to integrate features like chat completions, text generation, and knowledge graph interactions. The library is actively maintained with frequent updates, including a recent release candidate for version 3.0.0.","status":"active","version":"2.4.0","language":"en","source_language":"en","source_url":"https://github.com/writer/writer-python","tags":["AI","NLP","LLM","writer","sdk","generative-ai"],"install":[{"cmd":"pip install writer-sdk","lang":"bash","label":"Install stable version"},{"cmd":"pip install --pre writer-sdk","lang":"bash","label":"Install pre-release versions (e.g., 3.0.0-rc1)"}],"dependencies":[{"reason":"Requires Python 3.9 or higher for compatibility.","package":"Python","optional":false}],"imports":[{"note":"The primary client class is imported from 'writerai', not 'writer_sdk'.","wrong":"from writer_sdk import Writer","symbol":"Writer","correct":"from writerai import Writer"}],"quickstart":{"code":"import os\nfrom writerai import Writer\n\n# Initialize the Writer client.\n# The API key will be inferred from the `WRITER_API_KEY` environment variable.\n# Ensure you have 'export WRITER_API_KEY=\"your-api-key\"' in your environment\n# or pass it explicitly: client = Writer(api_key=\"your-api-key\")\nclient = Writer(api_key=os.environ.get(\"WRITER_API_KEY\", \"\"))\n\nif not client.api_key:\n    print(\"WARNING: WRITER_API_KEY environment variable not set. Please set it for authentication.\")\n    print(\"You can obtain your API key from your Writer AI Studio account settings.\")\nelse:\n    try:\n        response = client.chat.chat(\n            messages=[{\n                \"content\": \"Write a short poem about Python\",\n                \"role\": 'user'\n            }],\n            model=\"palmyra-x5\"\n        )\n        print(response.choices[0].message.content)\n    except Exception as e:\n        print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the Writer client and make a basic chat completion request. It emphasizes using the `WRITER_API_KEY` environment variable for secure authentication."},"warnings":[{"fix":"Review the v3.0.0-rc1 changelog and update your code to remove usage of deprecated features or use alternative Writer API capabilities.","message":"Version 3.0.0-rc1 deprecates several API features, including AI Detection, Medical Comprehend, and Context-Aware Text Splitting. Applications relying on these specific endpoints will break upon upgrade to v3.0.0.","severity":"breaking","affected_versions":">=3.0.0-rc1"},{"fix":"If you encounter type-related errors after upgrading to v2.0.0+, review the updated type definitions in the SDK or limit usage to the `client.chat.chat` method without direct type imports.","message":"The 2.0.0 release introduced breaking changes to the underlying models used in chat completion. This primarily affects users directly importing specific types related to chat completion models.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure you are installing `writer-sdk` for the API client and `writer` for the framework, and import accordingly. The SDK's client is typically imported as `from writerai import Writer`.","message":"The `writer-sdk` library should not be confused with the `writer` PyPI package, which corresponds to `writer-framework`. They are distinct libraries with different purposes, where `writer-framework` is for building UI-based AI applications.","severity":"gotcha","affected_versions":"All"},{"fix":"Set the `WRITER_API_KEY` environment variable before running your application (e.g., `export WRITER_API_KEY=\"your-api-key\"`) or use a `.env` file for local development. Alternatively, pass it explicitly to the client constructor (e.g., `client = Writer(api_key=os.environ.get('WRITER_API_KEY'))`).","message":"API keys should not be hard-coded in your application. The library automatically infers the API key from the `WRITER_API_KEY` environment variable.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure the library is installed with `pip install writer-sdk` and that your import statement is `from writerai import Writer`.","cause":"The `writer-sdk` package is either not installed, or the import statement is incorrect.","error":"ModuleNotFoundError: No module named 'writerai'"},{"fix":"Verify that your `WRITER_API_KEY` environment variable is set correctly with a valid API key from your Writer AI Studio account. Ensure there are no leading/trailing spaces or incorrect characters.","cause":"The provided API key is invalid, missing, or expired.","error":"writerai.APIStatusError: 401 Unauthorized"},{"fix":"Check your internet connection, firewall settings, and ensure that `https://api.writer.com/v1` is accessible. Increase client timeout if necessary.","cause":"The client could not connect to the Writer API, possibly due to network issues, a timeout, or a firewall blocking the connection.","error":"writerai.APIConnectionError: Connection error"},{"fix":"Refer to the official Writer SDK documentation for the correct API calls for your installed version. Upgrade your `writer-sdk` to the latest version to access new features, and review changelogs for breaking changes if upgrading across major versions.","cause":"You are attempting to call an API method that does not exist in your installed SDK version, or the method name has changed in a newer version. This can also happen if a service/feature was deprecated.","error":"AttributeError: 'Writer' object has no attribute 'some_method'"}]}