Skip to main content

A type-safe Python DSL for cross-platform mobile resource generation

Project description

resforge

A type-safe Python DSL for generating Android XML resources and Xcode Asset Catalogs (.xcassets).

Installation

pip install resforge

Quick Example

Android

from resforge.android import ValuesWriter, dp, sp

with ValuesWriter("res/values/resources.xml") as res:
    res.string(
        app_name="My App",
        welcome_message="Welcome!",
    )

    res.color(
        primary="#FF6200EE",
        secondary="#FF03DAC5",
    )

    res.dimension(
        padding_small=dp(8),
        text_body=sp(16),
    )
<resources>
    <string name="app_name">My App</string>
    <string name="welcome_message">Welcome!</string>

    <color name="primary">#FF6200EE</color>
    <color name="secondary">#FF03DAC5</color>

    <dimen name="padding_small">8dp</dimen>
    <dimen name="text_body">16sp</dimen>
</resources>

Asset Catalog (iOS)

from resforge.apple import Appearance, AppleColor, AssetCatalog

with AssetCatalog("App", "Assets") as ac:
    ac.colorset(
        "Background",
        "#ffffff",
        AppleColor("#000000", appearances=[Appearance.Dark]),
    )
{
  "info": {
    "author": "xcode",
    "version": 1
  },
  "colors": [
    {
      "idiom": "universal",
      "color": {
        "components": {
          "red": "1.000",
          "green": "1.000",
          "blue": "1.000",
          "alpha": "1.000"
        },
        "color-space": "srgb"
      }
    },
    {
      "idiom": "universal",
      "color": {
        "components": {
          "red": "0.000",
          "green": "0.000",
          "blue": "0.000",
          "alpha": "1.000"
        },
        "color-space": "srgb"
      },
      "appearances": [
        {
          "appearance": "luminosity",
          "value": "dark"
        }
      ]
    }
  ]
}

Features

  • Fluent, Pythonic API
  • Supports all Android res/values/ types
  • Built-in validation for Asset Catalog logic

Full Android Example

from resforge.android import PluralValues, ValuesWriter, dp, sp

with ValuesWriter("res/values/resources.xml") as res:
    res.comment("Strings")
    res.string(
        app_name="My App",
        welcome_message="Welcome to My App!",
    )

    res.comment("Booleans")
    res.boolean(
        feature_enabled=True,
        dark_mode=False,
    )

    res.comment("Colors")
    res.color(
        primary="#FF6200EE",
        secondary="#FF03DAC5",
        accent="#6200EE",
    )

    res.comment("Dimensions")
    res.dimension(
        padding_small=dp(8),
        padding_large=dp(24),
        text_body=sp(16),
        text_heading=sp(24),
    )

    res.comment("Integers")
    res.integer(
        max_retries=3,
        timeout_seconds=30,
    )

    res.comment("Resource IDs")
    res.res_id("btn_submit", "tv_title", "iv_logo")

    res.comment("String arrays")
    res.string_array("planets", ["Mercury", "Venus", "Earth", "Mars"])

    res.comment("Integer arrays")
    res.integer_array("fibonacci", [1, 1, 2, 3, 5, 8, 13])

    res.comment("Typed arrays")
    res.typed_array(
        "icons", ["@drawable/home", "@drawable/settings", "@drawable/logout"]
    )

    res.comment("Plurals")
    res.plurals(
        item_count=PluralValues(one="%d item", other="%d items"),
        file_count=PluralValues(one="%d file", other="%d files"),
    )

    res.comment("Styles")
    res.style(
        "AppTheme",
        parent="Theme.MaterialComponents.DayNight",
        colorPrimary="@color/primary",
        colorSecondary="@color/secondary",
    )

Roadmap

  • Support for more Asset Catalog types (ImageSet, IconSet)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

resforge-0.2.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

resforge-0.2.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file resforge-0.2.0.tar.gz.

File metadata

  • Download URL: resforge-0.2.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for resforge-0.2.0.tar.gz
Algorithm Hash digest
SHA256 43307c70a9ca17f0615a60baa1d27f30c73f67514797970e26bf263b456a9f24
MD5 790d0be637a9e1a3001194925aba9a8c
BLAKE2b-256 01de929b822c5aa03d22d60fced9726c5806e1e00aea29e80c10fc0a34cf4100

See more details on using hashes here.

Provenance

The following attestation bundles were made for resforge-0.2.0.tar.gz:

Publisher: publish.yml on ok100/resforge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file resforge-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: resforge-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for resforge-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd6f0bc515dc9924e4dc2c1748613d5f32153efdd7078afa04150ebd55cdc3d8
MD5 c365cfa08da530fea741514e2e024826
BLAKE2b-256 15023cffc0527675016476c19cb46d950c88378a1cd2089054d84e80c3747cd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for resforge-0.2.0-py3-none-any.whl:

Publisher: publish.yml on ok100/resforge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page