Penlight: pure Lua modules for paths, tables, strings and lambdas, modelled on the Python standard library
A set of pure Lua libraries focusing on input data handling (such as reading configuration files), functional programming (such as map, reduce, placeholder expressions,etc), and OS path management. Much of the functionality is inspired by the Python standard libraries.
At a glance
- What is it?
- Penlight is an MIT licensed set of pure Lua libraries for input data handling, functional programming and OS path management. Its file functions need LuaFileSystem, and its versioning rules say exactly what counts as a breaking change.
- Who is it for?
- Choose Penlight if you write Lua applications or tools and want ready made path, table, string and argument parsing modules in the style of the Python standard library. Skip it if you need to avoid the LuaFileSystem dependency.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 5 days ago.
- What is it written in?
- Mainly Lua, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 26, 2026, and from our analysis. They are not legal advice.
Star history
- lunarmodules/Penlight2,141 ★ · +8
| Repository | 2026-10-11 | 2026-11-26 |
|---|---|---|
| lunarmodules/Penlight | 2.1k | 2.1k |
8 Stars in the last 46 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The Python standard library is the model for the whole set
The project says much of its functionality is inspired by the Python standard libraries, and the module list shows it. List is an implementation of the Python list type with slices, concatenation and partitioning. stringx extends Lua strings to cover the Python string type. text can make the percent operator work as in Python on strings. The Map, Set and OrderedMap classes give specialized kinds of tables.
The focus areas are input data handling, such as reading configuration files, functional programming, such as map, reduce and placeholder expressions, and OS path management. Everything is pure Lua, so there is no C module to compile.
A Python programmer picking up Lua will recognize most of the names. The converse is a risk: expecting Python behavior in every corner. The README says inspired by, not compatible with, so check the module docs for the exact semantics.
path, dir and file split the filesystem work three ways
Filesystem helpers are three modules. path answers queries like isdir, isfile and exists, and splits paths with dirname and basename. dir lists files in directories with getfiles and getallfiles and creates or removes directory paths. file offers copy and move, plus read and write for contents.
The README states the dependency plainly: the file and directory functions depend on LuaFileSystem, which LuaRocks installs automatically. On Windows, dir.copyfile works elegantly only if Alien is also installed. Both libraries come with Lua for Windows.
Pure Lua therefore has an asterisk. If you copy the lua/pl directory by hand, as the manual install allows, you also have to supply LuaFileSystem yourself, or the path and file modules fail. The modules that do not touch the filesystem stand alone.
app and lapp turn a usage string into an argument parser
For command line tools there are two levels. app has require_here, which rebases require to work from the main script's path, and parse_args for simple argument parsing. lapp offers sophisticated usage text driven argument parsing: you write the help text and the parser is derived from it.
config reads Unix config files and Windows INI files flexibly, and the examples directory has testconfig.lua. strict checks for undefined global variables, and strict.module extends that to modules. The types module adds predicates such as is_callable and is_integer along with an extended type function.
The set covers most of what a small Lua tool needs before it grows a framework. The README says little about error handling inside lapp when a user passes bad flags, so read the lapp documentation before relying on it for a public command line interface.
Strings, tables and iterators each get a dedicated module
String work is split across several modules. utils.split splits on a delimiter. lexer is a lexical scanner with special cases for Lua and C. template is a small template expansion engine. sip stands for Simple Input Patterns, higher level string patterns for parsing text, and the examples folder includes sipscan.lua.
Table work has tablex for copying, comparing and mapping, pretty for pretty printing tables and various safe ways to load Lua as data, data for tabular data in 2D arrays, array2d for operations on them, and permute for generating permutations.
For iteration, seq works with iterator pipelines and collects iterators as tables. Each of those is a separate require, so you load only what you use. The cost is a long list to learn. A newcomer's first hour goes to deciding which module owns a given function, for example utils versus stringx for string helpers.
Lambdas and comprehensions are written as strings
The functional modules take an unusual route. utils.string_lambda converts a short string like '|x| x^2' into a function. func handles symbolic manipulation of expressions and lambda expressions. comprehension builds list comprehensions, and the README shows C'x for x=1,4'() == {1,2,3,4}.
A class module provides a simple reusable class framework for object oriented code.
The tradeoff is clear. Writing logic as a string means Lua compiles it at runtime, so a typo in the string surfaces when the code runs, not when the file loads. Editors and static checkers cannot see inside the quotes, and the repository's own .luacheckrc will not analyse them either. Use the string forms for short expressions and keep real logic in ordinary functions.
Strict SemVer, with deprecation warnings that can appear in any release
Penlight is strictly versioned according to Semantic Versioning. In scope are the functionality of the modules and classes, running on stock Lua PuC-Rio or LuaJIT. Out of scope are documentation, textual changes in error messages and deprecation warnings, which go to stderr by default.
Any version may deprecate functionality, so new notices can appear in major, minor and patch releases. Final removal of a breaking change only happens in a major version. The README strongly suggests enabling the warning system when you upgrade:
require "pl.compat"
warn "@on"In Lua 5.4 warn is built in, and for earlier versions the pl.compat function supplies it. See pl.utils.raise_deprecation for more. Do not parse error message text in your code, since the project does not treat changes to it as breaking.
luarocks install penlight, or copy lua/pl into your module path
The LuaRocks route is one command, luarocks install penlight, on the module page under tieske. The manual route is copying the lua/pl directory into your Lua module path, typically /usr/local/share/lua/5.x on Linux and C:\Program Files\Lua\5.x\lua for Lua for Windows.
Tests run with lua run.lua tests, and examples with lua run.lua examples. Documentation builds with ldoc from LuaRocks, by running ldoc . in the repository. The repository carries a .busted file and a spec/ directory as well as the tests/ folder.
The repository has no GitHub releases, so versions come from rockspecs and the CHANGELOG.md file. The repository is not archived, and the last push was on 2026-09-03. The license is MIT.
Editorial conclusion
Choose Penlight if you write Lua applications or tools and want ready made path, table, string and argument parsing modules in the style of the Python standard library. Skip it if you need to avoid the LuaFileSystem dependency. Before upgrading, turn on the deprecation warnings and run your code, since any release can add them.
Frequently asked questions
What is Penlight, the Lua library?
Penlight is a set of pure Lua libraries focused on input data handling, functional programming and OS path management. Much of it is inspired by the Python standard libraries.
How do you install Penlight for Lua?
Run luarocks install penlight, or copy the lua/pl directory into your Lua module path. The file and directory functions depend on LuaFileSystem, which LuaRocks installs automatically.
How do you use Penlight in a Lua project?
Require the module you need, such as pl.path for paths or pl.compat for deprecation warnings. Run lua run.lua examples in the repository to see working samples.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/lunarmodules-penlight)Star history chart for your README
[](https://hysenlabs.com/projects/lunarmodules-penlight)Was this useful?