configparser
Base module for pyRevit config parsing.
Classes
ConfigSection(section_name, configuration)
Bases: object
Read/write access to the options of a single config section.
Options can be accessed either as attributes (section.option) or
through the explicit get_option/set_option methods. Values are
stored as JSON and decoded tolerantly on read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_name
|
str
|
canonical name of the section |
required |
configuration
|
the backing |
required |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
Attributes
header
property
str: Full canonical name of this section.
subheader
property
str: Last component of the section's canonical name.
Methods:
has_option(option_name)
Check if this section contains the given option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option_name
|
str
|
name of the option |
required |
Returns:
| Type | Description |
|---|---|
bool
|
whether the option exists |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
get_option(op_name, default_value=None)
Get the value of an option, decoding it tolerantly.
A missing key returns default_value; an explicitly stored empty
string is treated as a real value. Values that are not valid JSON
(legacy single-quoted strings, Python bools, bare paths) are decoded
tolerantly rather than raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op_name
|
str
|
name of the option |
required |
default_value
|
value to return when the option is not set |
None
|
Returns:
| Type | Description |
|---|---|
|
the decoded option value, or |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
set_option(op_name, value)
Set the value of an option, encoding it as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op_name
|
str
|
name of the option |
required |
value
|
value to store |
required |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
remove_option(option_name)
Remove an option from this section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option_name
|
str
|
name of the option |
required |
Returns:
| Type | Description |
|---|---|
bool
|
whether an option was removed |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
has_subsection(section_name)
add_subsection(section_name)
Add subsection to section.
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
get_subsections()
Return all subsections nested under this section.
Returns:
| Type | Description |
|---|---|
list[ConfigSection]
|
the nested subsections |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
get_subsection(section_name)
Return the named subsection nested under this section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_name
|
str
|
short name of the subsection |
required |
Returns:
| Type | Description |
|---|---|
ConfigSection
|
the subsection, or None if not found |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
ConfigSections(configuration_service)
Bases: object
Access the sections of the default configuration.
Sections can be reached either as attributes (sections.core) or
through the explicit section methods. Iterating yields section names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configuration_service
|
the backing |
required |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
Methods:
has_section(section_name)
Check if the config contains the given section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_name
|
str
|
name of the section |
required |
Returns:
| Type | Description |
|---|---|
bool
|
whether the section exists |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
add_section(section_name)
Add a new section to the config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_name
|
str
|
name of the section |
required |
Returns:
| Type | Description |
|---|---|
ConfigSection
|
the added section |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
get_section(section_name)
Get the named config section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_name
|
str
|
name of the section |
required |
Returns:
| Type | Description |
|---|---|
ConfigSection
|
the requested section |
Raises:
| Type | Description |
|---|---|
AttributeError
|
if the section does not exist |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
remove_section(section_name)
Remove the named section, and its subsections, from the config.
Subsections are stored as sibling sections under a dotted name rather than nested inside their parent, so they must be found and removed explicitly here - dropping the parent alone would leave them behind for a reinstall to silently inherit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_name
|
str
|
name of the section |
required |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
save()
Write pending changes to the backing file.
Option writes land in the in-memory store only, so a caller that edits a config must call this for the change to survive the session.
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
Functions:
decode_option_value(raw_value)
Decode a stored option value across every encoding pyRevit has written.
Falls through, in order: the JSON candidates in :func:_json_candidates;
a bare unquoted Python bool (True/False, case-insensitive - a
string that merely spells "True" is stored quoted and already decoded by
the JSON pass); a bare hex integer (e.g. 0x0, which JSON's number
grammar rejects). Matching the C# reader's fallback order here is what
keeps the two readers agreeing on the same stored value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_value
|
str
|
stored value text |
required |
Returns:
| Type | Description |
|---|---|
|
the decoded value, or the raw text when no encoding accounts for it |
Source code in pyrevitlib/pyrevit/coreutils/configparser.py
open_config_file(cfg_file_path, read_only=False)
Open an ini file of your own, separate from the pyRevit user config.
For tool settings that belong in their own file rather than in the shared
pyRevit config. To read or write the shared config, use
:obj:pyrevit.userconfig.user_config instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg_file_path
|
str
|
path to the ini file; it need not exist yet |
required |
read_only
|
bool
|
open without allowing writes |
False
|
Returns:
| Type | Description |
|---|---|
ConfigSections
|
the sections of the given file |
Note
Imports pyrevit.labs locally: that module imports this one, so a
module-level import here would close the cycle.