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 with type-safe color and dimension properties
  • Supports all Android res/values/ types
  • Native Apple Asset Catalog (.xcassets) with dark mode support
  • Built-in validation for resource names and color formats

Installation

pip install resforge

Quick Example

Android (Jetpack Compose)

from resforge.android import ComposeWriter, dp

with ComposeWriter("Theme.kt", "dev.kipila.example") as compose:
    compose.dimension(border=dp(8))
    with compose.object_("AppColors") as colors:
        colors.color(primary="#FF0000", background="#FFFFFF")
package dev.kipila.example

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

val border: Dp = 8.dp

object AppColors {
    val primary: Color = Color(0xFFFF0000)
    val background: Color = Color(0xFFFFFFFF)
}

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="#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"
        }
      ]
    }
  ]
}

Roadmap

  • Asset Catalog image support (ImageSet, IconSet)
  • Android res/drawable vector asset support

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.3.1.tar.gz (16.6 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.3.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for resforge-0.3.1.tar.gz
Algorithm Hash digest
SHA256 9a1b4660b10798ec34105907ae935cf8c2bab29fe2e2ca2d6014cce8b900e9cf
MD5 9dba8eb5b235fb9caac1baaf850dc436
BLAKE2b-256 348f405e39aa9b5b4d63ded51582965fd4850ddf6751e6d31f9336f864ecc06d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: resforge-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e643ebcd157e4ea552d0bf5f05aa9ec39cc19b0e9926d4c71ac9810655ff034
MD5 3070db7a023cde59761540c3242c1762
BLAKE2b-256 779f7892193217bedee5b008bbeb660e5824d7911308ae61ef22ad692d2ef873

See more details on using hashes here.

Provenance

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