spdx
spdx.cr
SPDX license expression parser and SPDX 2.3 document toolkit for Crystal. Includes 740 embedded SPDX licenses (SPDX License List v3.29.0) with zero external dependencies.
Installation
Add the dependency to your shard.yml:
dependencies:
spdx:
github: hahwul/spdx.cr
Then run shards install.
Usage
Library
require "spdx"
# Parse license expression
ast = Spdx.parse("MIT AND Apache-2.0")
# Validate expression
Spdx.valid_expression?("MIT OR GPL-2.0-only") # => true
# Lookup license
license = Spdx.find_license("MIT")
license.name # => "MIT License"
license.osi_approved? # => true
# Check license existence
Spdx.license?("MIT") # => true
CLI
# License expression
spdx expression parse "MIT AND Apache-2.0"
spdx expression validate "GPL-2.0-only WITH Classpath-exception-2.0"
# License lookup
spdx license list --osi
spdx license info MIT
spdx license search apache
# SPDX document
spdx validate document.spdx.json
spdx convert document.spdx --format json
Examples
Runnable examples live in examples/:
crystal run examples/basic.cr # parse, valid_expression?, validate_expression
crystal run examples/license_lookup.cr # SPDX license & exception lookup with metadata
crystal run examples/document_io.cr # JSON ↔ Tag-Value document conversion
Features
- License expression parser with full operator precedence (AND, OR, WITH, +)
- 740 SPDX licenses and 86 exceptions (SPDX License List v3.29.0) embedded at compile time
- SPDX 2.3 document model with validation
- JSON and Tag-Value format support (parse / generate / convert)
- CLI tool
Contributing
- Fork it (https://github.com/hahwul/spdx.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request