{"id":13478472,"url":"https://github.com/chalk-diagrams/chalk","last_synced_at":"2026-04-09T04:01:25.050Z","repository":{"id":37035349,"uuid":"444481171","full_name":"chalk-diagrams/chalk","owner":"chalk-diagrams","description":"A declarative drawing API in Python","archived":false,"fork":false,"pushed_at":"2024-08-28T04:48:21.000Z","size":61829,"stargazers_count":294,"open_issues_count":20,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-04T22:37:24.516Z","etag":null,"topics":["cairo","declarative-language","drawing","edsl","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chalk-diagrams.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-04T16:03:58.000Z","updated_at":"2025-02-11T07:20:09.000Z","dependencies_parsed_at":"2024-01-16T07:22:07.322Z","dependency_job_id":"7fbf2be9-2c06-4bae-9c11-74349696d438","html_url":"https://github.com/chalk-diagrams/chalk","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk-diagrams%2Fchalk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk-diagrams%2Fchalk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk-diagrams%2Fchalk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalk-diagrams%2Fchalk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chalk-diagrams","download_url":"https://codeload.github.com/chalk-diagrams/chalk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245802452,"owners_count":20674668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cairo","declarative-language","drawing","edsl","python"],"created_at":"2024-07-31T16:01:57.515Z","updated_at":"2025-10-21T19:27:00.803Z","avatar_url":"https://github.com/chalk-diagrams.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/examples/output/logo-sm.png\" width=300\u003e\u003c/p\u003e\n\nChalk is a declarative drawing library.\nThe API draws heavy inspiration from\nHaskell's [diagrams](https://diagrams.github.io/),\nScala's [doodle](https://github.com/creativescala/doodle/) and\nJeremy Gibbons's lecture notes on [Functional Programming for Domain−Specific Languages](http://www.cs.ox.ac.uk/publications/publication7583-abstract.html).\n\nThe documentation is available at [https://chalk-diagrams.github.io](https://chalk-diagrams.github.io).\n\n⚠️ The library is still very much work in progress and subject to change.\n\n## Installation\n\nThe library is available on PyPI as `chalk-diagrams` and can be installed with `pip`:\n\n```bash\npip install git+https://github.com/chalk-diagrams/chalk/\n```\n\nOn Debian (or Colab) you will need to install Cairo for [PyCairo](https://pycairo.readthedocs.io)\n\n```bash\nsudo apt-get install libcairo2-dev\n```\n\nIf you want to use the LaTeX extension, run:\n\n```bash\npip install chalk-diagrams[latex]\n```\n\nFor the LaTeX extension you might need to install `pdf2svg` and `texlive`;\non Debian these dependencies can be installed as follows:\n\n```bash\nsudo apt-get install pdf2svg texlive texlive-science texlive-latex-recommended texlive-latex-extra\n```\n\n**Installation with Conda**\n\nYou can install the library with **conda** from `conda-forge` channel.\n\n```powershell\nconda install -c conda-forge chalk-diagrams\n```\n\n## Overview\n\nBelow we provide a brief introduction of the main functionality of the library.\nThese examples are available in the `examples/intro.py` file.\n\nWe start by importing the [`colour`](https://github.com/vaab/colour) module and the `diagrams` functions:\n\n```python\nfrom colour import Color\nfrom chalk import *\n```\n\nWe also define some colors that will be shortly used:\n\n```python\npapaya = Color(\"#ff9700\")\nblue = Color(\"#005FDB\")\n```\n\nWe can easily create basic shapes (the functions `circle`, `square`, `triangle`) and style them with various attributes (the methods`fill_color`, `line_color`, `line_width`).\nFor example:\n\n```python\nd = circle(1).fill_color(papaya)\n```\n\n![circle](https://raw.githubusercontent.com/chalk-diagrams/chalk/master/examples/output/intro-01.png)\n\nThe diagram can be saved to an image using the `render` method:\n\n```python\nd.render(\"examples/output/intro-01.png\", height=64)\n```\n\nWe can glue together two diagrams using the combinators `atop` (or `+`), `beside` (or `|`), `above` (or `/`).\nFor example:\n\n```python\ncircle(0.5).fill_color(papaya) | square(1).fill_color(blue)\n```\n\nwhich is equivalent to\n\n```python\ncircle(0.5).fill_color(papaya).beside(square(1).fill_color(blue), unit_x)\n```\n\nThis code produces the following image:\n\n![atop](https://raw.githubusercontent.com/chalk-diagrams/chalk/master/examples/output/intro-02.png)\n\nWe also provide combinators for a list of diagrams:\n`hcat` for horizontal composition, `vcat` for vertical composition.\nFor example:\n\n```python\nhcat(circle(0.1 * i) for i in range(1, 6)).fill_color(blue)\n```\n![hcat](https://raw.githubusercontent.com/chalk-diagrams/chalk/master/examples/output/intro-03.png)\n\nWe can use Python functions to build more intricate diagrams:\n\n```python\ndef sierpinski(n: int, size: int) -\u003e Diagram:\n    if n \u003c= 1:\n        return triangle(size)\n    else:\n        smaller = sierpinski(n - 1, size / 2)\n        return smaller.above((smaller | smaller).center_xy())\n\nd = sierpinski(5, 4).fill_color(papaya)\n```\n\n![sierpinski](https://raw.githubusercontent.com/chalk-diagrams/chalk/master/examples/output/intro-04.png)\n\n### Gallery of examples\n\nFor more examples, please check the `examples` folder;\ntheir output is illustrated below:\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/squares.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/squares.py\"\u003esquares.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/logo.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/logo.py\"\u003elogo.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/escher-square-limit.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/escher_square_limit.py\"\u003eescher_square_limit.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/hilbert.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/hilbert.py\"\u003ehilbert.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/koch.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/koch.py\"\u003ekoch.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/hex-variation.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/hex_variation.py\"\u003ehex-variation.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/lenet.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/lenet.py\"\u003elenet.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/tensor.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/tensor.py\"\u003etensor.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/hanoi.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/hanoi.py\"\u003ehanoi.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/tree.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/tree.py\"\u003etree.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003ctd align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/chalk-diagrams/chalk/master/doc/imgs/lattice.png\"\u003e\u003cbr\u003e\u003ccode\u003e\u003ca href=\"https://github.com/chalk-diagrams/chalk/tree/master/examples/lattice.py\"\u003elattice.py\u003c/a\u003e\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c!--\u003ctr\u003e\n\u003c/tr\u003e\n--\u003e\n\u003c/table\u003e\n\nThese scripts can be run as follows:\n\n```bash\npython examples/squares.py\n```\n\n## Authors\n\n- [Dan Oneață](http://doneata.bitbucket.io/)\n- [Alexander Rush](http://rush-nlp.com/)\n\nSpecial thanks to:\n- [Sugato Ray](https://github.com/sugatoray/), for his significant contributions and suggestions;\n- [Ionuț G. Stan](http://igstan.ro/), for providing many useful insights and comments.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalk-diagrams%2Fchalk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchalk-diagrams%2Fchalk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalk-diagrams%2Fchalk/lists"}