filelock

A platform-independent file lock for Python that supports the with-statement.

Library
PyPI
v3.32.3
975stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
88/100Excellent
Development Activity96
Maintenance96
Community72
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
85/100Excellent
Architecture88
Code Quality90
Innovation80
Learning Curve82

filelock provides a simple, dependable way to coordinate access to a shared resource across processes and threads using lock files. It ships multiple lock strategies — a strict OS-native lock backed by fcntl/msvcrt, a soft lock that relies on atomic file creation, and async variants for asyncio-based applications — all behind a consistent context-manager API.

The library is a foundational dependency in the Python packaging ecosystem (used by tox, pip, virtualenv, and many CI tools) precisely because it solves a narrow problem extremely well: preventing two processes from stepping on the same file or directory at the same time, on any platform, without requiring a database or external service.

What You Get

  • A FileLock class that picks the right backend automatically (fcntl on Unix, msvcrt on Windows, atomic-create soft lock as a fallback)
  • Context-manager and explicit acquire/release APIs with configurable timeouts and polling intervals
  • AsyncFileLock and related async primitives for use inside asyncio event loops without blocking the loop
  • Strict and soft lock variants, including a StrictSoftFileLock that layers ownership/staleness checks on top of the soft lock
  • Reentrant (recursive) lock acquisition within the same thread, with reference counting
  • Read-write lock support (ReadWriteLock) for shared vs exclusive access patterns

Common Use Cases

  • Preventing concurrent CI/test runners (e.g. tox, pytest-xdist workers) from corrupting a shared cache or virtualenv directory
  • Guarding a single-instance script or cron job so overlapping runs don’t clobber shared state
  • Coordinating writes to a shared config or data file across multiple processes on the same host
  • Serializing access to a downloaded/extracted dependency cache in packaging and build tools

Under The Hood

Architecture filelock separates concerns cleanly across _api.py (the shared BaseFileLock context-manager contract and acquire/release/timeout logic), platform-specific backends (_unix.py using fcntl, _windows.py using msvcrt, _soft.py using atomic O_CREAT|O_EXCL file creation), and a parallel async stack (asyncio.py, _async.py) that wraps the same backends behind coroutine-friendly acquire/release calls run off the event loop thread. A _strict.py module layers ownership/staleness detection (via _marker.py and _identity.py process-identity records) on top of the soft lock to detect and recover from crashed lock holders, and _read_write.py/_async_read_write.py add a separate reader-writer lock built on SQLite for cross-process shared/exclusive semantics.

Tech Stack Pure Python (99.9%) with zero runtime dependencies, targeting Python 3.10+ per pyproject.toml. Uses hatchling/hatch-vcs for the build backend and version derivation from git tags. Platform integration is via stdlib-only modules (fcntl, msvcrt, sqlite3) rather than third-party bindings, keeping the dependency footprint at zero.

Code Quality Extensive test suite (40+ files in tests/) covering async cancellation semantics, fork safety, strict/soft lock races, lock expiry, and platform-specific fallback behavior — well beyond typical coverage for a library this size. Code is fully typed, uses from __future__ import annotations, and is organized into small, single-responsibility modules with private (_-prefixed) internals and a curated public __all__ export list.

API Design The public API is deliberately minimal: a single FileLock (or AsyncFileLock) alias resolves to the right backend for the current platform, used identically via with lock: or await lock.acquire(). Advanced variants (SoftFileLock, StrictSoftFileLock, ReadWriteLock) follow the same constructor/acquire/release shape, so users can start with the simple case and opt into stronger guarantees without relearning the API. Documentation is hosted on Read the Docs with runnable examples for both sync and async usage.

Used by 21 apps in this directory

Python
100%
Apache 2.0

Agno

Devops · AI Development · Automation

41,774

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
67
Dependency
Built with
Python100%
Updated today
Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,530

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
66
Dependency
Built with
Python90%
Updated today
C++
69%
Apache 2.0

ClickHouse

Databases · Analytics · Data Engineering

49,325

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
68
Dependency
Built with
C++69%
Python13%
Updated today
Python
100%
GPL 3.0

ComfyUI

AI Design Tools · AI Development

128,363

The most powerful node-based AI workflow engine for creating images, video, 3D models, and audio with full control over every generation step.

View details
92
Repo Health
81
Technical
75
Dependency
Built with
Python100%
Updated today
Python
99%
MIT

deepagents

AI Agents · AI Development

27,919

The batteries-included Python agent harness — planning, sub-agents, filesystem, shell, memory, and skills bundled in, built on LangGraph.

View details
88
Repo Health
83
Technical
74
Dependency
Built with
Python99%
Updated today
Python
64%
MIT

Flowfile

Data Engineering

341

Visual ETL that compiles to Polars — build pipelines on a canvas, export as standalone Python, and run anywhere without platform lock-in.

View details
83
Repo Health
81
Technical
66
Dependency
Built with
Python64%
Vue19%
TypeScript16%
Updated today
Python
91%
MIT

Gemma Multimodal Fine-Tuner

AI Development

1,498

An Apple-Silicon-native LoRA fine-tuning tool for Gemma on text, image, and audio data — with a wizard CLI, live browser-based training visualizer, and streaming from GCS/BigQuery for datasets too large for local disk.

View details
51
Repo Health
68
Technical
76
Dependency
Built with
Python91%
Updated 6 days ago
Python
63%
Apache 2.0

GPT Researcher

Productivity · AI Assistants

29,039

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
88
Repo Health
91
Technical
64
Dependency
Built with
Python63%
TypeScript23%
Updated 1 months ago
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,083

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
62
Repo Health
81
Technical
66
Dependency
Built with
TypeScript91%
Updated 3 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search