Debian Codegraph @

docs/plugins/export.rst

raw
1 Export Plugin
2 =============
3
4 The ``export`` plugin lets you get data from the items and export the content as
5 JSON_, CSV_, or XML_.
6
7 .. _csv: https://fileinfo.com/extension/csv
8
9 .. _json: https://www.json.org
10
11 .. _xml: https://fileinfo.com/extension/xml
12
13 Enable the ``export`` plugin (see :ref:`using-plugins` for help). Then, type
14 ``beet export`` followed by a :doc:`query </reference/query>` to get the data
15 from your library. For example, run this:
16
17 ::
18
19 $ beet export beatles
20
21 to print a JSON file containing information about your Beatles tracks.
22
23 Command-Line Options
24 --------------------
25
26 The ``export`` command has these command-line options:
27
28 - ``--include-keys`` or ``-i``: Choose the properties to include in the output
29 data. The argument is a comma-separated list of simple glob patterns where
30 ``*`` matches any string. For example:
31
32 ::
33
34 $ beet export -i 'title,mb*' beatles
35
36 will include the ``title`` property and all properties starting with ``mb``.
37 You can add the ``-i`` option multiple times to the command line.
38
39 - ``--library`` or ``-l``: Show data from the library database instead of the
40 files' tags.
41 - ``--album`` or ``-a``: Show data from albums instead of tracks (implies
42 ``--library``).
43 - ``--output`` or ``-o``: Path for an output file. If not informed, will print
44 the data in the console.
45 - ``--append``: Appends the data to the file instead of writing.
46 - ``--format`` or ``-f``: Specifies the format the data will be exported as. If
47 not informed, JSON will be used by default. The format options include csv,
48 json, `jsonlines <https://jsonlines.org/>`_ and xml.
49
50 Configuration
51 -------------
52
53 To configure the plugin, make a ``export:`` section in your configuration file.
54 For JSON export, these options are available under the ``json`` and
55 ``jsonlines`` keys:
56
57 - **ensure_ascii**: Escape non-ASCII characters with ``\uXXXX`` entities.
58 - **indent**: The number of spaces for indentation.
59 - **separators**: A ``[item_separator, dict_separator]`` tuple.
60 - **sort_keys**: Sorts the keys in JSON dictionaries.
61
62 Those options match the options from the `Python json module`_. Similarly, these
63 options are available for the CSV format under the ``csv`` key:
64
65 - **delimiter**: Used as the separating character between fields. The default
66 value is a comma (,).
67 - **dialect**: The kind of CSV file to produce. The default is ``excel``.
68
69 These options match the options from the `Python csv module`_.
70
71 .. _python csv module: https://docs.python.org/3/library/csv.html#csv-fmt-params
72
73 .. _python json module: https://docs.python.org/3/library/json.html#basic-usage
74
75 The default options look like this:
76
77 ::
78
79 export:
80 json:
81 formatting:
82 ensure_ascii: false
83 indent: 4
84 separators: [',' , ': ']
85 sort_keys: true
86 csv:
87 formatting:
88 delimiter: ','
89 dialect: excel