Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
harttraveller committed Nov 7, 2024
1 parent 0d4593e commit a234660
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 40 deletions.
2 changes: 1 addition & 1 deletion docs/module/pyeio.json.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: json
---

::: pyeio.json
::: pyeio.json
124 changes: 101 additions & 23 deletions docs/notebook/json.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,103 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# comment this out to use default `print` function\n",
"from rich import print"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic usage"
"## Basic Usage"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# import the necessary module\n",
"from pyeio import json"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Opening a file"
"### Parsing serialized data\n",
"\n",
"Reference: https://harttraveller.github.io/pyeio/module/pyeio.json/#pyeio.json.parse"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'color': 'green', 'count': 3}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"python_dictionary = json.parse(data='{\"color\":\"green\", \"count\": 3}')\n",
"python_dictionary"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Serializing python data\n",
"\n",
"Reference: https://harttraveller.github.io/pyeio/module/pyeio.json/#pyeio.json.serialize"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'{\\n \"color\": \"green\", \\n \"count\": 3\\n}'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"json_string = json.serialize(python_dictionary, compact_serialization=False)\n",
"json_string"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Opening a file\n",
"\n",
"Reference: https://harttraveller.github.io/pyeio/module/pyeio.json/#pyeio.json.open"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -123,38 +187,45 @@
}
],
"source": [
"data = json.open(file_path=\"../../data/json/books.json\")\n",
"\n",
"print(data)"
"# load the data into memory\n",
"python_dictionary = json.open(path=\"../../data/json/books.json\")\n",
"# print the data\n",
"print(python_dictionary)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Saving data to a file"
"### Saving data to a file\n",
"\n",
"Reference: https://harttraveller.github.io/pyeio/module/pyeio.json/#pyeio.json.save"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"data = {\"message\": \"hello world\", \"data\": [1, 2, 3, 4]}\n",
"json.save(data=data, path=\"./temp/temp.json\")"
"# defin sample data\n",
"python_dictionary = {\"message\": \"hello world\", \"data\": [1, 2, 3, 4]}\n",
"# save to local temp file\n",
"json.save(data=python_dictionary, path=\"./temp/temp.json\", overwrite=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Loading data from a URL"
"### Loading data from a URL\n",
"\n",
"Reference: https://harttraveller.github.io/pyeio/module/pyeio.json/#pyeio.json.load"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -236,38 +307,45 @@
}
],
"source": [
"data = json.load(\n",
"# load the data from url\n",
"python_dictionary = json.load(\n",
" url=\"https://raw.githubusercontent.com/harttraveller/pyeio/refs/heads/main/data/json/books.json\"\n",
")\n",
"\n",
"print(data)"
"# print data\n",
"print(python_dictionary)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Downloading data at a URL to a file"
"### Downloading data at a URL to a file\n",
"\n",
"Reference: https://harttraveller.github.io/pyeio/module/pyeio.json/#pyeio.json.download"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# download data to local file\n",
"json.download(\n",
" url=\"https://raw.githubusercontent.com/harttraveller/pyeio/refs/heads/main/data/json/books.json\",\n",
" path=\"./temp/books.json\",\n",
" overwrite=True,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"## Meta Module\n",
"\n",
"**TODO**"
]
}
],
"metadata": {
Expand Down
15 changes: 1 addition & 14 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ plugins:
show_object_full_path: true
show_root_heading: true
heading_level: 1

# - mkdocstrings:
# handlers:
# python:
# options:
# show_root_heading: true
# show_object_full_path: true
# allow_inspection: true
# show_bases: false
# parameter_headings: false
show_signature: false

theme:
name: material
Expand All @@ -40,16 +31,12 @@ theme:
- navigation.indexes
- navigation.instant
- navitation.instant.progress
# - navigation.footer
- search.suggest
- search.share
- content.code.copy
- content.code.annotate
- header.autohide

# extra:
# generator: false

# extra_css:
# - static/extra.css

Expand Down
4 changes: 2 additions & 2 deletions pyeio/base/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
variant_file_extensions: tuple[VariantFileExtension, ...] = get_args(
VariantFileExtension
)
file_extensions: tuple[FileExtension, ...] = get_args(
FileExtension,
file_extensions: tuple[FileExtension, ...] = (
standard_file_extensions + variant_file_extensions
)


Expand Down

0 comments on commit a234660

Please sign in to comment.