A Port of the Clojure Pretty Print Library to Basilisp
Basilisp is a Python-based Lisp implementation that offers broad compatibility with Clojure. For more details, check out the documentation.
Overview
basilisp-pprint is a source code port of the clojure.pprint core library to Basilisp.
The clojure.pprint library provides pretty formatting capabilities for common Clojure data structures such as lists, maps, sets, vectors, as well as Clojure code. The library allows for customizable printing through various options and parameters.
basilisp-pprint provides these capabilities to Basilisp as an external library, allowing you to use it while the native basilisp.pprint support (note the dot in the name) is still in development. This includes enhanced API features, such as the cl-format function.
Installation
To install basilisp-pprint, run:
pip install basilisp-pprint
Usage
To use the library, require it as basilisp-pprint.pprint in your Basilisp code.
For general usage instructions, refer to the clojure.pprint documentation.
Examples
Pretty Printing a Nested Map
;; https://clojuredocs.org/clojure.pprint/pprint#example-542692d0c026201cdc326ec5
(require '[basilisp-pprint.pprint :as p])
(def big-map (zipmap
[:a :b :c :d :e]
(repeat
(zipmap [:a :b :c :d :e]
(take 5 (range))))))
;; => #'user/big-map
big-map
;; => {:e {:e 4 :a 0 :c 2 :d 3 :b 1} :a {:e 4 :a 0 :c 2 :d 3 :b 1} :c {:e 4 :a 0 :c 2 :d 3 :b 1} :d {:e 4 :a 0 :c 2 :d 3 :b 1} :b {:e 4 :a 0 :c 2 :d 3 :b 1}}
(p/pprint big-map)
;; {:e {:e 4, :a 0, :c 2, :d 3, :b 1},
;; :a {:e 4, :a 0, :c 2, :d 3, :b 1},
;; :c {:e 4, :a 0, :c 2, :d 3, :b 1},
;; :d {:e 4, :a 0, :c 2, :d 3, :b 1},
;; :b {:e 4, :a 0, :c 2, :d 3, :b 1}}
Pretty Printing Clojure Code
;; https://clojuredocs.org/clojure.pprint/pprint#example-5b950e6ce4b00ac801ed9e8a
;;
;; get Clojure snippets to print nicely
(require '[basilisp-pprint.pprint :as p]
'basilisp.edn)
(def lost-formatting
"(defn op [sel] (condp = sel :plus + :minus - :mult *
:div / :rem rem :quot quot :mod mod))")
;; => #'user/lost-formatting
(p/with-pprint-dispatch
p/code-dispatch
(p/pprint
(basilisp.edn/read-string lost-formatting)))
;; (defn op [sel]
;; (condp = sel
;; :plus +
;; :minus -
;; :mult *
;; :div /
;; :rem rem
;; :quot quot
;; :mod mod))
Pretty Printing with Metadata
;; https://clojuredocs.org/clojure.pprint/pprint#example-6318f958e4b0b1e3652d765f
;;
;; pprint with metadata
(require '[basilisp-pprint.pprint :as p])
(binding [*print-meta* true]
(p/pprint ^{:hello :world} {}))
;; ^{:hello :world} {}
Pretty Printing Tables
;; https://clojuredocs.org/clojure.pprint/print-table#example-542692d6c026201cdc3270f1
;;
;; If there are keys not in the first row, and/or you want to specify only
;; some, or in a particular order, give the desired keys as the first arg.
(require '[basilisp-pprint.pprint :as p])
(p/print-table [:b :a] [{:a 1 :b 2 :c 3} {:b 5 :a 7 :c "dog"}])
;; | :b | :a |
;; |----+----|
;; | 2 | 1 |
;; | 5 | 7 |
Using cl-format
;; cl-format example
(require '[basilisp-pprint.pprint :as p])
(let [name "Alice"
born 1999
hobbies ["reading" "hiking" "hacking"]]
(-> (p/cl-format nil "Name: ~A~%Born: ~@R~%Hobbies: ~{~A~^, ~}~%"
name
born
hobbies)
print))
;; Name: Alice
;; Born: MCMXCIX
;; Hobbies: reading, hiking, hacking
Development and Testing
The approach taken for this port was to make as few changes as possible to the original clojure.pprint source code in order to maintain consistency. While the current implementations is feature-complete and works quite well, it has not yet been fully optimized for Python.
To run the test suite, use the following command:
basilsp test
License
This project is licensed under the Eclipse Public License 1.0. See the LICENSE file for details.
Acknowledgments
@chrisrink10, for developing Basilisp and ensuring API compatibility with Clojure, enabling smooth ports of Clojure source code to Python.
;;; pprint.clj -- Pretty printer and Common Lisp compatible format function (cl-format) for Clojure
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;; Author: Tom Faulhaber
;; April 3, 2009
;;
;; Porting to Basilisp initiated from Clojure,
;; based on the code available at
;; https://github.com/clojure/clojure/blob/08a2d9bdd013143a87e50fa82e9740e2ab4ee2c2/src/clj/clojure/pprint.clj
Metadata
Release files for basilisp-pprint 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| basilisp_pprint-0.2.0.tar.gz | 42.5 kB | With provenance | Details for basilisp_pprint-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| basilisp_pprint-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for basilisp_pprint-0.2.0-py3-none-any.whl |
Total release size: 84.7 kB
Release files / basilisp_pprint-0.2.0.tar.gz
| Download URL | basilisp_pprint-0.2.0.tar.gz |
|---|---|
| Size | 42.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
47683c06bc07982a28c3d1c721099d6d91f576733e0250c1ab036bebc64bd5e6
|
|
BLAKE2b-256 checksum How to use checksums |
021aced6bcf201a540f9b41c176f19f1d0ccf21aae1f7c955244537ce7d3a69e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 26, 2025.
Transparency logRelease files / basilisp_pprint-0.2.0-py3-none-any.whl
| Download URL | basilisp_pprint-0.2.0-py3-none-any.whl |
|---|---|
| Size | 42.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
68df68deeab75740c1ffe895ebaa462d7c1c2678022caedcf7aa161dcc1fa355
|
|
BLAKE2b-256 checksum How to use checksums |
6f79273acdb23c7d2e51b2d4405233a7658a9515dbab20e35438f9e3093124f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 26, 2025.
Transparency logSecurity for basilisp-pprint 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for basilisp_pprint-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 26, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.