Skip to main content

Converter between multiple open-standard file formats.

Project description

fconv

GitHub Github GitHub release (latest by date) GitHub Workflow Status PyPI version codecov Codacy Badge

fconv is a Command-Line utility and library for converting between multiple file formats such as JSON, YAML.

Getting started

pip install fconv
$ fconv --v
fconv: vx.x.x

Features

  • Convert a format into other format

  • Supported format

    • JSON
    • YAML
    • TOML
    • XML
  • To be supported

    • INI
    • JSON5
  • You can use fconv as command-line tool and Python module.

  • Using fconv as a module, String and file are available as input or output.

  • Using fconv as CLI tool, only file is available as input and String and file are available as output.

The options available in the CLI version are different from those available in the module version.

To know which options are available,

See SPEC.md:

Example

Use as a module

>>> from fconv.core import Former
>>> from fconv.formats.json import Json
>>> from fconv.formats.yaml import Yaml
>>> f = Former(src_format=Json, target_format=Yaml)

>>> f.form('{"key1":"value1"}')
'key1: value1\\n'

>>> f = Former(src_format=Yaml, target_format=Json, out_opt={'indent':3})
>>> f.form('key1: value1\\n')
'{\\n   "key1": "value1"\\n}'

Use as a command-line tool

Basic usage

fconv <source format> <target format> -i <source file name>

Convert json file into yaml and print out

fconv json yaml -i sample.json

Convert yaml file into json formated file

fconv yaml json -i sample.yaml -o result.json

Convert yaml file into json formated file with json indent option

fconv yaml json -i sample.yaml -o result.json --json-indent 2
$ fconv -h
usage: fconv [-h] -i I [--v] [--debug] [-o O] [--json-float-as-int]
             [--json-float-as-str] [--json-int-as-float] [--json-int-as-str]
             [--json-skip-keys] [--json-ignore-check-circular]
             [--json-disallow-nan] [--json-indent JSON_INDENT]
             [--json-sort-keys] [--yaml-explicit-start] [--yaml-explicit-end]
             [--yaml-indent YAML_INDENT] [--xml-process-namespaces]
             [--xml-process-comments] [--xml-particle-document]
             [--xml-disable-pretty]
             source-format target-format

Converter between multiple open-standard file formats.

positional arguments:
  source-format         data format converting from
  target-format         data format converting to

options:
  -h, --help            show this help message and exit
  -i I                  (Required) a file converting from
  --v                   print version number and exit
  --debug               print more information
  -o O                  a file converting to
  --json-float-as-int   JSON float to be decoded with int
  --json-float-as-str   JSON float to be decoded with string
  --json-int-as-float   JSON int to be decoded with float
  --json-int-as-str     JSON int to be decoded with string
  --json-skip-keys      keys that are not of a basic type (str, int, float,
                        bool, None) will be skipped
  --json-ignore-check-circular
                        the circular reference check for container types will
                        be skipped
  --json-disallow-nan   disallow to serialize out of range float values (nan,
                        inf, -inf) in strict compliance of the JSON
                        specification.
  --json-indent JSON_INDENT
                        JSON array elements and object members will be pretty-
                        printed with that indent level.
  --json-sort-keys      the output of dictionaries will be sorted by key.
  --yaml-explicit-start
                        add explicit start marker(See also
                        https://yaml.org/spec/1.2.2/#914-explicit-documents)
  --yaml-explicit-end   add explicit end marker(See also
                        https://yaml.org/spec/1.2.2/#914-explicit-documents)
  --yaml-indent YAML_INDENT
                        YAML array elements and object members will be pretty-
                        printed with that indent level.
  --xml-process-namespaces
                        enable namespace support(See more info at
                        https://github.com/martinblech/xmltodict#namespace-
                        support)
  --xml-process-comments
                        treat comments directives as an attribute
  --xml-particle-document
                        disable to add document root attribute
  --xml-disable-pretty  disable XML document to be pretty-printed with indent

Contribution

Have a look through existing Issues and Pull Requests that you could help with. If you'd like to request a feature or report a bug, please create a GitHub Issue using one of the templates provided. Any kind of contribution and suggestions are highly appreciated!

See contribution guide->

License

Licensed under the MIT License.

Project details


Download files

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

Source Distribution

fconv-3.2.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

fconv-3.2.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file fconv-3.2.2.tar.gz.

File metadata

  • Download URL: fconv-3.2.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for fconv-3.2.2.tar.gz
Algorithm Hash digest
SHA256 a89eb2e8af038baabd73d9e7c1273763636f769978b9b93e0eae37aced6d6675
MD5 491261809372f828cbf4ae1a79e663ce
BLAKE2b-256 7f94bddb259b31f4bfcf003731506051ab68b3cbb258c34062b32adfbabf0a13

See more details on using hashes here.

File details

Details for the file fconv-3.2.2-py3-none-any.whl.

File metadata

  • Download URL: fconv-3.2.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for fconv-3.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8eb8c848a1c357f55f554301187fe4ee110483a74bdbca274bae4b6e6b9d7bc2
MD5 d701f59a8bee295721b732d256fcc520
BLAKE2b-256 24be83c0eb4ad6fd4281b71e9129f44ca1ac4717f423ac6ebc5d390d21e49c7d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page