Skip to content

Commit 608b517

Browse files
committed
improve documentation
1 parent a9a45f8 commit 608b517

25 files changed

+844
-132
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
- [Why?](#why)
3434
- [What about the name?](#what-about-the-name)
3535
- [Getting Started](#getting-started)
36+
- [Installing](#installing)
37+
- [Example usage](#example-usage)
3638
- [Documentation](#documentation)
3739
- [License (_MIT License_)](#license-mit-license)
3840

@@ -55,15 +57,17 @@ library that inspired this creation.
5557

5658
## Getting Started
5759

60+
### Installing
61+
5862
Install using `pip`:
5963

60-
```
64+
```sh
6165
pip install parasite
6266
```
6367

6468
Install using `poetry` CLI:
6569

66-
```
70+
```sh
6771
poetry add parasite
6872
```
6973

@@ -74,10 +78,31 @@ or using `pyproject.toml`:
7478
parasite = "^0.1.0"
7579
```
7680

81+
### Example usage
82+
83+
```python
84+
from parasite import p
85+
86+
schema = p.obj({
87+
"name": p.string().required(),
88+
"age": p.number().integer().min(0).optional(),
89+
}).strip()
90+
91+
data = {
92+
"name": "John Doe",
93+
"age": 42,
94+
"extra": "This will be stripped",
95+
}
96+
97+
schema.parse(data) # {'name': 'John Doe', 'age': 42}
98+
schema.parse({}) # ValidationError: Missing required key: 'name'
99+
```
100+
77101
## Documentation
78102

79103
> [!IMPORTANT]
80-
> Work in Progress...
104+
>
105+
> You can find the sphinx online documentation [here](https://hendrikboeck.github.io/parasite)!
81106
82107
## License (_MIT License_)
83108

docs/source/apidocs/index.rst

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/source/apidocs/pkg_parasite/_const.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
############################
2-
``_const`` Private Submodule
3-
############################
1+
###################
2+
``parasite._const``
3+
###################
4+
5+
Member Reference
6+
================
47

58
.. automodule:: parasite._const
69
:members:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
############
2+
``parasite``
3+
############
4+
5+
Member Reference
6+
================
7+
8+
.. automodule:: parasite
9+
:members:
10+
:inherited-members:
11+
:undoc-members:
12+
:show-inheritance:

docs/source/apidocs/pkg_parasite/any.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
###########################
2-
``any`` Submodule Reference
3-
###########################
1+
################
2+
``parasite.any``
3+
################
44

55
Brief
66
=====

docs/source/apidocs/pkg_parasite/array.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#############################
2-
``array`` Submodule Reference
3-
#############################
1+
##################
2+
``parasite.array``
3+
##################
44

55
Brief
66
=====

docs/source/apidocs/pkg_parasite/boolean.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
###############################
2-
``boolean`` Submodule Reference
3-
###############################
1+
####################
2+
``parasite.boolean``
3+
####################
44

55
Brief
66
=====

docs/source/apidocs/pkg_parasite/errors.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
##############################
2-
``errors`` Submodule Reference
3-
##############################
1+
###################
2+
``parasite.errors``
3+
###################
44

55
Brief
66
=====
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
####################
2-
``parasite`` Package
3-
####################
1+
.. _apidocs:
42

5-
Module API
6-
==========
3+
#############
4+
API Reference
5+
#############
76

8-
.. automodule:: parasite
9-
:members:
10-
:undoc-members:
11-
:show-inheritance:
7+
This section documents the API of the ``parasite`` package. Use the links below to
8+
navigate the code documentation.
129

13-
Module Reference
14-
================
10+
Modules
11+
=======
1512

1613
.. toctree::
1714
:maxdepth: 3
1815

16+
_root
1917
_const
2018
errors
2119
any
2220
array
2321
boolean
22+
never
23+
object
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
##################
2+
``parasite.never``
3+
##################
4+
5+
Brief
6+
=====
7+
8+
Reference for the ``never`` submodule of the ``parasite`` package. This submodule
9+
contains the :class:`Never` class, which is a simple class that always raises a
10+
:class:`ValidationError` when called.
11+
12+
Usage
13+
=====
14+
15+
.. code-block:: python
16+
17+
from parasite import p
18+
19+
schema = p.never()
20+
schema.parse(1) # ValidationError: this type can never be parsed
21+
...
22+
23+
schema = p.obj({ "name": p.never() })
24+
schema.parse({ "name": "John" }) # ValidationError: key 'name' found, but this type can never be parsed
25+
...
26+
27+
Member Reference
28+
================
29+
30+
.. automodule:: parasite.never
31+
:members:
32+
:inherited-members:
33+
:undoc-members:
34+
:show-inheritance:
35+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
###################
2+
``parasite.object``
3+
###################
4+
5+
Brief
6+
=====
7+
8+
Reference for the ``object`` submodule of the ``parasite`` package. This submodule
9+
contains the :class:`Object` class, which is a generic container for a dictionary Python object.
10+
11+
Usage
12+
=====
13+
14+
.. code-block:: python
15+
16+
from parasite import p
17+
18+
schema = p.obj({
19+
"name": p.string(),
20+
"age": p.number().integer().min(0),
21+
}).strict()
22+
23+
schema.parse({
24+
"name": "John",
25+
"age": 30,
26+
}) # -> {'name': 'John', 'age': 30 }
27+
...
28+
29+
Member Reference
30+
================
31+
32+
.. automodule:: parasite.object
33+
:members:
34+
:inherited-members:
35+
:undoc-members:
36+
:show-inheritance:
37+

docs/source/conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
project = 'Parasite'
1515
copyright = f'2024-{datetime.date.today().year}, Hendrik Boeck <hendrikboeck.dev@protonmail.com>'
1616
author = 'Hendrik Boeck <hendrikboeck.dev@protonmail.com>'
17-
release = 'v0.1.5'
17+
release = 'v0.1.6'
1818
html_title = f"{project} {release}"
1919

2020
# -- General configuration ---------------------------------------------------
@@ -30,9 +30,13 @@
3030
templates_path = ['_templates']
3131
exclude_patterns = []
3232

33+
pygments_style = "emacs"
34+
pygments_dark_style = "one-dark"
35+
3336
# -- Options for HTML output -------------------------------------------------
3437
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3538
html_theme = 'qiskit-ecosystem'
39+
# html_theme = 'furo'
3640
html_static_path = ['_static']
3741
html_logo = "_static/parasite-logo.png"
3842

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Welcome to Parasite's documentation!
99
.. toctree::
1010
:hidden:
1111

12-
API Reference <apidocs/index>
12+
API Reference <apidocs/pkg_parasite/index>
1313
GitHub <https://github.com/hendrikboeck/parasite>
1414

1515
.. Documentation Home <index>

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "parasite"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
description = "Data validation for Python 3"
55
authors = ["Hendrik Boeck <hendrikboeck.dev@protonmail.com>"]
66
packages = [{ include = "*", from = "src" }]

src/parasite/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class p(_Namespace):
1919
sudo-namespace for all parasite types. Makes it easier to import and call them. Tries to mimic
2020
the behavior of the ``z`` object imported from ``zod`` library in JavaScript.
2121
22-
Example::
22+
Example usage::
2323
2424
>>> from parasite import p
2525
>>>

src/parasite/any.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,46 @@ def __init__(self) -> None:
3737

3838
def optional(self) -> Any_:
3939
"""
40-
Makes the value optional, when parsing with ``_find_and_parse(..)``. Has no effect on
41-
``parse(..)``. Inverse of ``required(..)``.
40+
Makes the value optional, when parsing with :func:`_find_and_parse`. Has no effect on
41+
:func:`parse`. Inverse of :func:`required`.
4242
4343
Returns:
4444
Any_: modified instance
45+
46+
Example usage::
47+
48+
from parasite import p
49+
50+
schema = p.obj({ "name": p.any() })
51+
schema.parse({ "name": "John" }) # -> { "name": "John" }
52+
schema.parse({ }) # -> ValidationError: key 'name' not found, but is required
53+
54+
schema = p.obj({ "name": p.any().optional() })
55+
schema.parse({ "name": "John" }) # -> { "name": "John" }
56+
schema.parse({ }) # -> { }
4557
"""
4658
self._f_optional = True
4759
return self
4860

4961
def required(self) -> Any_:
5062
"""
51-
Makes the value required, when parsing with ``_find_and_parse(..)``. Has no effect on
52-
``parse(..)``. Inverse of ``optional(..)``. Default behavior.
63+
Makes the value required, when parsing with :func:`_find_and_parse`. Has no effect on
64+
:func:`parse`. Inverse of :func:`optional`. Default behavior.
5365
5466
Returns:
5567
Any_: modified instance
68+
69+
Example usage::
70+
71+
from parasite import p
72+
73+
schema = p.obj({ "name": p.any() })
74+
schema.parse({ "name": "John" }) # -> { "name": "John" }
75+
schema.parse({ }) # -> ValidationError: key 'name' not found, but is required
76+
77+
schema = p.obj({ "name": p.any().required() })
78+
schema.parse({ "name": "John" }) # -> { "name": "John" }
79+
schema.parse({ }) # -> ValidationError: key 'name' not found, but is required
5680
"""
5781
self._f_optional = False
5882
return self

0 commit comments

Comments
 (0)