Sourcery
Sourcery is a Swift code generator that automates boilerplate code generation using templates and AST analysis. It reduces repetitive coding tasks like creating mocks, equality implementations, and codable conformances by orders of magnitude.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | krzysztofzablocki/Sourcery |
| Owner | krzysztofzablocki |
| Primary language | Swift |
| License | MIT — OSI-approved |
| Stars | 8k |
| Forks | 635 |
| Open issues | 94 |
| Latest release | 2.3.0 (2025-09-18) |
| Last updated | 2026-06-11 |
| Source | https://github.com/krzysztofzablocki/Sourcery |
What Sourcery is
Built on Apple's SwiftSyntax, Sourcery parses Swift source code into an AST and applies Stencil-based templates to generate new code. It supports both Stencil and JavaScript templates, runs as a CLI tool or Xcode build phase, and integrates with SwiftPM as a plugin.
Get the Sourcery source
Clone the repository and explore it locally.
git clone https://github.com/krzysztofzablocki/Sourcery.gitcd Sourcery# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Templates use Stencil syntax; team must learn Stencil idioms and AST navigation. Documentation is extensive but learning curve exists.
- Generated code should be committed or regenerated in CI/CD. Define a clear workflow: pre-commit hook, build phase, or CI step to avoid divergence.
- Sourcery Pro (Mac App Store) offers live Stencil editing and Xcode integration; open-source CLI is free but lacks IDE feedback.
- Template debugging requires understanding the AST structure Sourcery exposes. Errors in templates can silently produce incorrect or missing generated code.
- Version control: decide whether to commit generated files or regenerate on clone. Committing reduces friction; regenerating keeps repo lean.
When to avoid it — and what to weigh
- JavaScript template support is critical — The README notes JS templates are not supported when building with SPM. If your workflow requires JS templates and SPM distribution, this is a blocker.
- Zero build-time overhead is non-negotiable — Code generation adds a build step. If your project has strict build-time constraints or very frequent incremental builds, the added overhead may be problematic.
- Swift version pinning requirements — Sourcery parses using SwiftSyntax, which is tied to specific Swift versions. Rapid major Swift version migrations may create compatibility friction.
- Heavy reliance on runtime reflection — If your architecture depends on runtime inspection rather than compile-time code generation, Sourcery's static approach may not align.
License & commercial use
MIT License. Permissive OSI-approved license allowing commercial use, modification, and distribution with no restriction other than license/copyright notice preservation.
MIT is a permissive open-source license. Commercial use is permitted without license fee or approval. However, confirm your internal policy on third-party OSS dependencies and ensure your usage complies with your organization's open-source guidelines.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
Sourcery is a code generation tool running locally during build time. Security posture depends on: (1) template validation—ensure custom templates are reviewed, as they have broad AST access; (2) source code access—runs on your source tree, no external data transmission claimed; (3) SwiftSyntax dependency—regularly updated by Apple. No known vulnerabilities reported in available data. As with any build tool, audit templates from third parties before use.
Alternatives to consider
Swift macros (Swift 5.9+)
Apple's native compile-time macro system provides similar boilerplate elimination with language-level support. Newer projects may prefer macros for derived Equatable/Codable, though Sourcery remains more flexible for complex patterns.
Xcode code snippets + manual templates
Low-tech alternative using Xcode's built-in snippet system. No build-time overhead, but no automation; suited for simple, infrequent patterns.
GYB (Generate Your Boilerplate, part of Swift toolchain)
Lightweight, Python-based code generation baked into Swift stdlib. Minimal dependencies but less user-friendly and smaller community than Sourcery.
Build on Sourcery with DEV.co software developers
Sourcery automates code generation for mocks, equality, and domain-specific patterns. Get started with templates and integrate into your build pipeline—no license fee, MIT open source.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
Sourcery FAQ
Can we use Sourcery in a CI/CD pipeline without Xcode?
Do we have to commit generated code to git?
Is there IDE support beyond terminal?
How do we migrate if Swift macros become sufficient?
Work with a software development agency
DEV.co helps companies turn open-source tools like Sourcery into production software. Our software development services cover the full lifecycle — architecture, web development, integration, and maintenance — delivered by software developers and web developers who ship. Engage our software development agency to implement or customize it for your ai coding agents stack.
Reduce boilerplate and accelerate iOS/macOS development
Sourcery automates code generation for mocks, equality, and domain-specific patterns. Get started with templates and integrate into your build pipeline—no license fee, MIT open source.