bike
A lightweight model validator for modern projects.
Instalation
pip install bike
First Pedals
Lets define a simple model to represent a person.
import bike
@bike.model()
class Person:
name: str
height: float
weight: float
...
p1 = Person(
name='Patrick Love',
height=75,
weight=180
)
A Person instance can be created passing the attributes. Also can be instantiated by a dict.
...
data = {
'name': 'Patrick Love',
'height': 75,
'weight': 180
}
p1 = Person(**data)
Nested Models
We can create and mananger more complex structs by nested models. It's simply by using a model as field type of other model.
# implement.py
import bike
@bike.model()
class Address:
address_1: str
address_2: str = ''
city: str
state: str
code: str
country: str
@bike.model()
class Phone:
country_code: str
local_code: str
number: str
@bike.model()
class Person:
name: str
address: Address
phones: list[Phone]
...
payload = {
'name': 'Aline Mark',
'address': {
'address_1': '239 W 45th St',
'address_2': '',
'city': 'New York',
'state': 'NY',
'code': '10036',
'country': 'EUA'
},
'phones': [
{
'country_code': '+1',
'local_code': '010',
'number': '134354325'
},
{
'country_code': '+2',
'local_code': '011',
'number': '134565436'
}
]
}
p1 = Person(**payload)
print(p1.phones[0].country_code)
# +1
print(p1.phones[1].local_code)
# 011
print(p1.address.state)
# NY
Parsing to Json and Dict
We can parse data to dict or json by using .dict() or json() methods respectively.
import bike
@bike.model()
class Make:
name: str
country: str
@bike.model()
class Car:
name: str
make: Make
m1 = Make(name='Nissan', country='JP')
c1 = Car(name='Leaf', make=m1)
c1_dict = c1.dict()
print(c1_dict['make']['country'])
# JP
c1_json = c1.json()
print(c1_json)
# {"name": "Leaf", "make": {"name": "Nissan", "country": "JP"}}
Validating Fields
Fields can be validated adding the validator annotation.
import bike
@bike.model()
class Character:
name: str
health: float = 1.0
@bike.validator('name')
def name_validator(cls, val):
return val.title()
@bike.validator('health')
def health_validator(cls, val):
if val < 0:
return 0.0
elif val > 1:
return 1.0
return val
c1 = Character(name='ninki walker', health=2.0)
print(c1.name)
# Ninki Walker
print(c1.health)
# 1.0
Metadata
Release files for bike 0.3.6
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 |
|---|---|---|---|---|
| bike-0.3.6.tar.gz | 5.9 kB | Without provenance | Details for bike-0.3.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bike-0.3.6-py3-none-any.whl | Python 3 | none | any | Details for bike-0.3.6-py3-none-any.whl |
Total release size: 12.8 kB
Release files / bike-0.3.6.tar.gz
| Download URL | bike-0.3.6.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a65349b58528a2d6e0ad2b67ac0e2fadb653e41bbc05294130294030748b2ca2
|
|
BLAKE2b-256 checksum How to use checksums |
ef6f6a8528ea250ad075dc6255d60b30d4d6c5815ea535d154d2cb208cad150b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-45-generic
|
Release files / bike-0.3.6-py3-none-any.whl
| Download URL | bike-0.3.6-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7303e235b682b4386db7b57bd1674328822c54b2bce432184ccf951c9358444
|
|
BLAKE2b-256 checksum How to use checksums |
204fa643bd0c2f258515d2cd3da520f12d810c61f34647bb81722f1277f5bfff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-45-generic
|
Security for bike 0.3.6
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.