### Development Environment Setup Source: https://github.com/amatobahn/figmapy/blob/master/CLAUDE.md Commands to install the development dependencies and verify the project state. ```bash pip install -e ".[dev]" pytest -q ruff check . ``` -------------------------------- ### Development environment setup and testing commands Source: https://github.com/amatobahn/figmapy/blob/master/README.md Commands to install development dependencies, run tests with mocks, and check code style using ruff. ```bash pip install -e ".[dev]" pytest # no network needed, every request is mocked ruff check . ``` -------------------------------- ### Versioning scheme examples Source: https://github.com/amatobahn/figmapy/blob/master/docs/versioning.md Examples of the date-based versioning format showing releases and patch fixes. ```text 2026.1.0 first release of 2026 2026.1.1 patch fix within that release 2026.2.0 second release of 2026 2027.1.0 first release of 2027 ``` -------------------------------- ### Install FigmaPy Source: https://github.com/amatobahn/figmapy/blob/master/README.md Command to install the package via pip. ```bash pip install FigmaPy ``` -------------------------------- ### Run figmapy examples with Figma token Source: https://github.com/amatobahn/figmapy/blob/master/examples/README.md Set the FIGMA_TOKEN environment variable and execute a script with a Figma file URL. ```bash export FIGMA_TOKEN=figd_... # Windows: set FIGMA_TOKEN=figd_... python examples/export_components.py https://www.figma.com/design/aBc123XyZ/My-File ``` -------------------------------- ### Run maintenance tasks by hand Source: https://github.com/amatobahn/figmapy/blob/master/docs/maintenance.md Commands for installing development dependencies, syncing the spec, regenerating files, and running tests. ```bash pip install -e ".[dev]" python tools/sync_spec.py --check # is there a newer spec? python tools/sync_spec.py # sync to the newest python tools/sync_spec.py --version 0.43.0 # sync to a specific one python tools/generate.py # regenerate from the vendored spec pytest -q # no network, every request is mocked ruff check . ``` -------------------------------- ### Broken package configuration in setup.py Source: https://github.com/amatobahn/figmapy/blob/master/docs/review-and-plan.md The package configuration incorrectly referenced 'FigmaPy' while the directory was named 'figmapy', resulting in an installation that contained no code. ```python packages=['FigmaPy'], # the directory on disk is lowercase `figmapy` ``` -------------------------------- ### Patch release workflow Source: https://github.com/amatobahn/figmapy/blob/master/docs/versioning.md Example of how bug fixes in hand-written code result in patch version increments. ```text 2026.1.0 initial release 2026.1.1 fix in figmapy/client.py 2026.2.0 next planned release (may include a new spec version) ``` -------------------------------- ### Call Figma API methods Source: https://github.com/amatobahn/figmapy/blob/master/README.md Examples of calling various API methods like fetching nodes, images, posting comments, and listing team projects. ```python figma.get_file_nodes("aBc123XyZ", ids=["1:2", "1:3"]) figma.get_images("aBc123XyZ", ids=["1:2"], format="svg", scale=2) figma.post_comment("aBc123XyZ", message="ship it") figma.get_team_projects("1234567890") ``` -------------------------------- ### Requesting an unsupported endpoint Source: https://github.com/amatobahn/figmapy/blob/master/README.md Use the request method to access Figma API endpoints that are not yet explicitly supported by the installed version of the package. ```python # An endpoint that shipped after your version of this package data = figma.request("POST", "/v1/files/aBc/some_new_thing", json_body={"x": 1}) ``` -------------------------------- ### Initialize Figma client with different authentication methods Source: https://github.com/amatobahn/figmapy/blob/master/README.md Shows how to initialize the client using a personal access token, environment variables, or an OAuth2 token. ```python figma = figmapy.Figma("figd_...") figma = figmapy.Figma() # reads FIGMA_TOKEN from the environment figma = figmapy.Figma(oauth_token, oauth2=True) # OAuth2 access token instead ``` -------------------------------- ### Using Node Helper Functions Source: https://github.com/amatobahn/figmapy/blob/master/MIGRATION.md Demonstrates the usage of the new free functions for walking nodes and retrieving image URLs. ```python from figmapy import walk, find_all, pages, page, image_urls file = figma.get_file(key) for node in walk(file.document): print(node.type, node.name) urls = image_urls(figma, key, find_all(file.document, type="COMPONENT"), format="svg") ``` -------------------------------- ### Initialize FigmaPy and extract text nodes Source: https://github.com/amatobahn/figmapy/blob/master/README.md Demonstrates initializing the Figma client and iterating through all text nodes in a file. ```python import figmapy figma = figmapy.Figma(token="figd_...") # or set FIGMA_TOKEN file = figma.get_file("aBc123XyZ") for text in figmapy.find_all(file.document, type="TEXT"): print(text.characters) ``` -------------------------------- ### Project file structure Source: https://github.com/amatobahn/figmapy/blob/master/docs/maintenance.md Overview of the repository layout and the roles of specific files. ```text spec/openapi.yaml Figma's official spec, vendored. The input to everything. spec/VERSION Which release of it. Single source of truth for the version. tools/generate.py spec -> figmapy/_endpoints.py + figmapy/models.py tools/sync_spec.py fetch a newer spec, regenerate, write a diff report figmapy/*.py hand written: client, errors, helpers, compat shims ``` -------------------------------- ### Migrating from AioHttpFigmaPy to AsyncFigma Source: https://github.com/amatobahn/figmapy/blob/master/MIGRATION.md Shows the transition from the deprecated AioHttpFigmaPy client to the new AsyncFigma context manager pattern. ```python # before from figmapy import AioHttpFigmaPy figma = AioHttpFigmaPy(token) # now import asyncio, figmapy async def main(): async with figmapy.AsyncFigma(token) as figma: return await asyncio.gather(figma.get_file(a), figma.get_file(b)) ``` -------------------------------- ### Release the project Source: https://github.com/amatobahn/figmapy/blob/master/docs/maintenance.md Command to tag a new release and push it to trigger the release workflow. ```bash git tag v2026.1.0 && git push --tags ``` -------------------------------- ### Project Layout Overview Source: https://github.com/amatobahn/figmapy/blob/master/CLAUDE.md A summary of the file structure and the roles of specific directories and files within the repository. ```text spec/openapi.yaml Figma's official spec, vendored. The input to everything. spec/VERSION Which release. The package version is this number. tools/generate.py spec -> the two generated modules tools/sync_spec.py fetch a newer spec, regenerate, write a diff report figmapy/client.py hand written: auth, transport, retries, error mapping figmapy/errors.py hand written: the exception hierarchy figmapy/helpers.py hand written: tree walking, URL parsing, batching figmapy/_compat.py hand written: names kept from 2018.1.0 tests/ offline, every request mocked with httpx.MockTransport ``` -------------------------------- ### Backward compatible FigmaPy usage Source: https://github.com/amatobahn/figmapy/blob/master/MIGRATION.md Demonstrates that the FigmaPy class, key= keyword, and get_file_images method remain functional via compatibility shims. ```python import figmapy figma = figmapy.FigmaPy(token) # FigmaPy is an alias for Figma figma.get_file(key="aBc123XyZ") # key= is still accepted figma.get_file_images(key, ids=["1:2"]) ``` -------------------------------- ### Dependency pinning options Source: https://github.com/amatobahn/figmapy/blob/master/docs/versioning.md Recommended syntax for pinning FigmaPy versions in requirements files. ```text Whatever is newest | `FigmaPy` A known-good release, plus patches | `FigmaPy==2026.1.*` Byte-for-byte reproducible | `FigmaPy==2026.1.0` ``` -------------------------------- ### Fetch multiple files asynchronously with AsyncFigma Source: https://github.com/amatobahn/figmapy/blob/master/README.md Use the AsyncFigma client with asyncio.gather to fetch multiple files concurrently. This is recommended when fetching many files at once. ```python import asyncio, figmapy async def main(): async with figmapy.AsyncFigma() as figma: keys = ["aBc", "dEf", "gHi"] files = await asyncio.gather(*(figma.get_file(k) for k in keys)) return [f.name for f in files] asyncio.run(main()) ``` -------------------------------- ### Traverse and query Figma files Source: https://github.com/amatobahn/figmapy/blob/master/README.md Use helper functions like find, find_all, and walk to navigate deeply nested Figma file structures. These functions operate on the file document and avoid redundant requests. ```python from figmapy import file_key_from_url, find, find_all, pages, page, walk, image_urls key = file_key_from_url("https://www.figma.com/design/aBc123XyZ/My-File?node-id=1-2") file = figma.get_file(key) pages(file) # the CANVAS nodes page(file, "Icons") # one page by name find(file.document, name="Button/Primary") # first match, or None find_all(file.document, type="COMPONENT") # every match find_all(file.document, where=lambda n: n.name.startswith("btn_")) for node in walk(file.document): # everything, depth first print(node.type, node.name) # One request for the whole batch, not one per node. urls = image_urls(figma, key, find_all(file.document, type="COMPONENT"), format="svg") ``` -------------------------------- ### Accessing version attributes Source: https://github.com/amatobahn/figmapy/blob/master/docs/versioning.md How to check the package version and the underlying Figma OpenAPI specification version. ```python figmapy.__version__ # '2026.1.0' figmapy.FIGMA_SPEC_VERSION # '0.42.0' - the Figma OpenAPI spec this was generated from ``` -------------------------------- ### Handling Figma Exceptions Source: https://github.com/amatobahn/figmapy/blob/master/MIGRATION.md Shows how to catch specific exceptions like FigmaNotFoundError instead of relying on None returns. ```python from figmapy import FigmaNotFoundError, FigmaAuthError, FigmaRateLimitError try: file = figma.get_file(key) except FigmaNotFoundError: ... ``` -------------------------------- ### File Traversal Helpers Source: https://github.com/amatobahn/figmapy/blob/master/README.md Utility functions for navigating and querying the deeply nested structure of Figma files. ```APIDOC ## File Traversal Helpers ### Description These helper functions allow users to extract specific nodes, pages, or image URLs from a Figma file object without manual tree traversal. ### Functions - `file_key_from_url(url)`: Extracts the file key from a Figma URL. - `pages(file)`: Returns all CANVAS nodes. - `page(file, name)`: Returns a specific page by name. - `find(node, name=None, type=None)`: Finds the first matching node. - `find_all(node, name=None, type=None, where=None)`: Finds all matching nodes based on criteria. - `walk(node)`: Generator for depth-first traversal of the file tree. - `image_urls(figma, key, nodes, format)`: Fetches image URLs for a list of nodes. ``` -------------------------------- ### AsyncFigma Client Source: https://github.com/amatobahn/figmapy/blob/master/README.md The AsyncFigma client provides an asynchronous interface for making concurrent requests to the Figma API, ideal for fetching multiple files simultaneously. ```APIDOC ## AsyncFigma Client ### Description The `AsyncFigma` client allows for non-blocking, asynchronous requests to the Figma API. It mirrors the synchronous client's surface area and is recommended for high-concurrency operations. ### Usage ```python import asyncio, figmapy async def main(): async with figmapy.AsyncFigma() as figma: keys = ["aBc", "dEf", "gHi"] files = await asyncio.gather(*(figma.get_file(k) for k in keys)) return [f.name for f in files] asyncio.run(main()) ``` ``` -------------------------------- ### Fixing a Failed Spec-Sync Pull Request Source: https://github.com/amatobahn/figmapy/blob/master/CLAUDE.md Commands to check out a spec-sync branch and verify the failure state. ```bash git fetch && git checkout spec-sync/ pip install -e ".[dev]" && pytest -q ``` -------------------------------- ### Spec and package version updates Source: https://github.com/amatobahn/figmapy/blob/master/docs/versioning.md Comparison of how spec versions and package versions are updated during maintenance. ```text spec/VERSION 0.42.0 -> 0.43.0 (written by sync_spec.py) pyproject.toml 2026.1.0 -> 2026.2.0 (updated manually before tagging) ``` -------------------------------- ### Maintaining Legacy None Return Behavior Source: https://github.com/amatobahn/figmapy/blob/master/MIGRATION.md Shows how to explicitly catch FigmaHTTPError to maintain the previous behavior of returning None on failure. ```python try: file = figma.get_file(key) except figmapy.FigmaHTTPError: file = None ``` -------------------------------- ### OAuth2 token exchange with httpx Source: https://github.com/amatobahn/figmapy/blob/master/MIGRATION.md The OAuth2 code-for-token exchange is now performed using httpx.post as it is not a standard Figma REST API endpoint. ```python httpx.post("https://api.figma.com/v1/oauth/token", data={ "client_id": ..., "client_secret": ..., "redirect_uri": ..., "code": ..., "grant_type": "authorization_code", }).json()["access_token"] ``` -------------------------------- ### Inadequate error handling pattern Source: https://github.com/amatobahn/figmapy/blob/master/docs/review-and-plan.md The original implementation used a generic exception catch that printed the error and returned None, leading to difficult-to-debug downstream errors. ```python except Exception as e: print(f'Error: {e}') return None ``` -------------------------------- ### Update Node Type Checking Source: https://github.com/amatobahn/figmapy/blob/master/MIGRATION.md Replace isinstance checks with node type string comparisons when working with node models. ```python # before from figmapy import datatypes as dt isinstance(node, dt.Text) # now node.type == "TEXT" ``` -------------------------------- ### Error Handling Source: https://github.com/amatobahn/figmapy/blob/master/README.md Exception classes provided by the library to handle specific API response states. ```APIDOC ## Error Handling ### Description Handle specific API failure scenarios using the provided exception classes. The library automatically retries 429 and 5xx errors with exponential backoff. ### Exceptions - `FigmaNotFoundError`: Raised for 404 errors. - `FigmaAuthError`: Raised for 401/403 errors (bad token or missing scope). - `FigmaRateLimitError`: Raised for 429 errors after retries are exhausted. - `FigmaHTTPError`: General HTTP error base class. ``` -------------------------------- ### Handle API errors Source: https://github.com/amatobahn/figmapy/blob/master/README.md Catch specific exceptions such as FigmaNotFoundError, FigmaAuthError, and FigmaRateLimitError to handle API failures gracefully. ```python from figmapy import FigmaAuthError, FigmaNotFoundError, FigmaRateLimitError, FigmaHTTPError try: figma.get_file(key) except FigmaNotFoundError: ... # 404 except FigmaAuthError: ... # 401 / 403, bad token or missing scope except FigmaRateLimitError as e: ... # 429, and the retries were already exhausted ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.