{"id":27966,"library":"motor-stubs","title":"Motor-Stubs","description":"Type stubs for Motor (async MongoDB driver) providing type hints for Motor classes. This package enables static type checking of Motor-based code in projects using mypy or pyright. It is maintained separately from Motor and has a version 1.7.1 as of last update, targeting Python >=3.9. Release cadence is irregular.","status":"active","version":"1.7.1","language":"python","source_language":"en","source_url":"https://github.com/Yian8068/motor-stubs","tags":["type-stubs","motor","mongodb","async","typing","mypy"],"install":[{"cmd":"pip install motor-stubs","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"motor-stubs provides type stubs for the motor package; runtime dependency required","package":"motor","optional":false},{"reason":"Optional: to use type checking during development","package":"mypy","optional":true},{"reason":"Motor internally uses pymongo types; pymongo-stubs may be needed for complete type coverage","package":"pymongo-stubs","optional":true}],"imports":[{"note":"No alternative import; motor stubs mirror actual motor imports","symbol":"AsyncIOMotorClient","correct":"from motor.motor_asyncio import AsyncIOMotorClient"}],"quickstart":{"code":"import asyncio\nfrom motor.motor_asyncio import AsyncIOMotorClient\n\nasync def main():\n    client = AsyncIOMotorClient('mongodb://localhost:27017')\n    db = client.test_database\n    collection = db.test_collection\n    doc = await collection.find_one({'_id': 1})\n    print(doc)\n\nasyncio.run(main())","lang":"python","description":"Basic Motor async usage; stubs provide type checking."},"warnings":[{"fix":"Update code to match stubs; ensure None is handled explicitly for optional parameters","message":"Breaking change in v1.0.0: AsyncIOMotorCursor type annotations changed; methods like .to_list() now expect Optional arguments","severity":"breaking","affected_versions":">=1.0.0 (first major release)"},{"fix":"Use # type: ignore[attr-defined] or contribute to stubs","message":"Stubs may not cover all Motor internals; mypy may report missing imports for certain attributes","severity":"gotcha","affected_versions":"all"},{"fix":"Replace 'from pymongo_stubs import ...' with motor-stubs; ensure only motor-stubs is installed","message":"Some pymongo stubs (pymongo-stubs) are deprecated in favor of motor-stubs; motor-stubs now includes pymongo types","severity":"deprecated","affected_versions":">=0.6.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Install motor-stubs: pip install motor-stubs. If using mypy, ensure stubs are automatically discovered or explicitly configured.","cause":"motor-stubs not installed or not recognized by type checker","error":"Module 'motor.motor_asyncio' has no attribute 'AsyncIOMotorClient'"},{"fix":"pip install motor-stubs; if using mypy check MYPYPATH or stub configuration.","cause":"motor-stubs missing or mypy can't locate stubs","error":"Cannot find implementation or library stub for module 'motor'"},{"fix":"Cast or use a variable: filter = {'_id': 1}; await collection.find_one(filter)","cause":"motor-stubs type annotations are stricter than pymongo; dict literal not accepted directly","error":"Argument 1 to 'find_one' of 'Collection' has incompatible type 'Dict[str, int]'; expected 'Mapping[str, Any] | None'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}