Package: py-tailwind-utils
py-tailwind-utilsA library that makes working with Tailwind CSS in python easier. It provides
set of operators, functions, and python native objects that make it easier
to express and manipulate tailwind directives.Instead of styling a component of with a long string such "bg-pink-400 ring-offset-red-200 justify-content-start text-black-800", using
this library you would instead write the same as first class python statement:tstr(bg/pink/4,ring/offset/red/2,jc.start,fc/black/8)This has several advantages:makes manipulation of styles such as-- passing style directives to functions,-- substitution of style through variable assignment a lot easier.makes it feasible to do bookkeeping and analyis of style used across various components of an webpageis basis for theme manipulation, i.e., bulk modify styles of several components using a single command.A word of caution:
This library does pollute the namespace of your python file/module, so be careful if using "from py_tailwind_utils  import *".
Also, not all construct of tailwind is available here.UsageTailwind constructs as python objectsTo begin with the library exports name that reflect various tailwind constructs. For, e.g.bgreflects tailwind utility classbg,bdreflectsborderand so on. See table for
mapping between python constructs and tailwind constructs.Tailwind expression builderThe above python-tailwind constructs support division operator using which one can create tailwind styling expression
such as "bg-green-100", "ring-offset-red-200", etc. In py-tailwind-utils, these are expressed
as first class python objects asbg/green/1andring/offset/red/2.Tailwind utility as python enumsThe library provides enum classes that encapsulate options for a tailwind utility.
For e.g. for various options for justify content, the library provides enum classJustifyContent(orjc) as follows:class JustifyContent(Enum):
    start = "justify-start"
    end = "justify-end"
    center = "justify-center"
    between = "justify-between"
    evenly = "justify-evenly"
    around = "justify-around"The helps group directives or identify duplicates in a style definition.Tailwind modifier functionsmodifiers are expressed using functions over tailwind expression.
For example,hover(jc.end, bg/green/1, fc/blue/8)*hover(*focus(bg/green/400), *focus(*placeholder(noop/fw.bold), fc/pink/100))Convert python style expression to tailwind class expressionThetstrfunction converts python tailwind style expression to
string value containing tailwind directives.
In the example,from py_tailwind_utils import tstr
tstr(bg/pink/4, ring/offset/red/2, jc.start, fc/pink/8)tstrwill convert to proper tailwind definition:bg-pink-400 ring-offset-red-200 justify-start text-pink-800Append/merge tailwind directive to an existing style listProvidesconc_twtagsfunction to add/merge/append new directive  to an exisiting
list of styles.
For e.g.  ifmytags=[bg/green/1,fc/blue/1,flx.row,]is an exisiting set of styles, and if we addbg/blue/1usingconc_twtags, then it  will perform
a smart merge, i.e., it will override the exisiting directive
that belong to the same utility class.
So,classes=tstr(conc_twtags(*mytags,bg/blue/1))will result in:bg-blue-100 text-blue-100 flex-rowThis feature ofpy-tailwind-tagscomes in very useful for theme customization.Remove a tailwind directiveUseremove_from_twtag_listto remove a tailwind directive from an existing list.
An example:mytags=[bg/green/1,fc/blue/1,jc.start,flx.row,]remove_from_twtag_list(mytags,jc.start)Note: will throw ValueError if the request removeal object is not present in the list.Store tailwind styles as JsonAll the  styles applied to a component can be exported out as json, organized by utility
class. For example, to print out   json use command:res = tt.styClause.to_json(
    *hover(*focus(bg/green/400), *focus(*placeholder(noop/fw.bold), fc/pink/100)))which will output:
Theresout:{"passthrough":[],"bg":{"_val":"green-400","_modifier_chain":["hover","focus"]},"FontWeight":{"_val":"bold","_modifier_chain":["hover","focus","placeholder"]},"fc":{"_val":"pink-100","_modifier_chain":["hover","focus"]}}Load json back as tailwind styleFinally, once can read back the json, to convert the original tailwind style statement:claus = tt.styClause.to_clause(res)
print(tstr(*claus))Which outputs the original tailwind expressionhover:focus:bg-green-400 hover:focus:placeholder:font-bold hover:focus:text-pink-100Not supported featuresBackground opacity modifiers are not yet supportedSo, this expression will failAll supported tailwind constructs in python as keywords or Enum classesReferenceStyle Tagspython keywordtailwind constructbdborderfrom_fromto_tovia_toccNonecontainercontainerinheritinheritcurrentcurrenttransparenttransparentfirstfirstfullfullscreenscreenhiddenhiddenlastlastnonenonescrollscrollspanspantexttextvisiblevisibleautoautogroupgroupdoubledoubleclipclipinvisibleinvisibleabsoluteabsolutegrowgrowbgbgxxyydurationdurationinsetinsetmaxmaxminminoffsetoffsetopacityopacityorderorderringringrowrowrowsrowscolcolcolscolsspacespacestrokestrokegapgapendendfctextGgridHhlhleadingmrmovfoverflowpdpphplaceholderresizeresizesbbsllsrrstttoptoprightrightbottombottomleftleftstartstartWwzoznoopoutlineoutlineshadowshadowStyle valuesTailwind Utility ClassPython enum classpython attr namestailwind utilityDisplayBoxdbbblockbiinline-blockiinlinefflexfiinline-flexttableggridBoxLayoutdbbblockbiinline-blockiinlinefflexfiinline-flexttableggridWrapAroundwarfloat-rightlfloat-leftnfloat-noneClearWrapwclclear-leftrclear-rightbclear-bothnclear-noneObjectFitofcnobject-containcvobject-coverfobject-fillnobject-nonesdobject-scale-downObjectPositionopbobject-bottomcobject-centerlobject-leftlbobject-left-bottomltobject-left-toprobject-rightrbobject-right-bottomtobject-topVisibilityvisibilityvvisiblenvinvisibleFlexLayoutflxrowflex-rowrrowflex-row-reversecolflex-colrcolflex-col-reversewrapflex-wraprwrapflex-wrap-reversenowrapflex-nowraponeflex-1autoflex-autoinitialflex-initialnoneflex-nonegrowflex-grownogrowflex-grow-0shrinkflex-shrinknoshrinkflex-shrink-0JustifyContentjcstartjustify-startendjustify-endcenterjustify-centerbetweenjustify-betweenevenlyjustify-evenlyaroundjustify-aroundJustifyItemsjistartjustify-items-startendjustify-items-endcenterjustify-items-centerstretchjustify-items-stretchJustifySelfjsautojustify-self-autostartjustify-self-startendjustify-self-endcenterjustify-self-centerstretchjustify-self-stretchAlignContentacstartcontent-startendcontent-endcentercontent-centerbetweencontent-betweenevenlycontent-evenlyaroundcontent-aroundAlignItemsaistartitems-startenditems-endcenteritems-centerstretchitems-stretchbaselineitems-baselinePlaceContentpcstartplace-content-startendplace-content-endcenterplace-content-centerbetweenplace-content-betweenevenlyplace-content-evenlyaroundplace-content-aroundstretchplace-content-stretchPlaceItemspistartplace-items-startendplace-items-endcenterplace-items-centerstretchplace-items-stretchPlaceSelfpsautoplace-self-autostartplace-self-startendplace-self-endcenterplace-self-centerstretchplace-self-stretchFontFamilyffsansfont-sansseriffont-serifmonofont-monoFontSizefzxstext-xssmtext-sm_text-baselgtext-lgxltext-xlxl2text-2xlxl3text-3xlxl4text-4xlxl5text-5xlxl6text-6xlFontWeightfwthinfont-thinextralightfont-extralightlightfont-lightnormalfont-normalmediumfont-mediumboldfont-boldextraboldfont-extraboldblackfont-blacksemiboldfont-semiboldLetterSpacelstightertracking-tightertighttracking-tightnormaltracking-normalwidetracking-widewidertracking-widerwidesttracking-widestLineHeightlhnoneleading-nonetightleading-tightsnugleading-snugnormalleading-normalrelaxedleading-relaxedlooseleading-looseListItemslinonelist-nonedisclist-discdecimallist-decimalinsidelist-insideoutsidelist-outsideTextAligntalefttext-leftcentertext-centerrighttext-rightjustifytext-justifystarttext-startendtext-endTextTransformttuuppercasellowercaseccapitalizennormal-caseVerticalAlignvatopalign-topmiddlealign-middlebottomalign-bottomBackgroundAttachmentbafbg-fixedlbg-localsbg-scrollBorderRadiusbdrsmrounded-smmdrounded-mdlgrounded-lgfullrounded-fullnonerounded-noneBorderStylebdssolidborder-soliddashedborder-dasheddottedborder-dotteddoubleborder-doublenoneborder-nonecollapseborder-collapseseparateborder-separateOutlineoutlinenoneoutline-none_outlinedashedoutline-dasheddottedoutline-dotteddoubleoutline-doublehiddenoutline-hiddenBoxShadowshadowsmshadow-sm_shadowmdshadow-mdlgshadow-lgxlshadow-xlxl2shadow-2xlnoneshadow-noneinnershadow-innerTabletblautotable-autofixedtable-fixedBoxTopobtbdbordercontainercontainerPlacementPositionpposstaticstaticfixedfixedabsoluteabsoluterelativerelativestickystickyBoxSizingboxszbbox-bordercbox-contentProseprsesmprose-sm_prose-baselgprose-lgxlprose-xlxl2prose-2xlGridFlowgfrowgrid-flow-rowcolgrid-flow-colrowdgrid-flow-row-densecoldgrid-flow-col-denseGridAutogacautogrid-cols-autocmingrid-cols-mincmaxgrid-cols-maxcfrgrid-cols-frrautogrid-rows-autormingrid-ros-minrmaxgrid-rows-maxrfrgrid-rows-frEndNotesDocs (in readthedocs format):https://github.com/Monallabs-org/py-tailwind-utilsDeveloped By: webworks.monallabs.in