Free tools Windows power users keep installed
One-click scans. No signup required.
Use Python’s built-in configparser to read and write a sectioned INI-style configuration file. For TOML input, use tomllib on Python 3.11 or later; for JSON, use the standard-library json module. The right choice depends on your file format, Python version, and whether your program needs to write settings back.
Read an INI configuration file with configparser
A configuration file keeps settings outside your Python source code. An INI-style file groups key-value options into sections, which configparser.ConfigParser can read. For example, save this as settings.ini:
[server]
host = localhost
port = 8080
Then load it from Python:
import configparser
config = configparser.ConfigParser()
config.read("settings.ini", encoding="utf-8")
host = config["server"]["host"]
port = config["server"].getint("port", fallback=8080)
print(host, port)
Here, host is a string and port is converted to an integer. The Python 3.14.8 configparser documentation describes sections, options, and typed accessors.
Choose how to handle missing files
ConfigParser.read() returns the filenames it successfully read and ignores files it cannot open. That makes it suitable for optional configuration locations, but it can conceal a missing required file. If the file must exist, open it and use read_file() so the failure is reported:
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
import configparser
config = configparser.ConfigParser()
with open("settings.ini", encoding="utf-8") as file:
config.read_file(file)
host = config["server"]["host"]
Convert values to the types your code needs
INI options are read as strings. Use the typed getters when expecting numbers or booleans; invalid text raises a conversion error instead of being silently treated as a valid value.
port = config["server"].getint("port", fallback=8080)
ratio = config["display"].getfloat("scale", fallback=1.0)
enabled = config["feature"].getboolean("enabled", fallback=False)
Set fallbacks only where a missing option has a sensible default. If a setting is required, access it without a fallback so a missing option is not mistaken for an intentional default.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Choose the configuration format
| Format | Standard-library route | Best fit | Limitation |
|---|---|---|---|
| INI-like | configparser |
Sectioned settings; built-in reading and writing | Values are strings until converted; writing does not retain original comments |
| TOML | tomllib |
TOML input, especially when typed values are useful | Available in the standard library from Python 3.11; parses only, with no write support |
| JSON | json |
JSON-shaped data or an existing JSON interface | JSON does not support comments |
These capabilities and format notes are documented by Python’s configparser documentation and tomllib documentation. Prefer the format already used by your application or required by another system. If people edit the file and comments matter, remember that parsing and rewriting with configparser will not preserve those original comments.
Layer defaults and overrides predictably
The special [DEFAULT] section provides options available through other sections. You can also read multiple files into one parser: later files replace conflicting options from earlier files, while non-conflicting earlier options remain.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
import configparser
config = configparser.ConfigParser()
config.read(["settings.ini", "settings.local.ini"], encoding="utf-8")
With this ordering, settings.ini supplies the base configuration and settings.local.ini overrides matching values. The second file is optional under read(); use read_file() when a particular file is mandatory. Decide and document the precedence order so it is clear which value wins.
Load TOML in Python
Python’s built-in tomllib parses TOML 1.0.0 and is available starting with Python 3.11. Open TOML input in binary mode and pass the file object to load():
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
import tomllib
with open("settings.toml", "rb") as file:
config = tomllib.load(file)
host = config["server"]["host"]
port = config["server"]["port"]
Unlike configparser, tomllib does not provide TOML writing. If your program must create or edit TOML, Python’s documentation points to external packages for writing or style-preserving edits; those are not part of the standard library. Limit the amount of TOML data parsed when input may be untrusted, because malicious input can consume substantial CPU and memory. See the Python 3.14.8 tomllib documentation.
Write an INI configuration file
ConfigParser.write() writes the parser’s current configuration to a text file:
Recommended Free Tools
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
import configparser
config = configparser.ConfigParser()
config["server"] = {"host": "localhost", "port": "8080"}
with open("settings.ini", "w", encoding="utf-8") as file:
config.write(file)
Writing parsed settings does not preserve comments from the original configuration file. If retaining a human-edited file’s comments is important, do not assume a parse-and-write cycle will keep them.
Names and interpolation in configparser
Option names are case-insensitive by default and are converted to lowercase internally. If an application depends on case-sensitive option names, change the parser’s optionxform behavior. The default interpolation feature can substitute values from other options; use raw access or disable interpolation when that behavior is not wanted. Treat interpolation as part of the file format your application accepts, particularly when configuration comes from users.
Troubleshoot common configuration problems
- A required file appears to load, but settings are missing:
read()ignores files it cannot open. Useread_file()for required input and confirm the path and permissions. - A setting is missing from a section: Check the section and option spelling. Option names are case-insensitive by default; section names are accessed through their section key.
- A number or boolean causes a conversion error: Verify that the file contains a value accepted by the relevant typed getter, such as
getint()orgetboolean(). - Changing an INI file removes comments: This is expected when writing parsed configuration with
ConfigParser.write(); original comments are not preserved. import tomllibfails: The standard-library module requires Python 3.11 or later. Check the interpreter running the program, not only the version installed on your machine.- You need to write TOML:
tomllibis read-only. Use a suitable external TOML package if writing is required.
Or skip the browser setup
If the task is capturing a website rather than configuring a Python application, ScreenshotNeo provides a screenshot API and MCP server. Cookie banners, newsletter popups, and chat widgets can be removed before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 shots a month with no card, and paid plans start at $5 for 3,000 shots.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options, then sign up free for 1,000 screenshots a month with no card.
Frequently Asked Questions
Can I use configparser to read more than one INI file?
Yes. Read the files into the same parser in precedence order; later files override conflicting options and earlier non-conflicting options remain.
Does Python’s built-in TOML parser write TOML files?
No. tomllib parses TOML input only; use an external package if you need TOML writing.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

