xtable


Namextable JSON
Version 1.1.6 PyPI version JSON
download
home_pagehttps://github.com/walkerever/xtable
Summaryoperate table format in console. console table, csv, json, yaml and markdown.
upload_time2023-01-05 15:39:42
maintainer
docs_urlNone
authorYonghang Wang
requires_python
licenseApache 2
keywords xtable table simpletable quicktable
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## [doc on github.io](https://walkerever.github.io/)

# xtable

print console tables.  xtable serves as both a class and a command line tool.

- [installation](#installation)
- [use the class](#use-the-class)
- [command line](#use-the-command-line) from CSV, preformatted table, JSON list to console table, JSON, markdown and more.
- [convert table data to Markdown](#markdown)

----


## Installation
    `pip install xtable`
   run it through xtable` or `python -mxtable`

----

below is a simple introduction for some basic usage.

## use the class
<pre><font color="#5FD7FF">from</font> xtable <font color="#5FD7FF">import</font> xtable

data = [
        [<font color="#C061CB">1</font>,<font color="#C061CB">2</font>,<font color="#C061CB">3</font>,<font color="#C061CB">4</font>,<font color="#C061CB">5</font>],
        [<font color="#C061CB">11</font>,<font color="#C061CB">52</font>,<font color="#C061CB">3</font>,<font color="#C061CB">4</font>,<font color="#C061CB">5</font>],
        [<font color="#C061CB">11</font>,<font color="#33C7DE"><b>None</b></font>,<font color="#C061CB">3</font>,<font color="#C061CB">4</font>,<font color="#C061CB">5</font>],
        [<font color="#C061CB">11</font>,<font color="#33C7DE"><b>None</b></font>,<font color="#C061CB">3</font>,<font color="#33C7DE"><b>None</b></font>,<font color="#C061CB">5</font>],
        ]
hdr = [<font color="#C061CB">&apos;c1&apos;</font>,<font color="#C061CB">&apos;c2&apos;</font>,<font color="#C061CB">&apos;c3&apos;</font>,<font color="#C061CB">&apos;c4&apos;</font>,<font color="#C061CB">&apos;c5&apos;</font>]

xt = xtable(data=data,header=hdr)
<font color="#33C7DE"><b>print</b></font>(xt)

</pre>

// result : 
<pre>c1 c2 c3 c4 c5
--------------
1  2  3  4  5
11 52 3  4  5
11    3  4  5
11    3     5
</pre>
-----

<pre><font color="#33C7DE"># test/t2.csv</font>
<font color="#C061CB">&apos;&apos;&apos;</font>
<font color="#C061CB">h1,h2,h3</font>
<font color="#C061CB">&quot;asd&quot;,&quot;sdfsadf&quot;,1</font>
<font color="#C061CB">&quot;c&quot;,&quot;cc&quot;,233</font>
<font color="#C061CB">&apos;&apos;&apos;</font>

xt = xtable.init_from_csv(<font color="#C061CB">&quot;test/t2.csv&quot;</font>)
<font color="#33C7DE"><b>print</b></font>(xt)
</pre>

// result :
<pre>h1  h2      h3
---------------
asd sdfsadf 1
c   cc      233
</pre>

-----
<pre>
data = [
        {<font color="#C061CB">&quot;h1&quot;</font>:<font color="#C061CB">&quot;v1&quot;</font>,<font color="#C061CB">&quot;h2&quot;</font>:<font color="#C061CB">&quot;v2&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>:<font color="#C061CB">&quot;v3&quot;</font>},
        {<font color="#C061CB">&quot;h1&quot;</font>:<font color="#C061CB">&quot;v11&quot;</font>,<font color="#C061CB">&quot;h2&quot;</font>:<font color="#C061CB">&quot;v22&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>:<font color="#C061CB">&quot;v33&quot;</font>},
        {<font color="#C061CB">&quot;h1&quot;</font>:<font color="#C061CB">&quot;v11111&quot;</font>,<font color="#C061CB">&quot;h2&quot;</font>:<font color="#C061CB">&quot;v22222&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>:<font color="#C061CB">&quot;v34444&quot;</font>},
     ]
xt = xtable.init_from_list(data)
<font color="#33C7DE"><b>print</b></font>(xt)</pre>

// result :
<pre>
h1     h2     h3
--------------------
v1     v2     v3
v11    v22    v33
v11111 v22222 v34444

</pre>

-----

// all of them support "xheader".

<pre>data = [
        {<font color="#C061CB">&quot;h1&quot;</font>:<font color="#C061CB">&quot;v1&quot;</font>,<font color="#C061CB">&quot;h2&quot;</font>:<font color="#C061CB">&quot;v2&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>:<font color="#C061CB">&quot;v3&quot;</font>},
        {<font color="#C061CB">&quot;h1&quot;</font>:<font color="#C061CB">&quot;v11&quot;</font>,<font color="#C061CB">&quot;h2&quot;</font>:<font color="#C061CB">&quot;v22&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>:<font color="#C061CB">&quot;v33&quot;</font>},
        {<font color="#C061CB">&quot;h1&quot;</font>:<font color="#C061CB">&quot;v11111&quot;</font>,<font color="#C061CB">&quot;h2&quot;</font>:<font color="#C061CB">&quot;v22222&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>:<font color="#C061CB">&quot;v34444&quot;</font>},
     ]
xt = xtable.init_from_list(data, xheader=[<font color="#C061CB">&quot;h1&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>])
<font color="#33C7DE"><b>print</b></font>(xt)

xt2 = xtable.init_from_list(data, xheader=<font color="#C061CB">&quot;h2,h3&quot;</font>)
<font color="#33C7DE"><b>print</b></font>(xt2)

</pre>

<pre>h1     h3
-------------
v1     v3
v11    v33
v11111 v34444

h2     h3
-------------
v2     v3
v22    v33
v22222 v34444
</pre>

-----

// output json/yaml/csv/html

<pre>

data = [
        {<font color="#C061CB">&quot;h1&quot;</font>:<font color="#C061CB">&quot;v1&quot;</font>,<font color="#C061CB">&quot;h2&quot;</font>:<font color="#C061CB">&quot;v2&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>:<font color="#C061CB">&quot;v3&quot;</font>},
        {<font color="#C061CB">&quot;h1&quot;</font>:<font color="#C061CB">&quot;v11&quot;</font>,<font color="#C061CB">&quot;h2&quot;</font>:<font color="#C061CB">&quot;v22&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>:<font color="#C061CB">&quot;v33&quot;</font>},
        {<font color="#C061CB">&quot;h1&quot;</font>:<font color="#C061CB">&quot;v11111&quot;</font>,<font color="#C061CB">&quot;h2&quot;</font>:<font color="#C061CB">&quot;v22222&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>:<font color="#C061CB">&quot;v34444&quot;</font>},
     ]
xt = xtable.init_from_list(data, xheader=[<font color="#C061CB">&quot;h1&quot;</font>,<font color="#C061CB">&quot;h3&quot;</font>])
<font color="#33C7DE"><b>print</b></font>(xt.csv())
<font color="#33C7DE"><b>print</b></font>(xt.yaml())
<font color="#33C7DE"><b>print</b></font>(xt.json())
<font color="#33C7DE"><b>print</b></font>(xt.html())

</pre>

// result
<pre>- h1: v1
  h3: v3
- h1: v11
  h3: v33
- h1: v11111
  h3: v34444

[
  {
    &quot;h1&quot;: &quot;v1&quot;,
    &quot;h3&quot;: &quot;v3&quot;
  },
  {
    &quot;h1&quot;: &quot;v11&quot;,
    &quot;h3&quot;: &quot;v33&quot;
  },
  {
    &quot;h1&quot;: &quot;v11111&quot;,
    &quot;h3&quot;: &quot;v34444&quot;
  }
]
&lt;table border=1 style=&quot;border-collapse:collapse;&quot;&gt;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;h1&lt;/b&gt;&lt;/td&gt;
&lt;td&gt;&lt;b&gt;h3&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;v1&lt;/td&gt;
&lt;td&gt;v3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;v11&lt;/td&gt;
&lt;td&gt;v33&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;v11111&lt;/td&gt;
&lt;td&gt;v34444&lt;/td&gt;
&lt;/tr&gt;
</pre>

-----

## use the command line

<pre>[yonghang@mtp xtable]$ cat test/t1.txt  
a b c
121 1212 12
12 332  2323
[yonghang@mtp xtable]$ cat test/t1.txt  | xtable 
a   b    c
-------------
121 1212 12
12  332  2323
[yonghang@mtp xtable]$ 
[yonghang@mtp xtable]$ cat test/t2.csv 
h1,h2,h3
&quot;asd&quot;,&quot;sdfsadf&quot;,1
&quot;c&quot;,&quot;cc&quot;,233
[yonghang@mtp xtable]$ 
[yonghang@mtp xtable]$ cat test/t2.csv  | xtable -b&quot;,&quot;
h1    h2        h3
-------------------
&quot;asd&quot; &quot;sdfsadf&quot; 1
&quot;c&quot;   &quot;cc&quot;      233</pre>

-----

<pre>[yonghang@mtp xtable]$ cat test/t3.json  | qic
[
  {
    <font color="#008700"><b>&quot;userId&quot;</b></font>: <font color="#626262">1</font>,
    <font color="#008700"><b>&quot;firstName&quot;</b></font>: <font color="#AF0000">&quot;Krish&quot;</font>,
    <font color="#008700"><b>&quot;lastName&quot;</b></font>: <font color="#AF0000">&quot;Lee&quot;</font>,
    <font color="#008700"><b>&quot;phoneNumber&quot;</b></font>: <font color="#AF0000">&quot;123456&quot;</font>,
    <font color="#008700"><b>&quot;emailAddress&quot;</b></font>: <font color="#AF0000">&quot;krish.lee@learningcontainer.com&quot;</font>
  },
  {
    <font color="#008700"><b>&quot;userId&quot;</b></font>: <font color="#626262">2</font>,
    <font color="#008700"><b>&quot;firstName&quot;</b></font>: <font color="#AF0000">&quot;racks&quot;</font>,
    <font color="#008700"><b>&quot;lastName&quot;</b></font>: <font color="#AF0000">&quot;jacson&quot;</font>,
    <font color="#008700"><b>&quot;phoneNumber&quot;</b></font>: <font color="#AF0000">&quot;123456&quot;</font>,
    <font color="#008700"><b>&quot;emailAddress&quot;</b></font>: <font color="#AF0000">&quot;racks.jacson@learningcontainer.com&quot;</font>
  },
  {
    <font color="#008700"><b>&quot;userId&quot;</b></font>: <font color="#626262">3</font>,
    <font color="#008700"><b>&quot;firstName&quot;</b></font>: <font color="#AF0000">&quot;denial&quot;</font>,
    <font color="#008700"><b>&quot;lastName&quot;</b></font>: <font color="#AF0000">&quot;roast&quot;</font>,
    <font color="#008700"><b>&quot;phoneNumber&quot;</b></font>: <font color="#AF0000">&quot;33333333&quot;</font>,
    <font color="#008700"><b>&quot;emailAddress&quot;</b></font>: <font color="#AF0000">&quot;denial.roast@learningcontainer.com&quot;</font>
  },
  {
    <font color="#008700"><b>&quot;userId&quot;</b></font>: <font color="#626262">4</font>,
    <font color="#008700"><b>&quot;firstName&quot;</b></font>: <font color="#AF0000">&quot;devid&quot;</font>,
    <font color="#008700"><b>&quot;lastName&quot;</b></font>: <font color="#AF0000">&quot;neo&quot;</font>,
    <font color="#008700"><b>&quot;phoneNumber&quot;</b></font>: <font color="#AF0000">&quot;222222222&quot;</font>,
    <font color="#008700"><b>&quot;emailAddress&quot;</b></font>: <font color="#AF0000">&quot;devid.neo@learningcontainer.com&quot;</font>
  },
  {
    <font color="#008700"><b>&quot;userId&quot;</b></font>: <font color="#626262">5</font>,
    <font color="#008700"><b>&quot;firstName&quot;</b></font>: <font color="#AF0000">&quot;jone&quot;</font>,
    <font color="#008700"><b>&quot;lastName&quot;</b></font>: <font color="#AF0000">&quot;mac&quot;</font>,
    <font color="#008700"><b>&quot;phoneNumber&quot;</b></font>: <font color="#AF0000">&quot;111111111&quot;</font>,
    <font color="#008700"><b>&quot;emailAddress&quot;</b></font>: <font color="#AF0000">&quot;jone.mac@learningcontainer.com&quot;</font>
  }
]

[yonghang@mtp xtable]$ cat test/t3.json  | xtable
userId firstName lastName phoneNumber emailAddress
------------------------------------------------------------------------
1      Krish     Lee      123456      krish.lee@learningcontainer.com
2      racks     jacson   123456      racks.jacson@learningcontainer.com
3      denial    roast    33333333    denial.roast@learningcontainer.com
4      devid     neo      222222222   devid.neo@learningcontainer.com
5      jone      mac      111111111   jone.mac@learningcontainer.com
</pre>

-----
### pivot 
<pre>[yonghang@mtp xtable]$ cat test/t3.json  | xtable -v
userId       : 1
firstName    : Krish
lastName     : Lee
phoneNumber  : 123456
emailAddress : krish.lee@learningcontainer.com
--
userId       : 2
firstName    : racks
lastName     : jacson
phoneNumber  : 123456
emailAddress : racks.jacson@learningcontainer.com
--
userId       : 3
firstName    : denial
lastName     : roast
phoneNumber  : 33333333
emailAddress : denial.roast@learningcontainer.com
--
userId       : 4
firstName    : devid
lastName     : neo
phoneNumber  : 222222222
emailAddress : devid.neo@learningcontainer.com
--
userId       : 5
firstName    : jone
lastName     : mac
phoneNumber  : 111111111
emailAddress : jone.mac@learningcontainer.com
</pre>

if we look at the source code, we know class xtable support .pivot() as well,

<pre>        <font color="#E9AD0C">if</font> <font color="#33C7DE"><b>type</b></font>(js) <font color="#E9AD0C">is</font> <font color="#33C7DE"><b>list</b></font> :
            xt = xtable.init_from_json(js,args.header)
            <font color="#E9AD0C">if</font> args.pivot :
                <font color="#33C7DE"><b>print</b></font>(xt.pivot<span style="background-color:#2AA1B3">()</span>)
            <font color="#E9AD0C">else</font> :
                <font color="#33C7DE"><b>print</b></font>(xt)
</pre>


-----
### when header has space...
some command output is already a table, only not that decent, eg. as below. xtable will help a little bit.  `-c` told xtable that `container id` is together while `-t` told xtable the input stream is already in "table" format.

<pre>[yonghang@mtp xtable]$ sudo podman ps --all
CONTAINER ID  IMAGE                           COMMAND               CREATED             STATUS                         PORTS   NAMES
eeb5db3c4f9a  docker.io/library/nginx:latest  nginx -g daemon o...  About a minute ago  Exited (0) About a minute ago          romantic_hamilton
5ef267563b44  docker.io/library/httpd:latest  httpd-foreground      55 seconds ago      Exited (0) 6 seconds ago               sad_lamarr
[yonghang@mtp xtable]$ 
[yonghang@mtp xtable]$ 
[yonghang@mtp xtable]$ sudo podman ps --all | xtable -c &quot;CONTAINER ID&quot; -t
CONTAINER ID IMAGE                          COMMAND              CREATED            STATUS                        PORTS NAMES
----------------------------------------------------------------------------------------------------------------------------------------
eeb5db3c4f9a docker.io/library/nginx:latest nginx -g daemon o... About a minute ago Exited (0) About a minute ago       romantic_hamilto
5ef267563b44 docker.io/library/httpd:latest httpd-foreground     About a minute ago Exited (0) 28 seconds ago           sad_lamar
[yonghang@mtp xtable]$ 
[yonghang@mtp xtable]$ sudo podman ps --all | xtable -c &quot;CONTAINER ID&quot; -tv
CONTAINER ID : eeb5db3c4f9a
IMAGE        : docker.io/library/nginx:latest
COMMAND      : nginx -g daemon o...
CREATED      : About a minute ago
STATUS       : Exited (0) About a minute ago
PORTS        : 
NAMES        : romantic_hamilto
--
CONTAINER ID : 5ef267563b44
IMAGE        : docker.io/library/httpd:latest
COMMAND      : httpd-foreground
CREATED      : About a minute ago
STATUS       : Exited (0) 32 seconds ago
PORTS        : 
NAMES        : sad_lamar
</pre>

### xtable take care of lines

<pre>[yonghang@W5202860 test]$ cat sql.json  | qic
[
  {
    <font color="#008700"><b>&quot;name&quot;</b></font>: <font color="#AF0000">&quot;sql example 1&quot;</font>,
    <font color="#008700"><b>&quot;query&quot;</b></font>: <font color="#AF0000">&quot;SELECT QUARTER, REGION, SUM(SALES)\n FROM SALESTABLE\n GROUP BY CUBE (QUARTER, REGION)&quot;</font>
  },
  {
    <font color="#008700"><b>&quot;name&quot;</b></font>: <font color="#AF0000">&quot;sql example 2&quot;</font>,
    <font color="#008700"><b>&quot;query&quot;</b></font>: <font color="#AF0000">&quot;select name, cast(text as varchar(8000)) \nfrom SYSIBM.SYSVIEWS \n where name=&apos;your table name&apos; &quot;</font>
  },
  {
    <font color="#008700"><b>&quot;name&quot;</b></font>: <font color="#AF0000">&quot;sql example 3&quot;</font>,
    <font color="#008700"><b>&quot;query&quot;</b></font>: <font color="#AF0000">&quot;select Id, max(V1),max(V2),max(V3) from \n (\n select ID,Value V1,&apos;&apos; V2,&apos;&apos; V3 from A where Code=1 \n union all \n select ID,&apos;&apos; V1, Value V2,&apos;&apos; V3 from A where Code=2 \n union all \n select ID,&apos;&apos; V1, &apos;&apos; V2,Value V3 from A where Code=3 \n) AG\n group by ID&quot;</font>
  }
]

[yonghang@W5202860 test]$ 
[yonghang@W5202860 test]$ cat sql.json  | xtable
name          query
-------------------------------------------------------------------
sql example 1 SELECT QUARTER, REGION, SUM(SALES)
               FROM SALESTABLE
               GROUP BY CUBE (QUARTER, REGION)
sql example 2 select name, cast(text as varchar(8000))
              from SYSIBM.SYSVIEWS
               where name=&apos;your table name&apos;
sql example 3 select Id, max(V1),max(V2),max(V3) from
               (
               select ID,Value V1,&apos;&apos; V2,&apos;&apos; V3 from A where Code=1
               union all
               select ID,&apos;&apos; V1, Value V2,&apos;&apos; V3 from A where Code=2
               union all
               select ID,&apos;&apos; V1, &apos;&apos; V2,Value V3 from A where Code=3
              ) AG
               group by ID
</pre>


## markdown

```
yonghang@air xtable % cat test/t2.csv
h1,h2,h3
"asd","sdfsadf",1
"c","cc",233

yonghang@air xtable % cat test/t2.csv | xtable -F md
|  h1,h2,h3           |
|  -----------------  |
|  "asd","sdfsadf",1  |
|  "c","cc",233       |
yonghang@air xtable %
yonghang@air xtable % cat test/t1.txt
a b c
121 1212 12
12 332  2323
yonghang@air xtable % cat test/t1.txt | xtable -F md
|  a    | b    | c     |
|  ---- | ---- | ----  |
|  121  | 1212 | 12    |
|  12   | 332  | 2323  |
yonghang@air xtable %
yonghang@air xtable % cat test/t3.json | qic
[
  {
    "userId": 1,
    "firstName": "Krish",
    "lastName": "Lee",
    "phoneNumber": "123456",
    "emailAddress": "krish.lee@learningcontainer.com"
  },
  {
    "userId": 2,
    "firstName": "racks",
    "lastName": "jacson",
    "phoneNumber": "123456",
    "emailAddress": "racks.jacson@learningcontainer.com"
  },
  {
    "userId": 3,
    "firstName": "denial",
    "lastName": "roast",
    "phoneNumber": "33333333",
    "emailAddress": "denial.roast@learningcontainer.com"
  },
  {
    "userId": 4,
    "firstName": "devid",
    "lastName": "neo",
    "phoneNumber": "222222222",
    "emailAddress": "devid.neo@learningcontainer.com"
  },
  {
    "userId": 5,
    "firstName": "jone",
    "lastName": "mac",
    "phoneNumber": "111111111",
    "emailAddress": "jone.mac@learningcontainer.com"
  }
]

yonghang@air xtable %
yonghang@air xtable % cat test/t3.json | xtable -F md
|  userId | firstName | lastName | phoneNumber | emailAddress                        |
|  ------ | --------- | -------- | ----------- | ----------------------------------  |
|       1 | Krish     | Lee      | 123456      | krish.lee@learningcontainer.com     |
|       2 | racks     | jacson   | 123456      | racks.jacson@learningcontainer.com  |
|       3 | denial    | roast    | 33333333    | denial.roast@learningcontainer.com  |
|       4 | devid     | neo      | 222222222   | devid.neo@learningcontainer.com     |
|       5 | jone      | mac      | 111111111   | jone.mac@learningcontainer.com      |
yonghang@air xtable %
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/walkerever/xtable",
    "name": "xtable",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "xtable,table,simpletable,quicktable",
    "author": "Yonghang Wang",
    "author_email": "wyhang@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/85/57/904d5bedd62e86498b2313b7003aba7284727f2f2882dc64d94a3ea3e7ad/xtable-1.1.6.tar.gz",
    "platform": null,
    "description": "## [doc on github.io](https://walkerever.github.io/)\n\n# xtable\n\nprint console tables.  xtable serves as both a class and a command line tool.\n\n- [installation](#installation)\n- [use the class](#use-the-class)\n- [command line](#use-the-command-line) from CSV, preformatted table, JSON list to console table, JSON, markdown and more.\n- [convert table data to Markdown](#markdown)\n\n----\n\n\n## Installation\n    `pip install xtable`\n   run it through xtable` or `python -mxtable`\n\n----\n\nbelow is a simple introduction for some basic usage.\n\n## use the class\n<pre><font color=\"#5FD7FF\">from</font> xtable <font color=\"#5FD7FF\">import</font> xtable\n\ndata = [\n        [<font color=\"#C061CB\">1</font>,<font color=\"#C061CB\">2</font>,<font color=\"#C061CB\">3</font>,<font color=\"#C061CB\">4</font>,<font color=\"#C061CB\">5</font>],\n        [<font color=\"#C061CB\">11</font>,<font color=\"#C061CB\">52</font>,<font color=\"#C061CB\">3</font>,<font color=\"#C061CB\">4</font>,<font color=\"#C061CB\">5</font>],\n        [<font color=\"#C061CB\">11</font>,<font color=\"#33C7DE\"><b>None</b></font>,<font color=\"#C061CB\">3</font>,<font color=\"#C061CB\">4</font>,<font color=\"#C061CB\">5</font>],\n        [<font color=\"#C061CB\">11</font>,<font color=\"#33C7DE\"><b>None</b></font>,<font color=\"#C061CB\">3</font>,<font color=\"#33C7DE\"><b>None</b></font>,<font color=\"#C061CB\">5</font>],\n        ]\nhdr = [<font color=\"#C061CB\">&apos;c1&apos;</font>,<font color=\"#C061CB\">&apos;c2&apos;</font>,<font color=\"#C061CB\">&apos;c3&apos;</font>,<font color=\"#C061CB\">&apos;c4&apos;</font>,<font color=\"#C061CB\">&apos;c5&apos;</font>]\n\nxt = xtable(data=data,header=hdr)\n<font color=\"#33C7DE\"><b>print</b></font>(xt)\n\n</pre>\n\n// result : \n<pre>c1 c2 c3 c4 c5\n--------------\n1  2  3  4  5\n11 52 3  4  5\n11    3  4  5\n11    3     5\n</pre>\n-----\n\n<pre><font color=\"#33C7DE\"># test/t2.csv</font>\n<font color=\"#C061CB\">&apos;&apos;&apos;</font>\n<font color=\"#C061CB\">h1,h2,h3</font>\n<font color=\"#C061CB\">&quot;asd&quot;,&quot;sdfsadf&quot;,1</font>\n<font color=\"#C061CB\">&quot;c&quot;,&quot;cc&quot;,233</font>\n<font color=\"#C061CB\">&apos;&apos;&apos;</font>\n\nxt = xtable.init_from_csv(<font color=\"#C061CB\">&quot;test/t2.csv&quot;</font>)\n<font color=\"#33C7DE\"><b>print</b></font>(xt)\n</pre>\n\n// result :\n<pre>h1  h2      h3\n---------------\nasd sdfsadf 1\nc   cc      233\n</pre>\n\n-----\n<pre>\ndata = [\n        {<font color=\"#C061CB\">&quot;h1&quot;</font>:<font color=\"#C061CB\">&quot;v1&quot;</font>,<font color=\"#C061CB\">&quot;h2&quot;</font>:<font color=\"#C061CB\">&quot;v2&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>:<font color=\"#C061CB\">&quot;v3&quot;</font>},\n        {<font color=\"#C061CB\">&quot;h1&quot;</font>:<font color=\"#C061CB\">&quot;v11&quot;</font>,<font color=\"#C061CB\">&quot;h2&quot;</font>:<font color=\"#C061CB\">&quot;v22&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>:<font color=\"#C061CB\">&quot;v33&quot;</font>},\n        {<font color=\"#C061CB\">&quot;h1&quot;</font>:<font color=\"#C061CB\">&quot;v11111&quot;</font>,<font color=\"#C061CB\">&quot;h2&quot;</font>:<font color=\"#C061CB\">&quot;v22222&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>:<font color=\"#C061CB\">&quot;v34444&quot;</font>},\n     ]\nxt = xtable.init_from_list(data)\n<font color=\"#33C7DE\"><b>print</b></font>(xt)</pre>\n\n// result :\n<pre>\nh1     h2     h3\n--------------------\nv1     v2     v3\nv11    v22    v33\nv11111 v22222 v34444\n\n</pre>\n\n-----\n\n// all of them support \"xheader\".\n\n<pre>data = [\n        {<font color=\"#C061CB\">&quot;h1&quot;</font>:<font color=\"#C061CB\">&quot;v1&quot;</font>,<font color=\"#C061CB\">&quot;h2&quot;</font>:<font color=\"#C061CB\">&quot;v2&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>:<font color=\"#C061CB\">&quot;v3&quot;</font>},\n        {<font color=\"#C061CB\">&quot;h1&quot;</font>:<font color=\"#C061CB\">&quot;v11&quot;</font>,<font color=\"#C061CB\">&quot;h2&quot;</font>:<font color=\"#C061CB\">&quot;v22&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>:<font color=\"#C061CB\">&quot;v33&quot;</font>},\n        {<font color=\"#C061CB\">&quot;h1&quot;</font>:<font color=\"#C061CB\">&quot;v11111&quot;</font>,<font color=\"#C061CB\">&quot;h2&quot;</font>:<font color=\"#C061CB\">&quot;v22222&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>:<font color=\"#C061CB\">&quot;v34444&quot;</font>},\n     ]\nxt = xtable.init_from_list(data, xheader=[<font color=\"#C061CB\">&quot;h1&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>])\n<font color=\"#33C7DE\"><b>print</b></font>(xt)\n\nxt2 = xtable.init_from_list(data, xheader=<font color=\"#C061CB\">&quot;h2,h3&quot;</font>)\n<font color=\"#33C7DE\"><b>print</b></font>(xt2)\n\n</pre>\n\n<pre>h1     h3\n-------------\nv1     v3\nv11    v33\nv11111 v34444\n\nh2     h3\n-------------\nv2     v3\nv22    v33\nv22222 v34444\n</pre>\n\n-----\n\n// output json/yaml/csv/html\n\n<pre>\n\ndata = [\n        {<font color=\"#C061CB\">&quot;h1&quot;</font>:<font color=\"#C061CB\">&quot;v1&quot;</font>,<font color=\"#C061CB\">&quot;h2&quot;</font>:<font color=\"#C061CB\">&quot;v2&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>:<font color=\"#C061CB\">&quot;v3&quot;</font>},\n        {<font color=\"#C061CB\">&quot;h1&quot;</font>:<font color=\"#C061CB\">&quot;v11&quot;</font>,<font color=\"#C061CB\">&quot;h2&quot;</font>:<font color=\"#C061CB\">&quot;v22&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>:<font color=\"#C061CB\">&quot;v33&quot;</font>},\n        {<font color=\"#C061CB\">&quot;h1&quot;</font>:<font color=\"#C061CB\">&quot;v11111&quot;</font>,<font color=\"#C061CB\">&quot;h2&quot;</font>:<font color=\"#C061CB\">&quot;v22222&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>:<font color=\"#C061CB\">&quot;v34444&quot;</font>},\n     ]\nxt = xtable.init_from_list(data, xheader=[<font color=\"#C061CB\">&quot;h1&quot;</font>,<font color=\"#C061CB\">&quot;h3&quot;</font>])\n<font color=\"#33C7DE\"><b>print</b></font>(xt.csv())\n<font color=\"#33C7DE\"><b>print</b></font>(xt.yaml())\n<font color=\"#33C7DE\"><b>print</b></font>(xt.json())\n<font color=\"#33C7DE\"><b>print</b></font>(xt.html())\n\n</pre>\n\n// result\n<pre>- h1: v1\n  h3: v3\n- h1: v11\n  h3: v33\n- h1: v11111\n  h3: v34444\n\n[\n  {\n    &quot;h1&quot;: &quot;v1&quot;,\n    &quot;h3&quot;: &quot;v3&quot;\n  },\n  {\n    &quot;h1&quot;: &quot;v11&quot;,\n    &quot;h3&quot;: &quot;v33&quot;\n  },\n  {\n    &quot;h1&quot;: &quot;v11111&quot;,\n    &quot;h3&quot;: &quot;v34444&quot;\n  }\n]\n&lt;table border=1 style=&quot;border-collapse:collapse;&quot;&gt;\n&lt;tr&gt;\n&lt;td&gt;&lt;b&gt;h1&lt;/b&gt;&lt;/td&gt;\n&lt;td&gt;&lt;b&gt;h3&lt;/b&gt;&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td&gt;v1&lt;/td&gt;\n&lt;td&gt;v3&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td&gt;v11&lt;/td&gt;\n&lt;td&gt;v33&lt;/td&gt;\n&lt;/tr&gt;\n&lt;tr&gt;\n&lt;td&gt;v11111&lt;/td&gt;\n&lt;td&gt;v34444&lt;/td&gt;\n&lt;/tr&gt;\n</pre>\n\n-----\n\n## use the command line\n\n<pre>[yonghang@mtp xtable]$ cat test/t1.txt  \na b c\n121 1212 12\n12 332  2323\n[yonghang@mtp xtable]$ cat test/t1.txt  | xtable \na   b    c\n-------------\n121 1212 12\n12  332  2323\n[yonghang@mtp xtable]$ \n[yonghang@mtp xtable]$ cat test/t2.csv \nh1,h2,h3\n&quot;asd&quot;,&quot;sdfsadf&quot;,1\n&quot;c&quot;,&quot;cc&quot;,233\n[yonghang@mtp xtable]$ \n[yonghang@mtp xtable]$ cat test/t2.csv  | xtable -b&quot;,&quot;\nh1    h2        h3\n-------------------\n&quot;asd&quot; &quot;sdfsadf&quot; 1\n&quot;c&quot;   &quot;cc&quot;      233</pre>\n\n-----\n\n<pre>[yonghang@mtp xtable]$ cat test/t3.json  | qic\n[\n  {\n    <font color=\"#008700\"><b>&quot;userId&quot;</b></font>: <font color=\"#626262\">1</font>,\n    <font color=\"#008700\"><b>&quot;firstName&quot;</b></font>: <font color=\"#AF0000\">&quot;Krish&quot;</font>,\n    <font color=\"#008700\"><b>&quot;lastName&quot;</b></font>: <font color=\"#AF0000\">&quot;Lee&quot;</font>,\n    <font color=\"#008700\"><b>&quot;phoneNumber&quot;</b></font>: <font color=\"#AF0000\">&quot;123456&quot;</font>,\n    <font color=\"#008700\"><b>&quot;emailAddress&quot;</b></font>: <font color=\"#AF0000\">&quot;krish.lee@learningcontainer.com&quot;</font>\n  },\n  {\n    <font color=\"#008700\"><b>&quot;userId&quot;</b></font>: <font color=\"#626262\">2</font>,\n    <font color=\"#008700\"><b>&quot;firstName&quot;</b></font>: <font color=\"#AF0000\">&quot;racks&quot;</font>,\n    <font color=\"#008700\"><b>&quot;lastName&quot;</b></font>: <font color=\"#AF0000\">&quot;jacson&quot;</font>,\n    <font color=\"#008700\"><b>&quot;phoneNumber&quot;</b></font>: <font color=\"#AF0000\">&quot;123456&quot;</font>,\n    <font color=\"#008700\"><b>&quot;emailAddress&quot;</b></font>: <font color=\"#AF0000\">&quot;racks.jacson@learningcontainer.com&quot;</font>\n  },\n  {\n    <font color=\"#008700\"><b>&quot;userId&quot;</b></font>: <font color=\"#626262\">3</font>,\n    <font color=\"#008700\"><b>&quot;firstName&quot;</b></font>: <font color=\"#AF0000\">&quot;denial&quot;</font>,\n    <font color=\"#008700\"><b>&quot;lastName&quot;</b></font>: <font color=\"#AF0000\">&quot;roast&quot;</font>,\n    <font color=\"#008700\"><b>&quot;phoneNumber&quot;</b></font>: <font color=\"#AF0000\">&quot;33333333&quot;</font>,\n    <font color=\"#008700\"><b>&quot;emailAddress&quot;</b></font>: <font color=\"#AF0000\">&quot;denial.roast@learningcontainer.com&quot;</font>\n  },\n  {\n    <font color=\"#008700\"><b>&quot;userId&quot;</b></font>: <font color=\"#626262\">4</font>,\n    <font color=\"#008700\"><b>&quot;firstName&quot;</b></font>: <font color=\"#AF0000\">&quot;devid&quot;</font>,\n    <font color=\"#008700\"><b>&quot;lastName&quot;</b></font>: <font color=\"#AF0000\">&quot;neo&quot;</font>,\n    <font color=\"#008700\"><b>&quot;phoneNumber&quot;</b></font>: <font color=\"#AF0000\">&quot;222222222&quot;</font>,\n    <font color=\"#008700\"><b>&quot;emailAddress&quot;</b></font>: <font color=\"#AF0000\">&quot;devid.neo@learningcontainer.com&quot;</font>\n  },\n  {\n    <font color=\"#008700\"><b>&quot;userId&quot;</b></font>: <font color=\"#626262\">5</font>,\n    <font color=\"#008700\"><b>&quot;firstName&quot;</b></font>: <font color=\"#AF0000\">&quot;jone&quot;</font>,\n    <font color=\"#008700\"><b>&quot;lastName&quot;</b></font>: <font color=\"#AF0000\">&quot;mac&quot;</font>,\n    <font color=\"#008700\"><b>&quot;phoneNumber&quot;</b></font>: <font color=\"#AF0000\">&quot;111111111&quot;</font>,\n    <font color=\"#008700\"><b>&quot;emailAddress&quot;</b></font>: <font color=\"#AF0000\">&quot;jone.mac@learningcontainer.com&quot;</font>\n  }\n]\n\n[yonghang@mtp xtable]$ cat test/t3.json  | xtable\nuserId firstName lastName phoneNumber emailAddress\n------------------------------------------------------------------------\n1      Krish     Lee      123456      krish.lee@learningcontainer.com\n2      racks     jacson   123456      racks.jacson@learningcontainer.com\n3      denial    roast    33333333    denial.roast@learningcontainer.com\n4      devid     neo      222222222   devid.neo@learningcontainer.com\n5      jone      mac      111111111   jone.mac@learningcontainer.com\n</pre>\n\n-----\n### pivot \n<pre>[yonghang@mtp xtable]$ cat test/t3.json  | xtable -v\nuserId       : 1\nfirstName    : Krish\nlastName     : Lee\nphoneNumber  : 123456\nemailAddress : krish.lee@learningcontainer.com\n--\nuserId       : 2\nfirstName    : racks\nlastName     : jacson\nphoneNumber  : 123456\nemailAddress : racks.jacson@learningcontainer.com\n--\nuserId       : 3\nfirstName    : denial\nlastName     : roast\nphoneNumber  : 33333333\nemailAddress : denial.roast@learningcontainer.com\n--\nuserId       : 4\nfirstName    : devid\nlastName     : neo\nphoneNumber  : 222222222\nemailAddress : devid.neo@learningcontainer.com\n--\nuserId       : 5\nfirstName    : jone\nlastName     : mac\nphoneNumber  : 111111111\nemailAddress : jone.mac@learningcontainer.com\n</pre>\n\nif we look at the source code, we know class xtable support .pivot() as well,\n\n<pre>        <font color=\"#E9AD0C\">if</font> <font color=\"#33C7DE\"><b>type</b></font>(js) <font color=\"#E9AD0C\">is</font> <font color=\"#33C7DE\"><b>list</b></font> :\n            xt = xtable.init_from_json(js,args.header)\n            <font color=\"#E9AD0C\">if</font> args.pivot :\n                <font color=\"#33C7DE\"><b>print</b></font>(xt.pivot<span style=\"background-color:#2AA1B3\">()</span>)\n            <font color=\"#E9AD0C\">else</font> :\n                <font color=\"#33C7DE\"><b>print</b></font>(xt)\n</pre>\n\n\n-----\n### when header has space...\nsome command output is already a table, only not that decent, eg. as below. xtable will help a little bit.  `-c` told xtable that `container id` is together while `-t` told xtable the input stream is already in \"table\" format.\n\n<pre>[yonghang@mtp xtable]$ sudo podman ps --all\nCONTAINER ID  IMAGE                           COMMAND               CREATED             STATUS                         PORTS   NAMES\neeb5db3c4f9a  docker.io/library/nginx:latest  nginx -g daemon o...  About a minute ago  Exited (0) About a minute ago          romantic_hamilton\n5ef267563b44  docker.io/library/httpd:latest  httpd-foreground      55 seconds ago      Exited (0) 6 seconds ago               sad_lamarr\n[yonghang@mtp xtable]$ \n[yonghang@mtp xtable]$ \n[yonghang@mtp xtable]$ sudo podman ps --all | xtable -c &quot;CONTAINER ID&quot; -t\nCONTAINER ID IMAGE                          COMMAND              CREATED            STATUS                        PORTS NAMES\n----------------------------------------------------------------------------------------------------------------------------------------\neeb5db3c4f9a docker.io/library/nginx:latest nginx -g daemon o... About a minute ago Exited (0) About a minute ago       romantic_hamilto\n5ef267563b44 docker.io/library/httpd:latest httpd-foreground     About a minute ago Exited (0) 28 seconds ago           sad_lamar\n[yonghang@mtp xtable]$ \n[yonghang@mtp xtable]$ sudo podman ps --all | xtable -c &quot;CONTAINER ID&quot; -tv\nCONTAINER ID : eeb5db3c4f9a\nIMAGE        : docker.io/library/nginx:latest\nCOMMAND      : nginx -g daemon o...\nCREATED      : About a minute ago\nSTATUS       : Exited (0) About a minute ago\nPORTS        : \nNAMES        : romantic_hamilto\n--\nCONTAINER ID : 5ef267563b44\nIMAGE        : docker.io/library/httpd:latest\nCOMMAND      : httpd-foreground\nCREATED      : About a minute ago\nSTATUS       : Exited (0) 32 seconds ago\nPORTS        : \nNAMES        : sad_lamar\n</pre>\n\n### xtable take care of lines\n\n<pre>[yonghang@W5202860 test]$ cat sql.json  | qic\n[\n  {\n    <font color=\"#008700\"><b>&quot;name&quot;</b></font>: <font color=\"#AF0000\">&quot;sql example 1&quot;</font>,\n    <font color=\"#008700\"><b>&quot;query&quot;</b></font>: <font color=\"#AF0000\">&quot;SELECT QUARTER, REGION, SUM(SALES)\\n FROM SALESTABLE\\n GROUP BY CUBE (QUARTER, REGION)&quot;</font>\n  },\n  {\n    <font color=\"#008700\"><b>&quot;name&quot;</b></font>: <font color=\"#AF0000\">&quot;sql example 2&quot;</font>,\n    <font color=\"#008700\"><b>&quot;query&quot;</b></font>: <font color=\"#AF0000\">&quot;select name, cast(text as varchar(8000)) \\nfrom SYSIBM.SYSVIEWS \\n where name=&apos;your table name&apos; &quot;</font>\n  },\n  {\n    <font color=\"#008700\"><b>&quot;name&quot;</b></font>: <font color=\"#AF0000\">&quot;sql example 3&quot;</font>,\n    <font color=\"#008700\"><b>&quot;query&quot;</b></font>: <font color=\"#AF0000\">&quot;select Id, max(V1),max(V2),max(V3) from \\n (\\n select ID,Value V1,&apos;&apos; V2,&apos;&apos; V3 from A where Code=1 \\n union all \\n select ID,&apos;&apos; V1, Value V2,&apos;&apos; V3 from A where Code=2 \\n union all \\n select ID,&apos;&apos; V1, &apos;&apos; V2,Value V3 from A where Code=3 \\n) AG\\n group by ID&quot;</font>\n  }\n]\n\n[yonghang@W5202860 test]$ \n[yonghang@W5202860 test]$ cat sql.json  | xtable\nname          query\n-------------------------------------------------------------------\nsql example 1 SELECT QUARTER, REGION, SUM(SALES)\n               FROM SALESTABLE\n               GROUP BY CUBE (QUARTER, REGION)\nsql example 2 select name, cast(text as varchar(8000))\n              from SYSIBM.SYSVIEWS\n               where name=&apos;your table name&apos;\nsql example 3 select Id, max(V1),max(V2),max(V3) from\n               (\n               select ID,Value V1,&apos;&apos; V2,&apos;&apos; V3 from A where Code=1\n               union all\n               select ID,&apos;&apos; V1, Value V2,&apos;&apos; V3 from A where Code=2\n               union all\n               select ID,&apos;&apos; V1, &apos;&apos; V2,Value V3 from A where Code=3\n              ) AG\n               group by ID\n</pre>\n\n\n## markdown\n\n```\nyonghang@air xtable % cat test/t2.csv\nh1,h2,h3\n\"asd\",\"sdfsadf\",1\n\"c\",\"cc\",233\n\nyonghang@air xtable % cat test/t2.csv | xtable -F md\n|  h1,h2,h3           |\n|  -----------------  |\n|  \"asd\",\"sdfsadf\",1  |\n|  \"c\",\"cc\",233       |\nyonghang@air xtable %\nyonghang@air xtable % cat test/t1.txt\na b c\n121 1212 12\n12 332  2323\nyonghang@air xtable % cat test/t1.txt | xtable -F md\n|  a    | b    | c     |\n|  ---- | ---- | ----  |\n|  121  | 1212 | 12    |\n|  12   | 332  | 2323  |\nyonghang@air xtable %\nyonghang@air xtable % cat test/t3.json | qic\n[\n  {\n    \"userId\": 1,\n    \"firstName\": \"Krish\",\n    \"lastName\": \"Lee\",\n    \"phoneNumber\": \"123456\",\n    \"emailAddress\": \"krish.lee@learningcontainer.com\"\n  },\n  {\n    \"userId\": 2,\n    \"firstName\": \"racks\",\n    \"lastName\": \"jacson\",\n    \"phoneNumber\": \"123456\",\n    \"emailAddress\": \"racks.jacson@learningcontainer.com\"\n  },\n  {\n    \"userId\": 3,\n    \"firstName\": \"denial\",\n    \"lastName\": \"roast\",\n    \"phoneNumber\": \"33333333\",\n    \"emailAddress\": \"denial.roast@learningcontainer.com\"\n  },\n  {\n    \"userId\": 4,\n    \"firstName\": \"devid\",\n    \"lastName\": \"neo\",\n    \"phoneNumber\": \"222222222\",\n    \"emailAddress\": \"devid.neo@learningcontainer.com\"\n  },\n  {\n    \"userId\": 5,\n    \"firstName\": \"jone\",\n    \"lastName\": \"mac\",\n    \"phoneNumber\": \"111111111\",\n    \"emailAddress\": \"jone.mac@learningcontainer.com\"\n  }\n]\n\nyonghang@air xtable %\nyonghang@air xtable % cat test/t3.json | xtable -F md\n|  userId | firstName | lastName | phoneNumber | emailAddress                        |\n|  ------ | --------- | -------- | ----------- | ----------------------------------  |\n|       1 | Krish     | Lee      | 123456      | krish.lee@learningcontainer.com     |\n|       2 | racks     | jacson   | 123456      | racks.jacson@learningcontainer.com  |\n|       3 | denial    | roast    | 33333333    | denial.roast@learningcontainer.com  |\n|       4 | devid     | neo      | 222222222   | devid.neo@learningcontainer.com     |\n|       5 | jone      | mac      | 111111111   | jone.mac@learningcontainer.com      |\nyonghang@air xtable %\n```\n",
    "bugtrack_url": null,
    "license": "Apache 2",
    "summary": "operate table format in console. console table, csv, json, yaml and markdown.",
    "version": "1.1.6",
    "split_keywords": [
        "xtable",
        "table",
        "simpletable",
        "quicktable"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8557904d5bedd62e86498b2313b7003aba7284727f2f2882dc64d94a3ea3e7ad",
                "md5": "6d6e2958324091e1d13d7b6a9341ff75",
                "sha256": "0c017be27bb6e2e1d8934cecb7e8da868d8c117ca0d44e96c2f0c1deff7bfbb7"
            },
            "downloads": -1,
            "filename": "xtable-1.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "6d6e2958324091e1d13d7b6a9341ff75",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 18901,
            "upload_time": "2023-01-05T15:39:42",
            "upload_time_iso_8601": "2023-01-05T15:39:42.972215Z",
            "url": "https://files.pythonhosted.org/packages/85/57/904d5bedd62e86498b2313b7003aba7284727f2f2882dc64d94a3ea3e7ad/xtable-1.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-05 15:39:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "walkerever",
    "github_project": "xtable",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "xtable"
}
        
Elapsed time: 0.02830s