Pyngo

Latest version: v2.0.1

Safety actively analyzes 638646 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 2

1.3.0

CVE-2022-34265: Potential SQL injection via `Trunc(kind)` and `Extract(lookup_name)` arguments `Trunc()` and `Extract()` database functions were subject to SQL injection if untrusted data was used as a `kind/lookup_name` value.

What's Changed
* Loosen Django pinned requirements by alysivji in https://github.com/yezz123/pyngo/pull/27

New Contributors
* alysivji made their first contribution in https://github.com/yezz123/pyngo/pull/27

**Full Changelog**: https://github.com/yezz123/pyngo/compare/1.2.0...1.3.0

1.2.0

Not secure
What's Changed
* Chore(deps): Bump pydantic from 1.8.2 to 1.9.0 by dependabot in https://github.com/yezz123/pyngo/pull/8
* Chore(deps-dev): Bump pre-commit from 2.16.0 to 2.17.0 by dependabot in https://github.com/yezz123/pyngo/pull/10
* Chore(deps-dev): Bump pytest from 6.2.5 to 7.0.0 by dependabot in https://github.com/yezz123/pyngo/pull/14
* Chore(deps-dev): Bump pytest from 7.0.0 to 7.0.1 by dependabot in https://github.com/yezz123/pyngo/pull/15
* chore(feat): Migrate to Flit Dependencies Manager by yezz123 in https://github.com/yezz123/pyngo/pull/26


**Full Changelog**: https://github.com/yezz123/pyngo/compare/1.1.0...1.2.0

1.1.0

Not secure
What's Changed
* Chore(deps-dev): Bump pre-commit from 2.15.0 to 2.16.0 by dependabot in https://github.com/yezz123/pyngo/pull/4
* Chore: Define Classes & Functions by adding `DocString` by yezz123 in https://github.com/yezz123/pyngo/pull/6
* Add `get_nested` function by yezz123 in https://github.com/yezz123/pyngo/pull/7


**Full Changelog**: https://github.com/yezz123/pyngo/compare/1.0.0...1.1.0

1.0.0

Not secure
Features 🎉

- Using Pydantic to Build your Models in Django Project.
- Using `OpenAPI` utilities to build params from a basic model.
- using `QueryDictModel` to build `Pydantic` models from a `QueryDict` object.
- propagate any errors from Pydantic in Django Rest Framework.
- Tested in Python 3.6 and up.

Examples 📚

OpenAPI

- `pyngo.openapi_params()` can build params from a basic model

py
from pydantic import BaseModel
from pyngo import openapi_params

class Model(BaseModel):
bingo: int

print(openapi_params(Model))


- `pyngo.ParameterDict.required` is set according to the type of the variable

py
from typing import Optional
from pydantic import BaseModel
from pyngo import openapi_params

class Model(BaseModel):
required_param: int
optional_param: Optional[int]

print(openapi_params(Model))


Other fields can be set through the field’s info:

py
from pydantic import BaseModel, Field
from pyngo import openapi_params

class WithDescription(BaseModel):
described_param: str = Field(
description="Hello World Use Me!"
)

class InPath(BaseModel):
path_param: str = Field(location="path")

class WithDeprecated(BaseModel):
deprecated_field: bool = Field(deprecated=True)

class WithNoAllowEmpty(BaseModel):
can_be_empty: bool = Field(allowEmptyValue=False)

print(openapi_params(WithDescription)[0]["description"])
print(openapi_params(InPath)[0]["in"])
print(openapi_params(WithDeprecated)[0]["deprecated"])
print(openapi_params(WithNoAllowEmpty)[0]["allowEmptyValue"])


Django

- `pyngo.querydict_to_dict()` and `pyngo.QueryDictModel` are conveniences for building a `pydantic.BaseModel` from a `django.QueryDict`.

py
from typing import List
from django.http import QueryDict
from pydantic import BaseModel
from pyngo import QueryDictModel, querydict_to_dict

class Model(BaseModel):
single_param: int
list_param: List[str]

class QueryModel(QueryDictModel):
single_param: int
list_param: List[str]

query_dict = QueryDict("single_param=20&list_param=Life")

print(Model.parse_obj(querydict_to_dict(query_dict, Model)))
print(QueryModel.parse_obj(query_dict))


> **Note:** Don't forget to Setup the Django Project.

Django Rest Framework

- `pyngo.drf_error_details()` will propagate any errors from Pydantic.

py
from pydantic import BaseModel, ValidationError
from pyngo import drf_error_details

class Model(BaseModel):
foo: int
bar: str

data = {"foo": "Cat"}

try:
Model.parse_obj(data)
except ValidationError as e:
print(drf_error_details(e))


Errors descend into nested fields:

py
from typing import List
from pydantic import BaseModel, ValidationError
from pyngo import drf_error_details

class Framework(BaseModel):
frm_id: int

class Language(BaseModel):
framework: List[Framework]

data = {"Framework": [{"frm_id": "not_a_number"}, {}]}
expected_details = {
"framework": {
"0": {"frm_id": ["value is not a valid integer"]},
"1": {"frm_id": ["field required"]},
}
}

try:
Framework.parse_obj(data)
except ValidationError as e:
print(drf_error_details(e))

Page 2 of 2

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.