Skip to main content

tableio-cfg-json

tableio-cfg-json stores TableIO configuration as validated JSON by using config-as-json.

Use it when an application uses TableIO for table-like files and wants persistent, user-editable configuration for formats, implementations and format-specific options. The configuration objects are both TableIO ConfigData objects and config-as-json Config objects, so the same object can be written as configuration file (as JSON), read back later, validated, and passed to TableIO.

Is this package for you?

This package is a good fit when one or more of these apply:

  • Your application uses TableIO.
  • You already use config-as-json, or can accept using it for persistent configuration.
  • You want one configuration file to describe one TableIO input or output endpoint.
  • You want to nest one or more TableIO endpoint configurations inside a larger application configuration file.
  • You want validation and generated user documentation for the TableIO options that are relevant to your application's capabilities.
  • You want to use the wizard user interface bridge defined in this package for some wizard (probably used for configuration).

This package is probably not the right one when:

  • You are looking for the table reader or writer itself. Use TableIO directly.
  • Your program always uses one hard-coded table format and has no persistent configuration.
  • You do not want to use config-as-json for configuration files.

Installation

tableio-cfg-json requires Python 3.12 or newer.

pip install --upgrade tableio-cfg-json

Quick start

Create a compact JSON configuration file for one TableIO endpoint:

from pathlib import Path
import sys

from tableio import FileAccess, access_capabilities
from tableio_cfg_json import tio_json_config_default

config_file = Path('tableio.cfg')
file_access = FileAccess.CREATE
capabilities = access_capabilities(file_access, error_file=sys.stderr)
config = tio_json_config_default(capabilities=capabilities,
                                 file_access=file_access,
                                 format_name='CSV')
config.write(to_json_filename=config_file)

For CSV this writes a small file like:

{
    "format_name": "CSV"
}

Read the configuration back and use it with TableIO:

from pathlib import Path
import sys

from tableio import FileAccess, access_capabilities, tio_config_create
from tableio_cfg_json import TioJsonConfig

config_file = Path('tableio.cfg')
table_file = Path('capitals.csv')
file_access = FileAccess.CREATE
capabilities = access_capabilities(file_access, error_file=sys.stderr)
config = TioJsonConfig(capabilities=capabilities,
                       file_access=file_access,
                       from_json_filename=config_file)
with tio_config_create(config=config, file_name=table_file,
                       file_access=file_access,
                       capabilities=capabilities) as table_io:
    table_io.write_table_listdata([
        ['Capital', 'Country'],
        ['Copenhagen', 'Denmark']
    ])

If implementation is omitted, TableIO chooses a matching implementation at runtime. If the user wants to lock down a specific implementation, it can be stored explicitly in JSON.

Optional settings can be added at the top level or in format-specific nested sections such as csv, html and latex. Compact output omits unset optional values, while template-style output can include all current default options.

Please see the teaching examples for a more thorough introduction.

Main entry points

  • TioJsonConfig Complete JSON-backed TableIO configuration for one endpoint. It can read JSON, write JSON and be passed to TableIO as normal configuration data.

  • tio_config_create() create a TableIO object from a TioJsonConfig object.

Helpers and details

  • tio_json_config_default() Create a validated default TioJsonConfig using TableIO's recommended choices for the requested capabilities and file access.

  • TioJsonCsvConfig, TioJsonHtmlConfig, TioJsonLatexConfig Optional nested configuration sections for format-specific settings.

  • describe_config(), describe_config_members(), describe_config_reference(), describe_config_example(), get_config_member_names() and get_general_cfg_info() Helpers for generating plain text syntax guides for configuration files.

  • tio_json_config_wizard() Interactive helper for creating one TableIO endpoint configuration through a user interface bridge.

  • WizardUiBridge, WizardUiBridgeConsole, WizardUiBridgeTextual and make_text_ui_bridge Interfaces for connecting the wizard to a console, GUI or scripted UI.

Validation model

The configuration file (in JSON) stores durable TableIO choices such as format_name, implementation, character encoding, presentation options and format-specific settings. Runtime values such as the actual file name are not stored in this configuration.

Validation happens in two layers:

  • config-as-json validates JSON structure, member names and member value types.
  • TableIO validates whether the selected format, implementation, capabilities and file access can work together.

Choice values are matched case-insensitively where TableIO defines a finite set of choices. For example, configuration file may use excel and the config object will store TableIO's normal Excel spelling after validation.

Nested application configs

TioJsonConfig can be used as the whole configuration file for a small program, or as a nested member inside a larger config-as-json application configuration. This is useful when one application has several TableIO endpoints, for example one input table and two independently configured output tables.

For larger configs, create each nested TioJsonConfig with the capabilities and file access for that endpoint. A read endpoint and a create endpoint may need different defaults and may validate different implementations.

The teaching examples show both styles.

Documentation

License

MIT

Test summary

  • Test result: 889 passed in 45s
  • No flake8 warnings.
  • No mypy errors found.
  • No pylint warnings.
  • No python layout warnings.
  • Built version(s): 1.0
  • Build and test using Python 3.14.6

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tableio_cfg_json-1.0.tar.gz (70.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tableio_cfg_json-1.0-py3-none-any.whl (77.6 kB view details)

Uploaded Python 3

File details

Details for the file tableio_cfg_json-1.0.tar.gz.

File metadata

  • Download URL: tableio_cfg_json-1.0.tar.gz
  • Upload date:
  • Size: 70.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for tableio_cfg_json-1.0.tar.gz
Algorithm Hash digest
SHA256 e4502f4f12318e30b91591d9f256e6b78ab15729e9ad841b2913dd5567880864
MD5 59835c061a2e5a6b608832928168e553
BLAKE2b-256 ed7496f4436a314533a92d4832d73a7047faaff58d78f588bbac89698c7968ab

See more details on using hashes here.

File details

Details for the file tableio_cfg_json-1.0-py3-none-any.whl.

File metadata

  • Download URL: tableio_cfg_json-1.0-py3-none-any.whl
  • Upload date:
  • Size: 77.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for tableio_cfg_json-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad64de470f665bc86341da11c45e3344c2957abfdf115a72a8df4df58402ff25
MD5 d70b145dda5852df3f8f1f7b4a40142b
BLAKE2b-256 a6f45595b5e3b2e3394f3d9566ca62e0546cbcae04b63d4e2b67e78a5cb68617

See more details on using hashes here.

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