Skip to main content

pycrud

codecov

A common crud framework for web.

The project moved to https://pypi.org/project/pycrud/

Features:

  • Generate query by json or dsl

  • Role based permission system

  • Easy to integrate with web framework

  • Tested coveraged

Examples:

Define

from typing import Optional

from playhouse.db_url import connect
from pycurd.crud.ext.peewee_crud import PeeweeCrud
from pycurd.types import RecordMapping

class User(RecordMapping):
    id: Optional[int]
    nickname: str
    username: str
    password: str = 'password'


db = connect("sqlite:///:memory:")

c = PeeweeCrud(None, {
    User: 'users'
}, db)

Create

from pycurd.values import ValuesToWrite

v = ValuesToWrite({'nickname': 'wwww', 'username': 'u2'})
lst = await c.insert_many(User, [v])

print(lst)

Read

from pycurd.query import QueryInfo

# from dsl
lst = await c.get_list(QueryInfo.from_table_raw(User, where=[
    User.id != 1
]))

# from json
lst = await c.get_list(QueryInfo.from_json(User, {
    'id.eq': 1
}))

print([x.to_dict() for x in lst])

Update

from pycurd.query import QueryInfo
from pycurd.values import ValuesToWrite

v = ValuesToWrite({'nickname': 'bbb', 'username': 'u2'})

# from dsl
lst = await c.update(QueryInfo.from_table_raw(User, where=[
    User.id.in_([1, 2, 3])
]))

# from json
lst = await c.update(QueryInfo.from_json(User, {
    'id.in': [1,2,3]
}), v)

print(lst)

Delete

from pycurd.query import QueryInfo

lst = await c.delete(QueryInfo.from_json(User, {
    'id.in': [1,2,3]
}))

print(lst)

Query by json

from pycurd.query import QueryInfo

# $or: (id < 3) or (id > 5)
QueryInfo.from_json(User, {
    '$or': {
        'id.lt': 3,  
        'id.gt': 5 
    }
})

# $and: 3 < id < 5
QueryInfo.from_json(User, {
    '$and': {
        'id.gt': 3,  
        'id.lt': 5 
    }
})


# $not: not (3 < id < 5)
QueryInfo.from_json(User, {
    '$not': {
        'id.gt': 3,  
        'id.lt': 5 
    }
})

# multiple same operator: (id == 3) or (id == 4) or (id == 5)
QueryInfo.from_json(User, {
    '$or': {
        'id.eq': 3,  
        'id.eq.2': 4,
        'id.eq.3': 5, 
    }
})

# multiple same operator: (3 < id < 5) or (10 < id < 15)
QueryInfo.from_json(User, {
    '$or': {
        '$and': {
            'id.gt': 3,
            'id.lt': 5
        },
        '$and.2': {
            'id.gt': 10,
            'id.lt': 15
        }
    }
})

Query by DSL

# $or: (id < 3) or (id > 5)
(User.id < 3) | (User.id > 5)

# $and: 3 < id < 5
(User.id > 3) & (User.id < 5)

# $not: not (3 < id < 5)
~((User.id > 3) & (User.id < 5))

# multiple same operator: (id == 3) or (id == 4) or (id == 5)
(User.id != 3) | (User.id != 4) | (User.id != 5)

# multiple same operator: (3 < id < 5) or (10 < id < 15)
((User.id > 3) & (User.id < 5)) | ((User.id > 10) & (User.id < 15))

Operators

type operator text
compare EQ ('eq', '==')
compare NE ('ne', '!=')
compare LT ('lt', '<')
compare LE ('le', '<=')
compare GE ('ge', '>=')
compare GT ('gt', '>')
relation IN ('in',)
relation NOT_IN ('notin', 'not in')
relation IS ('is',)
relation IS_NOT ('isnot', 'is not')
relation PREFIX ('prefix',)
relation CONTAINS ('contains',)
logic AND ('and',)
logic OR ('or',)
// usage:
{
  'time.ge': 1,
  '$or': {
    'id.in': [1, 2, 3],
    '$and': {
      'time.ge': 100,
      'time.le': 500,
    }
  }
}

Metadata

Release files for pycurd 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycurd 0.2.3
File Size Uploaded Provenance
pycurd-0.2.3.tar.gz 20.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pycurd 0.2.3
File Interpreter ABI Platform
pycurd-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 45.3 kB

Release files / pycurd-0.2.3.tar.gz

Download URL pycurd-0.2.3.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
934d62aefd19da61149532721e3c38f0a1f066a8d6d8c8880b581535b7293976
BLAKE2b-256 checksum
How to use checksums
d89eb209da57698a0e4911e0c3ddcad4443342580b41deb06351b7d5dd2bebe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.2 CPython/3.8.3 Windows/10

Release files / pycurd-0.2.3-py3-none-any.whl

Download URL pycurd-0.2.3-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
522921c8576d0866f5ecbd6865e6771d8042da0257546725b494be6479850e0e
BLAKE2b-256 checksum
How to use checksums
4cae3425c51b35fc69ac3ec2238ae33418a0259f17b3d4a538f988a4ee6de836
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.2 CPython/3.8.3 Windows/10

Security for pycurd 0.2.3

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page