推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
jfry
V2EX  ›  Python

找小伙伴一起造这个简单又实用的轮子:基于模式定义的对象验证器/转换器/生成器

  •  
  •   jfry ·
    toaco · Apr 4, 2018 · 2565 views
    This topic created in 2982 days ago, the information mentioned may be changed or developed.

    我的想法是主要实现这么一个库:使用 Python 定义模式,然后可以用改模式来:

    • 验证一个 Python 对象是否符合该模式
    • 将一个对象转换成符合该模式的对象
    • 随机生成符合该模式的对象
    • 基于该模式,提供一些其他库的扩展,比如:
      • flask/django 的参数验证扩展
      • pymongo 的简单 orm

    PyPI 上面类似的库是有的,但是觉得其 API 不好用,因此打算重新造一个轮子,下面是已经实现了的判断对象是否符合模式的例子:

    schema = {
        'a': [],
        'b': [
            {
                'c': int,
                'd': Int(default=3),
                'e': [str]
            }
        ],
        'c': Int(validator=lambda x: 1 < x < 10)
    }
    
    rubric.validate(schema, {
        'a': [],
        'b': [
            {
                'c': 1,
                'd': 2,
                'e': ['hello', 'world']
            }
        ],
        'c': 7
    }) # pass
    

    目前功能都只实现了部分(只作了验证,很多类型的验证规则也还没定义),代码也不到 200 行,因此特意来此找感兴趣的朋友来一起完成这个项目,主要是:

    • 一起设计出更好用的 API
    • 完成其他未完成的功能

    代码注释丰富,测试也很多,除了 pytest 之外不依赖任何第三方库.稍微熟悉 python 就可以了~,感兴趣的朋友快一起来吧~~

    2 replies    2018-04-04 15:04:59 +08:00
    jfry
        1
    jfry  
    OP
       Apr 4, 2018
    项目地址都忘记贴了=.=: https://github.com/toaco/rubric
    jfry
        2
    jfry  
    OP
       Apr 4, 2018
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3347 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 11:57 · PVG 19:57 · LAX 04:57 · JFK 07:57
    ♥ Do have faith in what you're doing.