{"id":28408926,"url":"https://github.com/librepcb/librepcb-parts-generator","last_synced_at":"2025-07-06T02:34:27.209Z","repository":{"id":43271453,"uuid":"141727981","full_name":"LibrePCB/librepcb-parts-generator","owner":"LibrePCB","description":"A collection of scripts to generate parts for the LibrePCB default library","archived":false,"fork":false,"pushed_at":"2025-04-20T12:23:36.000Z","size":7317,"stargazers_count":7,"open_issues_count":17,"forks_count":16,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-18T07:28:44.469Z","etag":null,"topics":[],"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/LibrePCB.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,"zenodo":null}},"created_at":"2018-07-20T15:21:37.000Z","updated_at":"2025-04-20T12:23:38.000Z","dependencies_parsed_at":"2023-01-21T13:45:46.122Z","dependency_job_id":"4db38b28-5f80-4ca1-933b-f9b03f5b64d2","html_url":"https://github.com/LibrePCB/librepcb-parts-generator","commit_stats":{"total_commits":337,"total_committers":9,"mean_commits":37.44444444444444,"dds":0.4688427299703264,"last_synced_commit":"3e4398af689bbb1fb0b02f6e19bf918f831f0386"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LibrePCB/librepcb-parts-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LibrePCB%2Flibrepcb-parts-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LibrePCB%2Flibrepcb-parts-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LibrePCB%2Flibrepcb-parts-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LibrePCB%2Flibrepcb-parts-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LibrePCB","download_url":"https://codeload.github.com/LibrePCB/librepcb-parts-generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LibrePCB%2Flibrepcb-parts-generator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261766569,"owners_count":23206648,"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":[],"created_at":"2025-06-02T04:38:08.231Z","updated_at":"2025-06-24T22:31:08.900Z","avatar_url":"https://github.com/LibrePCB.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LibrePCB Library Parts Generator Scripts\n\nThis is a collection of Python 3 based scripts to generate parts for the\n[LibrePCB](https://librepcb.org) default library.\n\n\n## Requirements\n\n- Python 3.8+\n- Dependencies in `pyproject.toml`\n\n\n## Introduction / Concepts\n\nWhile it's easy to create a one-off script to generate LibrePCB library\nelements, you quickly run into some issues:\n\n- If your output format does not match the canonical format used in LibrePCB,\n  your elements will be reformatted when opening them in the LibrePCB library\n  editor\n- When using random UUIDs, regenerating the library element with adjusted\n  parameters will result in a completely new library element (since it gets a\n  new UUID)\n- String concatenation results in messy and hard-to-modify generator scripts\n\nThis project uses a set of **entity wrapper types** that can be used to\ngenerate the corresponding library element. It also includes **helpers for\nthings like number formatting** as well as **a caching system for stable\nUUIDs**.\n\n### Entity Types\n\nThe entity types can be imported from the `entities` module. Unfortunately\nthere's no API documentation so far, so you'll have to take a look at the\n[source code](https://github.com/LibrePCB/librepcb-parts-generator/tree/master/entities)\nor rely on IDE autocompletion for now.\n\nFor example, instead of writing a symbol generator like this:\n\n```python\nlines = []\n\nlines.append('(librepcb_symbol {}'.format(uuid4()))\nlines.append(' (name \"{}\")'.format(\"Demo Symbol\"))\nlines.append(' (description \"{}\")'.format(\"A simple symbol with two pins.\"))\nlines.append(' (keywords \"{}\")'.format(','.join([\"simple\", \"demo\"]))\n# ...\nlines.append(' (pin {} (name \"1\")'.format(uuid4()))\nlines.append('  (position -10.16 0.0) (rotation 0.0) (length 2.54)')\nlines.append(' )')\nlines.append(' (pin {} (name \"2\")'.format(uuid4()))\nlines.append('  (position 10.16 0.0) (rotation 180.0) (length 2.54)')\nlines.append(' )')\n# ...\nprint('\\n'.join(lines))\n```\n\n...you can do something like this:\n\n```python\nfrom entities.common import Name, Description, Keywords, Position, Rotation, Length\nfrom entities.symbol import Symbol, Pin\n\n# Create symbol\nsymbol = Symbol(\n    str(uuid4()),\n    Name(\"Demo Symbol\"),\n    Description(\"A simple symbol with two pins.\"),\n    Keywords(\"simple,demo\"),\n    # ...\n)\n\n# Add pins\nsymbol.add_pin(Pin(str(uuid4()), Name(\"1\"), Position(-10.16, 0.0), Rotation(0.0), Length(2.54)))\nsymbol.add_pin(Pin(str(uuid4()), Name(\"2\"), Position(10.16, 0.0), Rotation(180.0), Length(2.54)))\n\n# ...\n\n# Print library element\nprint(str(symbol))\n```\n\nThis is much easier to write, read and maintain. Furthermore, since the\nentities are fully type annotated, you even benefit from type checking using\n[mypy](http://mypy-lang.org/)!\n\n### UUID Caching\n\nIn every generator script, you should first initialize the UUID cache:\n\n```python\nfrom common import init_cache, save_cache\n\n# Initialize UUID cache, load any pre-existing entries\nuuid_cache_file = 'uuid_cache_chip.csv'\nuuid_cache = init_cache(uuid_cache_file)\n```\n\nThe cache is a simple in-memory dictionary. The `init_cache` function will load\nany pre-existing cache entries from the file system.\n\nEvery generated UUID should have its own stable lookup key. Depending on the\nscript, a wrapper function that generates missing UUIDs on the fly might make\nsense:\n\n```python\ndef uuid(category: str, full_name: str, identifier: str, create: bool = True) -\u003e str:\n    \"\"\"\n    Return a UUID for the specified element.\n\n    Params:\n        category:\n            For example 'cmp' or 'pkg'.\n        full_name:\n            For example \"RESC3216X65\".\n        identifier:\n            For example 'pad-1' or 'pin-13'.\n    \"\"\"\n    key = '{}-{}-{}'.format(category, full_name, identifier).lower().replace(' ', '~')\n    if key not in uuid_cache:\n        if not create:\n            raise ValueError('Unknown UUID: {}'.format(key))\n        uuid_cache[key] = str(uuid4())\n    return uuid_cache[key]\n\npad_uuids = [\n    uuid('pkg', 'RESC3216X65', 'pad-1'),\n    uuid('pkg', 'RESC3216X65', 'pad-2'),\n]\n```\n\nAt the end of the generator script, all cached UUIDs should be persisted to the\nfile system.\n\n```python\n# Persist the cache to the file system\nsave_cache(uuid_cache_file, uuid_cache)\n```\n\n\n## Testing\n\nRun the tests using pytest:\n\n    $ pytest\n\n\n## License\n\nMIT, see `LICENSE` file\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrepcb%2Flibrepcb-parts-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibrepcb%2Flibrepcb-parts-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrepcb%2Flibrepcb-parts-generator/lists"}