Table of Contents
Why?
Data and object validation in Python is essential to ensure that the inputs to a program are
accurate and adhere to expected formats, thereby preventing runtime errors and enhancing code
reliability. The TypeScript library zod offers a concise and expressive syntax for schema
validation, making it easier to define and enforce data structures. Implementing a similar library
in Python would greatly benefit developers by providing a streamlined, declarative approach to
validation, reducing boilerplate code and improving maintainability. This would facilitate more
robust data handling and enhance the overall quality of Python applications.
What about the name?
I chose the name "Parasite" for this library because it draws heavy inspiration from the TypeScript
zod library, which excels in schema validation with its concise and expressive syntax. The name
"Parasite" is also a nod to one of Superman's iconic supervillains, serving as an homage to the
library that inspired this creation.
Getting Started
Installing
Install using pip:
pip install parasite
Install using poetry CLI:
poetry add parasite
or using pyproject.toml:
[tool.poetry.dependencies]
parasite = "^0.1.0"
Example usage
from parasite import p
schema = p.obj({
"name": p.string().required(),
"age": p.number().integer().min(0).optional(),
}).strip()
data = {
"name": "John Doe",
"age": 42,
"extra": "This will be stripped",
}
schema.parse(data) # {"name": "John Doe", "age": 42}
schema.parse({}) # ValidationError: Missing required key: "name"
Documentation
Code Coverage
---------- coverage: platform linux, python 3.11.9-final-0 -----------
Name Stmts Miss Cover
----------------------------------------------
src/parasite/__init__.py 22 0 100%
src/parasite/_const.py 17 0 100%
src/parasite/_utils.py 7 0 100%
src/parasite/any.py 27 0 100%
src/parasite/array.py 70 0 100%
src/parasite/boolean.py 72 0 100%
src/parasite/errors.py 1 0 100%
src/parasite/never.py 18 0 100%
src/parasite/null.py 29 0 100%
src/parasite/number.py 106 0 100%
src/parasite/object.py 93 0 100%
src/parasite/string.py 207 0 100%
src/parasite/type.py 29 0 100%
src/parasite/variant.py 61 0 100%
----------------------------------------------
TOTAL 759 0 100%
License (MIT License)
Copyright (c) 2024, Hendrik Böck <hendrikboeck.dev@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Metadata
Release files for parasite 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| parasite-0.1.10.tar.gz | 20.1 kB | Without provenance | Details for parasite-0.1.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| parasite-0.1.10-py3-none-any.whl | Python 3 | none | any | Details for parasite-0.1.10-py3-none-any.whl |
Total release size: 47.8 kB
Release files / parasite-0.1.10.tar.gz
| Download URL | parasite-0.1.10.tar.gz |
|---|---|
| Size | 20.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f919a69565c6c09ca48c460dd0f873c754605b7bba3d4e171921a91551d37f58
|
|
BLAKE2b-256 checksum How to use checksums |
46289d12877c0a2e84085767b64559bc76d892bf0df26528255a0963348bf718
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / parasite-0.1.10-py3-none-any.whl
| Download URL | parasite-0.1.10-py3-none-any.whl |
|---|---|
| Size | 27.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c07df18f16acaf03a3e018eca21466255795ed9bd83cb8c5bf0ace2a9d3e6682
|
|
BLAKE2b-256 checksum How to use checksums |
1ff3d557f8ccb7ba0df4c8595a52b3102db99d7f4ad3f7e3083e4696db8fc814
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Security for parasite 0.1.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.