@@ -644,36 +644,112 @@ target language English (`"EN"`) supports translations to both American English
644644### Style Rules
645645
646646Style rules allow you to customize your translations using a managed, shared list
647- of rules for style, formatting, and more. Multiple style rules can be stored with
647+ of rules for style, formatting, and more. Multiple style rules can be stored with
648648your account, each with a user-specified name and a uniquely-assigned ID.
649649
650- #### Creating and managing style rules
650+ #### Creating a style rule
651651
652- Currently style rules must be created and managed in the DeepL UI via
653- https://www.deepl.com/en/custom-rules . Full CRUD functionality via the APIs will
654- come shortly.
652+ Use ` create_style_rule() ` to create a new style rule with a name and language
653+ code. You can optionally provide ` configured_rules ` and ` custom_instructions ` .
655654
656- #### Listing all style rules
655+ ``` python
656+ style_rule = deepl_client.create_style_rule(
657+ name = " My Style Rule" ,
658+ language = " en" ,
659+ )
660+ print (f " Created: { style_rule.name} ( { style_rule.style_id} ) " )
661+ ```
662+
663+ #### Retrieving and listing style rules
664+
665+ Use ` get_style_rule() ` to retrieve a single style rule by ID, or
666+ ` get_all_style_rules() ` to list all style rules.
657667
658668` get_all_style_rules() ` returns a list of ` StyleRuleInfo ` objects
659669corresponding to all of your stored style rules. The method accepts optional
660670parameters: ` page ` (page number for pagination, 0-indexed), ` page_size ` (number
661- of items per page), and ` detailed ` (whether to include detailed configuration
662- rules in the ` configured_rules ` property).
671+ of items per page), and ` detailed ` . When ` True ` , the response includes
672+ ` configured_rules ` and ` custom_instructions ` for each style rule. When ` False `
673+ (default), these fields are omitted for faster responses.
663674
664675``` python
665- # Get all style rules
676+ # Get a single style rule by ID
677+ style_rule = deepl_client.get_style_rule(" YOUR_STYLE_ID" )
678+ print (f " { style_rule.name} ( { style_rule.language} ) " )
679+
680+ # List all style rules
666681style_rules = deepl_client.get_all_style_rules()
667682for rule in style_rules:
668683 print (f " { rule.name} ( { rule.style_id} ) " )
669684
670- # Get style rules with detailed configuration
685+ # List with detailed configuration
671686style_rules = deepl_client.get_all_style_rules(detailed = True )
672687for rule in style_rules:
673688 if rule.configured_rules:
674689 print (f " Number formatting: { rule.configured_rules.numbers} " )
675690```
676691
692+ #### Updating a style rule
693+
694+ Use ` update_style_rule_name() ` to rename a style rule, and
695+ ` update_style_rule_configured_rules() ` to update its configured rules.
696+
697+ ``` python
698+ # Update the name
699+ updated = deepl_client.update_style_rule_name(" YOUR_STYLE_ID" , " New Name" )
700+
701+ # Update configured rules
702+ updated = deepl_client.update_style_rule_configured_rules(
703+ " YOUR_STYLE_ID" ,
704+ {" style_and_tone" : {" formality" : " formal" }},
705+ )
706+ ```
707+
708+ #### Managing custom instructions
709+
710+ Custom instructions allow you to add free-text prompts to a style rule. Use
711+ ` create_style_rule_custom_instruction() ` , ` get_style_rule_custom_instruction() ` ,
712+ ` update_style_rule_custom_instruction() ` , and
713+ ` delete_style_rule_custom_instruction() ` to manage them.
714+
715+ ``` python
716+ # Create a custom instruction
717+ instruction = deepl_client.create_style_rule_custom_instruction(
718+ " YOUR_STYLE_ID" ,
719+ label = " Formal tone" ,
720+ prompt = " Always use formal language" ,
721+ )
722+ print (f " Created instruction: { instruction.id} " )
723+
724+ # Get a custom instruction
725+ instruction = deepl_client.get_style_rule_custom_instruction(
726+ " YOUR_STYLE_ID" , instruction.id
727+ )
728+
729+ # Update a custom instruction
730+ updated = deepl_client.update_style_rule_custom_instruction(
731+ " YOUR_STYLE_ID" ,
732+ instruction.id,
733+ label = " Updated label" ,
734+ prompt = " Use very formal language" ,
735+ )
736+
737+ # Delete a custom instruction
738+ deepl_client.delete_style_rule_custom_instruction(
739+ " YOUR_STYLE_ID" , instruction.id
740+ )
741+ ```
742+
743+ #### Deleting a style rule
744+
745+ Use ` delete_style_rule() ` to delete a style rule by ID.
746+
747+ ``` python
748+ deepl_client.delete_style_rule(" YOUR_STYLE_ID" )
749+ ```
750+
751+ #### Using a style rule in translations
752+
677753Style rules can also be used with the command line interface for text translation:
678754
679755``` bash
0 commit comments