NBatch 3.0.0

dotnet add package NBatch --version 3.0.0
                    
NuGet\Install-Package NBatch -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NBatch" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NBatch" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NBatch" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NBatch --version 3.0.0
                    
#r "nuget: NBatch, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NBatch@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NBatch&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NBatch&version=3.0.0
                    
Install as a Cake Tool

NBatch

NuGet Version NuGet Downloads CI

A lightweight batch processing framework for .NET, inspired by Spring Batch.

📖 Full Documentation — guides, API reference, and examples.

NBatch gives you a declarative, step-based pipeline for ETL jobs, data migrations, and scheduled tasks. Wire up readers, processors, and writers — NBatch handles chunking, error skipping, progress tracking, and restart-from-failure.

Packages

Package Description
NBatch Core framework — interfaces, chunking, skip policies, CsvReader, FlatFileItemWriter, DI, hosted service. No EF Core dependency.
NBatch.EntityFrameworkCore DbReader/DbWriter + EF Core job store for restart-from-failure (SQL Server, PostgreSQL, SQLite, MySQL/MariaDB)
dotnet add package NBatch
dotnet add package NBatch.EntityFrameworkCore   # DbReader/DbWriter + persistent job tracking

Examples

var job = Job.CreateBuilder("ETL")
    .AddStep("extract-transform", step => step
        .ReadFrom(new CsvReader<Order>(...))
        .WriteTo(new DbWriter<Order>(...))
        .WithChunkSize(100))
    .AddStep("notify", step => step
        .Execute(() => SendEmail()))
    .Build();

With SQL-backed job store for restart-from-failure

var job = Job.CreateBuilder("csv-import")
    .UseJobStore(connStr, DatabaseProvider.SqlServer)   // optional — enables restart-from-failure
    .AddStep("import", step => step
        .ReadFrom(new CsvReader<Product>("data.csv", mapFn))
        .ProcessWith(p => new Product { Name = p.Name.ToUpper(), Price = p.Price })
        .WriteTo(new DbWriter<Product>(dbContext))
        .WithSkipPolicy(SkipPolicy.For<FormatException>(maxSkips: 5))
        .WithChunkSize(100))
    .AddStep("notify", step => step
        .Execute(() => SendEmail()))
    .Build();

await job.RunAsync();

With Dependency Injection & Hosted Service

builder.Services.AddNBatch(nbatch =>
{
    nbatch.AddJob("csv-import", (sp, job) => job
        .AddStep("import", step => step
            .ReadFrom(new CsvReader<Product>("data.csv", mapFn))
            .WriteTo(new DbWriter<Product>(sp.GetRequiredService<AppDbContext>()))
            .WithChunkSize(100)))
        .RunEvery(TimeSpan.FromHours(1));
});

Highlights

  • Chunk-oriented processing — read, transform, and write in configurable batches
  • Item-level skip policies — skip malformed records instead of aborting the job; the rest of the chunk is still written
  • Retry policies — transient errors are retried (with optional backoff) before any skipping happens
  • Restart from failure — SQL-backed job store resumes where a crashed job left off; completed jobs auto-reset for the next run
  • Tasklet steps — fire-and-forget work (send an email, call an API, run a stored proc)
  • Lambda-friendly — processors and writers can be plain lambdas; CSV rows auto-map to your classes
  • DI & hosted service — AddNBatch(), DI-resolved components, RunOnce(), RunEvery(), and cron schedules via RunOnCron()
  • Observability — OpenTelemetry-ready traces and metrics out of the box
  • Multi-target — .NET 8, .NET 9, and .NET 10
  • Provider-agnostic — SQL Server, PostgreSQL, SQLite, or MySQL for the job store; any EF Core provider for your data

Documentation

See the full documentation for guides, API reference, and examples:

  • Core concepts — jobs, steps, readers, writers, processors
  • Readers & writers — CsvReader, DbReader, DbWriter, FlatFileItemWriter
  • Skip policies — error handling and skip limits
  • Job store — persistent tracking and restart-from-failure
  • DI & hosted service — AddNBatch(), IJobRunner, RunOnce(), RunEvery()
  • Listeners — job and step lifecycle hooks
  • API reference — all public types and methods
  • Examples — CSV-to-DB, DB-to-file, multi-step, DI, hosted service

Running locally

# Start the test database (SQL Server via Docker)
cd src && docker compose up -d

# Build & run the demo console app
dotnet build
dotnet run --project NBatch.ConsoleApp

# Run tests
dotnet test

Contributing

  1. Fork the repo
  2. Create a feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -m "Add my feature"
  4. Push: git push origin my-feature
  5. Open a pull request

License

See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NBatch:

Package Downloads
NBatch.EntityFrameworkCore

Entity Framework Core-based job store for NBatch. Provides SQL Server, PostgreSQL, SQLite, and MySQL/MariaDB support for persistent job tracking and restart-from-failure.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 103 8/3/2026
2.0.0 351 2/24/2026
1.0.1 4,038 4/12/2015
1.0.0 3,381 4/4/2015

v3.0.0 — Item-level skip scanning, retry policies with backoff, cron scheduling (RunOnCron), CSV auto-mapping, DI-resolved step components, job-level defaults, EnsureSuccess, OpenTelemetry-ready traces/metrics, auto-reset after successful runs, RFC 4180 quoted CSV parsing, order-independent job builder. Renames: ItemsProcessed→ItemsWritten, ErrorsSkipped→ItemsSkipped, WithToken→WithDelimiter. DbReader/DbWriter moved to NBatch.EntityFrameworkCore; the core package no longer depends on EF Core. See CHANGELOG for the migration guide.