{"id":28629525,"url":"https://github.com/lmstudio-ai/lmstudio-python","last_synced_at":"2026-01-17T04:33:55.286Z","repository":{"id":279843008,"uuid":"931855846","full_name":"lmstudio-ai/lmstudio-python","owner":"lmstudio-ai","description":"LM Studio Python SDK","archived":false,"fork":false,"pushed_at":"2025-10-27T02:07:44.000Z","size":1234,"stargazers_count":717,"open_issues_count":27,"forks_count":117,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-12-22T10:37:12.685Z","etag":null,"topics":["llm","lmstudio","python"],"latest_commit_sha":null,"homepage":"https://lmstudio.ai/docs/python","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lmstudio-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-02-13T00:55:05.000Z","updated_at":"2025-12-21T20:24:11.000Z","dependencies_parsed_at":"2025-02-28T02:53:30.998Z","dependency_job_id":"7897e259-ddd1-4ac7-b3e1-be876a66bcda","html_url":"https://github.com/lmstudio-ai/lmstudio-python","commit_stats":null,"previous_names":["lmstudio-ai/lmstudio-python"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/lmstudio-ai/lmstudio-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmstudio-ai%2Flmstudio-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmstudio-ai%2Flmstudio-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmstudio-ai%2Flmstudio-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmstudio-ai%2Flmstudio-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmstudio-ai","download_url":"https://codeload.github.com/lmstudio-ai/lmstudio-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmstudio-ai%2Flmstudio-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28495182,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T04:31:57.058Z","status":"ssl_error","status_checked_at":"2026-01-17T04:31:45.816Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["llm","lmstudio","python"],"created_at":"2025-06-12T12:01:35.408Z","updated_at":"2026-01-17T04:33:55.278Z","avatar_url":"https://github.com/lmstudio-ai.png","language":"Python","readme":"# LM Studio Python SDK\n\n## Using the SDK\n\n### Installation\n\nThe SDK can be installed from PyPI as follows:\n\n```console\n$ pip install lmstudio\n```\n\nInstallation from the repository URL or a local clone is also\nsupported for development and pre-release testing purposes.\n\n## Examples\n\nThe base component of the LM Studio SDK is the (synchronous) `Client`.\nThis should be created once and used to manage the underlying\nwebsocket connections to the LM Studio instance.\n\nHowever, a top level convenience API is provided for convenience in\ninteractive use (this API implicitly creates a default `Client` instance\nwhich will remain active until the Python interpreter is terminated).\n\nUsing this convenience API, requesting text completion from an already\nloaded LLM is as straightforward as:\n\n```python\nimport lmstudio as lms\n\nmodel = lms.llm()\nmodel.complete(\"Once upon a time,\")\n```\n\nRequesting a chat response instead only requires the extra step of\nsetting up a `Chat` helper to manage the chat history and include\nit in response prediction requests:\n\n```python\nimport lmstudio as lms\n\nEXAMPLE_MESSAGES = (\n    \"My hovercraft is full of eels!\",\n    \"I will not buy this record, it is scratched.\"\n)\n\nmodel = lms.llm()\nchat = lms.Chat(\"You are a helpful shopkeeper assisting a foreign traveller\")\nfor message in EXAMPLE_MESSAGES:\n    chat.add_user_message(message)\n    print(f\"Customer: {message}\")\n    response = model.respond(chat)\n    chat.add_assistant_response(response)\n    print(f\"Shopkeeper: {response}\")\n```\n\nAdditional SDK examples and usage recommendations may be found in the main\n[LM Studio Python SDK documentation](https://lmstudio.ai/docs/python).\n\n## SDK versioning\n\nThe LM Studio Python SDK uses a 3-part `X.Y.Z` numeric version identifier:\n\n* `X`: incremented when the minimum version of significant dependencies is updated\n  (for example, dropping support for older versions of Python or LM Studio).\n  Previously deprecated features may be dropped when this part of the version number\n  increases.\n* `Y`: incremented when new features are added, or some other notable change is\n  introduced (such as support for additional versions of Python). New deprecation\n  warnings may be introduced when this part of the version number increases.\n* `Z`: incremented for bug fix releases which don't contain any other changes.\n  Adding exceptions and warnings for previously undetected situations is considered\n  a bug fix.\n\nThis versioning policy is intentionally similar to [semantic versioning](https://semver.org/),\nbut differs in the specifics of when the different parts of the version number will be updated.\n\nRelease candidates *may* be published prior to full releases, but this will typically only\noccur when seeking broader feedback on particular features prior to finalizing the release.\n\nOutside the preparation of a new release, the SDK repository will include a `.devN` suffix\non the nominal Python package version.\n\n## Contributing to SDK development\n\n### Fetching the source code\n\n```console\n$ git clone https://github.com/lmstudio-ai/lmstudio-python\n$ cd lmstudio-python\n```\n\nTo be able to run `tox -e sync-sdk-schema`, it is also\nnecessary to ensure the `lmstudio-js` submodule is updated:\n\n```console\n$ git submodule update --init --recursive\n```\n\n### Development Environment\n\nIn order to work on the Python SDK, you need to install\n:pypi:`pdm`, :pypi:`tox`, and :pypi:`tox-pdm`\n(everything else can be executed via `tox` environments).\n\nGiven these tools, the default development environment can be set up\nand other commands executed as described below.\n\nThe simplest option for handling that is to install `uv`, and then use\nits `uv tool` command to set up `pdm` and a second environment\nwith `tox` + `tox-pdm`. `pipx` is another reasonable option for this task.\n\nIn order to _use_ the Python SDK, you just need some form of\nPython environment manager (since `lmstudio-python` publishes\nthe package `lmstudio` to PyPI).\n\n### Recommended local checks\n\nThe set of checks recommended for local execution are accessible via\nthe `check` marker in `tox`:\n\n```console\n$ tox -m check\n```\n\nThis runs the same checks as the `static` and `test` markers (described below).\n\n### Code consistency checks\n\nThe project source code is autoformatted and linted using :pypi:`ruff`.\nIt also uses :pypi:`mypy` in strict mode to statically check that Python APIs\nare being accessed as expected.\n\nAll of these commands can be invoked via tox:\n\n```console\n$ tox -e format\n```\n\n```console\n$ tox -e lint\n```\n\n```console\n$ tox -e typecheck\n```\n\nLinting and type checking can be executed together using the `static` marker:\n\n```console\n$ tox -m static\n```\n\nAvoid using `# noqa` comments to suppress these warnings - wherever\npossible, warnings should be fixed instead. `# noqa` comments are\nreserved for rare cases where the recommended style causes severe\nreadability problems, and there isn't a more explicit mechanism\n(such as `typing.cast`) to indicate which check is being skipped.\n\n`# fmt: off/on` and `# fmt: skip` comments may be used as needed\nwhen the autoformatter makes readability worse instead of better\n(for example, collapsing lists to a single line when they intentionally\ncover multiple lines, or breaking alignment of end-of-line comments).\n\n### Automated testing\n\nThe project's tests are written using the :pypi:`pytest` test framework.\n:pypi:`tox` is used to automate the setup and execution of these tests\nacross multiple Python versions. One of these is nominated as the\ndefault test target, and is accessible via the `test` marker:\n\n```console\n$ tox -m test\n```\n\nYou can also use other defined versions by specifying the target\nenvironment directly:\n\n```console\n$ tox -e py3.11\n```\n\nThere are additional labels defined for running the oldest test environment,\nthe latest test environment, and all test environments:\n\n```console\n$ tox -m test_oldest\n$ tox -m test_latest\n$ tox -m test_all\n```\n\nTo ensure all the required models are loaded before running the tests, run the\nfollowing command:\n\n```\n$ tox -e load-test-models\n```\n\n`tox` has been configured to forward any additional arguments it is given to\n`pytest`. This enables the use of pytest's\n[rich CLI](https://docs.pytest.org/en/stable/how-to/usage.html#specifying-which-tests-to-run).\nIn particular, you can select tests using all the options that pytest provides:\n\n```console\n$ # Using file name\n$ tox -m test -- tests/test_basics.py\n$ # Using markers\n$ tox -m test -- -m \"slow\"\n$ # Using keyword text search\n$ tox -m test -- -k \"catalog\"\n```\n\nAdditional notes on running and updating the tests can be found in the\n`tests/README.md` file.\n\n\n### Expanding the API\n\n- the content of `src/lmstudio/_sdk_models` is automatically generated by the\n  `sync-sdk-schema.py` script in `sdk-schema` and should not be modified directly.\n  Run `tox -e sync-sdk-schema` to regenerate the Python submodule from the existing\n  export of the `lmstudio-js` schema (for example, after modifying the data model\n  template). Run `tox -e sync-sdk-schema -- --regen-schema` after updating the\n  `sdk-schema/lmstudio-js` submodule itself to a newer iteration of the\n  `lmstudio-js` JSON API.\n- as support for new API namespaces is added to the SDK, each should get a dedicated\n  session type (similar to those for the already supported namespaces), even if it\n  is only used privately by the client implementation.\n- as support for new API channel endppoints is added to the SDK, each should get a\n  dedicated base endpoint type (similar to those for the already supported channels).\n  This avoids duplicating the receive message processing between the sync and async APIs.\n- the `json_api.SessionData` base class is useful for defining rich result objects which\n  offer additional methods that call back into the SDK (for example, this is how downloaded\n  model listings offer their interfaces to load a new instance of a model).\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmstudio-ai%2Flmstudio-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmstudio-ai%2Flmstudio-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmstudio-ai%2Flmstudio-python/lists"}