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.2.tar.gz (18.2 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.2-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: resforge-0.4.2.tar.gz
  • Upload date:
  • Size: 18.2 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.2.tar.gz
Algorithm Hash digest
SHA256 fd3b92888c993db23d808c5c49a979249571228bda7e1434d83c8f1c14a4ff40
MD5 9282a71f7af08fa62da0d52acee9268f
BLAKE2b-256 523898e4725de2cd6ff93e0c56b85367127c9cfa224d541e46756f249d8f6ed2

See more details on using hashes here.

Provenance

The following attestation bundles were made for resforge-0.4.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: resforge-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 17.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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a4d9e58274fbcc160f8a00475fb3eb2cbb6fa99d7f94be4b8a6dfc5df5f21efd
MD5 81051f2e129dfafba0dd59ab81285494
BLAKE2b-256 57383901c0d78421e019024f052245356430f12ec13b70a0e2bc0605024af275

See more details on using hashes here.

Provenance

The following attestation bundles were made for resforge-0.4.2-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