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 native Android and iOS resources from design tokens.

Features

  • Fluent, Pythonic API
  • Jetpack Compose theme generation for colors and dimensions
  • Supports all Android res/values/ types
  • Native Apple Asset Catalog (.xcassets) support
  • Wide Gamut support with automatic sRGB fallbacks
  • Built-in validation for resource names and color formats

Installation

pip install resforge

Quick Example

Android (Jetpack Compose)

from resforge.android import ComposeWriter

with ComposeWriter("Color.kt", "com.example.myapplication.ui.theme") as compose:
    compose.color(
        Purple80="#D0BCFF",
        PurpleGrey80="#CCC2DC",
        Pink80="#EFB8C8",
        Purple40="#6650a4",
        PurpleGrey40="#625b71",
        Pink40="#7D5260",
    )
package com.example.myapplication.ui.theme

import androidx.compose.ui.graphics.Color

val Purple80: Color = Color(0xFFD0BCFF)
val PurpleGrey80: Color = Color(0xFFCCC2DC)
val Pink80: Color = Color(0xFFEFB8C8)
val Purple40: Color = Color(0xFF6650A4)
val PurpleGrey40: Color = Color(0xFF625B71)
val Pink40: Color = Color(0xFF7D5260)

Android (XML Resources)

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="#6200EE",
        secondary="#03DAC5",
    )
    res.dimension(
        padding_small=dp(8),
        text_body=sp(16),
    )
<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="app_name">My App</string>
    <string name="welcome_message">Welcome!</string>
    <color name="primary">#FF6200EE</color>
    <color name="secondary">#FF00FF00</color>
    <dimen name="padding_small">8dp</dimen>
    <dimen name="text_body">16sp</dimen>
</resources>

Asset Catalog (iOS)

from resforge import Color
from resforge.apple import Appearance, AppleColor, AssetCatalog

with AssetCatalog("App", "Assets") as catalog:
    catalog.colorset(
        "MyColor",
        AppleColor(Color.p3(0.0, 1.0, 0.0)),
        AppleColor("#000000", appearances=[Appearance.Dark]),
    )
{
  "info": {
    "author": "xcode",
    "version": 1
  },
  "colors": [
    {
      "idiom": "universal",
      "color": {
        "components": {
          "red": "0.000",
          "green": "1.000",
          "blue": "0.000",
          "alpha": "1.000"
        },
        "color-space": "srgb"
      }
    },
    {
      "idiom": "universal",
      "color": {
        "components": {
          "red": "0.000",
          "green": "1.000",
          "blue": "0.000",
          "alpha": "1.000"
        },
        "color-space": "display-p3"
      },
      "display-gamut": "display-P3"
    },
    {
      "idiom": "universal",
      "color": {
        "components": {
          "red": "0.000",
          "green": "0.000",
          "blue": "0.000",
          "alpha": "1.000"
        },
        "color-space": "srgb"
      },
      "appearances": [
        {
          "appearance": "luminosity",
          "value": "dark"
        }
      ]
    }
  ]
}

Roadmap

  • SwiftUI dimensions
  • Typography
  • Images (ImageSet, IconSet, res/drawable vectors)

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.4.0.tar.gz (17.9 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.4.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for resforge-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a8d5b7858b7f68b2b9549ea35089b79ab349bf835e60c764cbc9e7ecff88b162
MD5 40d8a520528a0e6963710f72d25f669f
BLAKE2b-256 36456c0fe5b05f84ce3e842ce0e42fc8ab8afc4fb62bedd93227b9d47c78aaf6

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on kipila-dev/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.4.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for resforge-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c4ad9a84750be1213772c44fe9ca884b8b645bd1bfb5f9a3e9740a19f03b87e
MD5 a41a883e8f6a0ebe4b62c9691d25b971
BLAKE2b-256 dabfcd0153ac21a2c033aed7edc6aa9def198842b0d2273f50e769c2e201bcff

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on kipila-dev/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