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!",
    ).color(
        primary="#6200EE",
        secondary="#03DAC5",
    ).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.3.tar.gz (16.8 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.3-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: resforge-0.4.3.tar.gz
  • Upload date:
  • Size: 16.8 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.3.tar.gz
Algorithm Hash digest
SHA256 88872cd0187a97f501afdce58e2819f546f0203d7ffdc0f3c55053609fbd6bbe
MD5 8bd711af671b8094ab516841bc648f1c
BLAKE2b-256 b09c9417158e1945984234c175ac2b355039ae039d2049f739cc35f57b28e2ba

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on kipila-dev/forje

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.3-py3-none-any.whl.

File metadata

  • Download URL: resforge-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 16.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 44711c3d0fd1b6627f3116b52fecb78d5fbf1f8525722900679a826858796e21
MD5 31785fbee7b7d6bc57b0d73ab38884e6
BLAKE2b-256 25faea6ba446243011ae51eea1bf0eefd11db56bccba1d9c51b084e3828143be

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on kipila-dev/forje

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