{"id":5820,"library":"types-filelock","title":"Typing stubs for filelock","description":"This package provides static type checking stubs for the `filelock` library, enabling tools like MyPy to verify type correctness. It is part of the Python typeshed project, which maintains high-quality stubs generally kept up-to-date with the latest versions of their respective runtime libraries. Releases follow typeshed's continuous integration and release cycle, reflecting updates to the underlying `filelock` library.","status":"active","version":"3.2.7","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","filelock","type-hints"],"install":[{"cmd":"pip install types-filelock","lang":"bash","label":"Install typing stubs"}],"dependencies":[{"reason":"Provides the runtime functionality for which these stubs offer type hints. Must be installed separately.","package":"filelock","optional":false}],"imports":[{"note":"Typing stubs are not meant for direct import; they provide type information for the original library's imports.","wrong":"from types_filelock import FileLock","symbol":"FileLock","correct":"from filelock import FileLock"}],"quickstart":{"code":"import os\nimport time\nfrom filelock import FileLock\n\n# Define a lock file path\nlock_file_path = \"/tmp/my_app.lock\"\n\ntry:\n    # Acquire the lock. If another process holds it, this will block until it's released.\n    # The timeout parameter ensures it doesn't wait indefinitely.\n    with FileLock(lock_file_path, timeout=5):\n        print(\"Lock acquired. Performing exclusive operation...\")\n        # Simulate work\n        time.sleep(2)\n        print(\"Exclusive operation completed. Releasing lock.\")\nexcept Exception as e:\n    print(f\"Could not acquire lock or an error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates the usage of the `filelock` library, for which `types-filelock` provides type hints. To run this code with type checking, ensure both `filelock` and `types-filelock` are installed. The `FileLock` context manager ensures that the enclosed code block is executed exclusively, preventing race conditions across processes."},"warnings":[{"fix":"Ensure `filelock` is listed in your project's dependencies and installed alongside `types-filelock`.","message":"Installing `types-filelock` does NOT install the `filelock` runtime library. You must install `filelock` separately (e.g., `pip install filelock`) for your code to function.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always import symbols directly from the `filelock` package, e.g., `from filelock import FileLock`.","message":"Do not attempt to import symbols directly from `types_filelock` (or any variation of the stub package name). The purpose of `types-filelock` is to provide type information for imports from the original `filelock` library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If encountering type errors due to new `filelock` features, consider pinning `filelock` to an older version until stubs are updated, or temporarily ignoring specific `mypy` errors.","message":"Type stubs are maintained by the typeshed project and may occasionally lag behind the absolute latest releases of the `filelock` library. This can lead to `mypy` errors if `filelock` introduces new features or changes its API before corresponding stubs are updated.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}