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

  • SwiftUI color extension generation (SwiftUIWriter)
  • 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.0.tar.gz (15.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.3.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: resforge-0.3.0.tar.gz
  • Upload date:
  • Size: 15.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.3.0.tar.gz
Algorithm Hash digest
SHA256 eb8bc9fa207639a271705083eb713f6b5bc85a3cf971c688f72b68f5bc03ffa8
MD5 f924457fe890749fc513078d756214e2
BLAKE2b-256 cbc0239203d2744f45a588cceb58e08ef2367f11d0b4fe80b90fe71a371b7aaa

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: resforge-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c0f386114a47e3f317c32d9942ab048cbf9acb119b3a770099ed9f541e404f5
MD5 4469f7603d959e0f87fb669740340cf9
BLAKE2b-256 0d0cf5e04249acc9b590482262668a16b9dafe8f61541a330d54564b5afa31ea

See more details on using hashes here.

Provenance

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