{"id":13474949,"url":"https://github.com/messense/typst-py","last_synced_at":"2025-04-08T10:14:47.236Z","repository":{"id":149995721,"uuid":"622595297","full_name":"messense/typst-py","owner":"messense","description":"Python binding to typst","archived":false,"fork":false,"pushed_at":"2025-03-28T00:11:19.000Z","size":9532,"stargazers_count":165,"open_issues_count":5,"forks_count":13,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-01T09:32:51.278Z","etag":null,"topics":["typst"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/messense.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-04-02T15:20:04.000Z","updated_at":"2025-03-28T00:11:23.000Z","dependencies_parsed_at":"2023-04-19T14:24:44.867Z","dependency_job_id":"a8fc40da-9201-4709-ac4c-3c5c04d2206c","html_url":"https://github.com/messense/typst-py","commit_stats":{"total_commits":91,"total_committers":8,"mean_commits":11.375,"dds":"0.46153846153846156","last_synced_commit":"c1d8df2c1815ca08c0ba64ada8f10ac7d7e28b2b"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/messense%2Ftypst-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/messense%2Ftypst-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/messense%2Ftypst-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/messense%2Ftypst-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/messense","download_url":"https://codeload.github.com/messense/typst-py/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247819933,"owners_count":21001394,"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":["typst"],"created_at":"2024-07-31T16:01:16.183Z","updated_at":"2025-04-08T10:14:47.215Z","avatar_url":"https://github.com/messense.png","language":"Rust","readme":"# typst-py\n\n![CI](https://github.com/messense/typst-py/workflows/CI/badge.svg)\n[![PyPI](https://img.shields.io/pypi/v/typst.svg)](https://pypi.org/project/typst)\n\nPython binding to [typst](https://github.com/typst/typst),\na new markup-based typesetting system that is powerful and easy to learn.\n\n## Installation\n\n```bash\npip install typst\n```\n\n## Usage\n\n```python\nimport typst\n\n\n# Compile `hello.typ` to PDF and save as `hello.pdf`\ntypst.compile(\"hello.typ\", output=\"hello.pdf\")\n\n# Compile `hello.typ` to PNG and save as `hello.png`\ntypst.compile(\"hello.typ\", output=\"hello.png\", format=\"png\", ppi=144.0)\n\n# Or pass `hello.typ` content as bytes\nwith open(\"hello.typ\", \"rb\") as f:\n    typst.compile(f.read(), output=\"hello.pdf\")\n\n# Or return PDF content as bytes\npdf_bytes = typst.compile(\"hello.typ\")\n\n# Also for svg\nsvg_bytes = typst.compile(\"hello.typ\", format=\"svg\")\n\n# For multi-page export (the template is the same as the typst cli)\nimages = typst.compile(\"hello.typ\", output=\"hello{n}.png\", format=\"png\")\n\n# Or use Compiler class to avoid reinitialization\ncompiler = typst.Compiler(\"hello.typ\")\ncompiler.compile(format=\"png\", ppi=144.0)\n\n# Query something\nimport json\n\nvalues = json.loads(typst.query(\"hello.typ\", \"\u003cnote\u003e\", field=\"value\", one=True))\n```\n\n## Passing values\n\nYou can pass values to the compiled Typst file with the `sys_inputs` argument. For example:\n\n```python\nimport json\nimport typst\n\npersons = [{\"name\": \"John\", \"age\": 35}, {\"name\": \"Xoliswa\", \"age\": 45}]\nsys_inputs = {\"persons\": json.dumps(persons)}\n\ntypst.compile(input=\"main.typ\", output=\"ages.pdf\", sys_inputs=sys_inputs)\n```\n\nThe following example shows how the passed data can be used in a Typst file.\n\n```\n#let persons = json(bytes(sys.inputs.persons))\n\n#for person in persons [\n  #person.name is #person.age years old. \\\n]\n```\n\n## License\n\nThis work is released under the Apache-2.0 license. A copy of the license is provided in the [LICENSE](./LICENSE) file.\n","funding_links":[],"categories":["Rust","Integrations \u0026 Tools","编程"],"sub_categories":["Programming","杂项"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmessense%2Ftypst-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmessense%2Ftypst-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmessense%2Ftypst-py/lists"}