caterpillar-api


Namecaterpillar-api JSON
Version 1.62 PyPI version JSON
download
home_pagehttps://github.com/lukedupin/caterpillar
Summary🐛 Caterpillar Api, field management for Django without the boiler-plate.
upload_time2023-12-28 21:10:40
maintainer
docs_urlNone
authorLuke Dupin
requires_python
licenseMIT
keywords django api rest json jsonp json-p
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Caterpillar

A light-weight, fast and scalable api solution for Django. Uses a comfy set of functionality that isn't boilerplatey or opinionated.

Don't disregard Caterpillar because it's cute, it's scrapy to; with built in type conversion, session management, dead simple file handling, self documenting reports and error management. Caterpillar makes writing APIs fun.

# Install Caterpillar

```bash
pip3 install caterpillar-api
```

### Define your API

Inside your django project, create a function with a *@Cocoon* wrapper that defines your paramaters.

```python
from caterpillar_api import Cocoon, monarch

@Cocoon( param_req=(
            ('a', int),
            ('b', int),
))
def add( request, a, b ):
    return { "c": a + b }
```

### Add your endpoint to Django

Inside url.py.

```python
urlpatterns = [
    path('add/', views.add),
    ...
]
```

### Test out your API

Now using curl, you can post data to the API and get a JSON response.

```bash
curl -d "a=17&b=35" -X POST http://127.0.0.1:8000/add/; echo
{"c": 52, "successful": true}
```

# Why Caterpillar?

* Minimum boiler-plate
* Readable syntax
* Crazy fast
* Easy to use
* Unopnionated

# Client libraries
Caterpillar doesn't leave you hanging. We have an ever growing list of client libraries to speed up your development efforts. Although you don't need a custom client side library, it sure does feel good using one.

* React fetch_js
* Qt C++/QML interface

# Recipes

## Required POST arguments
post_req takes a tuple of tuples. The tuple entries define (variable name, python type). You can trust the parameter will be the expected type. If a parameter is missing from a post_req, Caterpillar will respond with an error before the endpoint is called.


```python
@Cocoon( post_req=(
            ('name', str),
            ('age', int),
))
def add_user( request, name, age ):
    usr = User.objects.create( name=name, age=age )
    return { 'id': usr.id }
```

## Optional POST arguments
post_opt uses the same format as post_req. Fields can exist or not. If a field isn't present, the default paramater value or None is used.

```python
@Cocoon(
    post_req=(
            ('uid', str),
    ),
    post_opt=(
        ('name', str),
        ('age', int),
        ('type', str, 'ADMIN'),
    )
)
def modify_user( request, uid, name, age, type ):
    usr = User.objects.get(uid=uid)
    if name is not None:
        usr.name = name
    if age is not None:
        usr.age = age
    usr.type = type
    usr.save()
    
    return monarch.succ( request, {})
```

## Optional POST using kwargs
post_opt argument checking using if statements does work, but it's a little ugly. It also creates a lot of code. The same operation can be done with kwargs.

```python
@Cocoon(
    post_req=(
            ('uid', str),
    ),
    post_opt=(
            ('name', str),
            ('age', int),
            ('type', str, 'ADMIN'),
    )
)
def modify_user( request, uid, **kwargs ):
    usr = User.objects.get(uid=uid)

    for key in ('name', 'age', 'type'):
        if kwargs[key] is not None:
            usr.__setattr__( key, kwargs[key] )
    usr.save()

    return monarch.succ( request, {})
```

## Meta data
@Coccon can provide meta data as an argument. This is handy because it can further reduce duplicate logic. Parameters are defined in one place only. Take the above example, now using meta data.

```python
@Cocoon(
    post_req=(
            ('uid', str),
    ),
    post_opt=(
            ('name', str),
            ('age', int),
            ('type', str),
    ),
    meta="meta"
)
def modify_user( request, uid, meta, **kwargs ):
    usr = User.objects.get(uid=uid)

    for key, _ in meta.post_opt:
        if kwargs[key] is not None:
            usr.__setattr__( key, kwargs[key] )
    usr.save()

    return monarch.succ( request, {})
```

## Authenticate user and check login status
Caterpillar also helps you work with session information. Session data can be used to authenticate a user and confirm their login state.

```python
from django.forms import model_to_dict

@Cocoon( param_req=(
            ('uid', str),
            ('password', str),
))
def login( request, uid, password ):
    if (usr := getByUid(User, uid)) is None:
        return "Couldn't find user"

    if usr.password != password:
        return "Invalid password"

    # Store the user's info into the session, this effectively logs the user in
    request.session['usr'] = model_to_dict(usr)
    return {}


@Cocoon(
    sess_req=[('usr', dict)]
)
def logout( request, usr ):
    del request.session['usr']
    return monarch.succ( request, {})


# sess_req['usr'] will only allow this endpoint to be called by users that are logged in
@Cocoon(
    sess_req=[('usr', dict)]
)
def user_details( request, usr ):
    usr = getByUid(User, usr['uid'])
    return monarch.succ( request, model_to_dict(usr))
```

If optional session checking is required, you can always use sess_opt

```python
@Cocoon(
    sess_opt=[('usr', dict)]
)
def is_online( request, usr ):
    return monarch.succ( request, { 'online': usr is not None })
```

## GET data from the URL
The same way POST can have required and optional arguments, GET variables can be accessed with @Cocoon.

```python
@Cocoon(
    get_req=[('video_code', str)]
)
def get_video( request, usr, video_code ):
    #http://server.com/?video_code=XXX
    print(video_code) # Prints XXX
    return monarch.succ( request, {'video_info': 'info'})
```

## Read a file
Caterpillar seamlessly handles file uploads as parameters. Files, like GET/POST, can be required or optional. The contents of the uploaded file can be read by calling .data(). If a hash of the data is required .hash() will return a sha256 hash.

```python
@Cocoon(
    sess_req=[('usr', dict)],
    file_req=["logo"]
)
def upload_logo( request, usr, logo ):
    if not s3.put_data(logo.data(), usr['uid']):
        return monarch.fail( request, "Couldn't upload to S3")

    return monarch.succ( request, {})
```

## Need to call an endpoint directly?
Not a problem; Caterpillar will happily get out of your way. Passing None for the request parameter will tell Caterpillar you are using the functions directly. Instead of a HttpResponse, you'll get the dict of the response.

```python
@Cocoon(
    post_req=(
            ('a', int),
            ('b', int),
    )
)
def add( request, a, b ):
    return monarch.succ( request, { "c": a + b })

add( None, 4, 3) # Returns { "c": 12 }
add( None, "cat", "fish") # Returns { "c": "catfish" } # Type checking isn't done when calling directly
```

## Where are PUT and DELETE?
They didn't make the cut. PUT and DELETE don't add any new functionality over update and remove endpoints. PUT/DELETE aren't fundimental to Django and since Caterpillar aims to be as lightweight as possible, this feature is out of scope.

# @Cocoon

Cocoon is a function decorator that defines endpoint arguments and data types. 

* **sess_opt** - Optional session parameters. Array/Tuple of tuples. ('name', type) or ('name', type, default)
* **sess_req** - Required session parameters. Array/Tuple of tuples. ('name', type).
* **param_opt** - Optional POST/GET parameters. Array/Tuple of tuples. ('name', type) or ('name', type, default).
* **param_req** - Required POST/GET parameters. Array/Tuple of tuples. ('name', type).
* **post_opt** - Optional POST parameters. Array/Tuple of tuples. ('name', type) or ('name', type, default).
* **post_req** - Required POST parameters. Array/Tuple of tuples. ('name', type).
* **get_opt** - Optional GET parameters. Array/Tuple of tuples. ('name', type) or ('name', type, default).
* **get_req** - Required GET parameters. Array/Tuple of tuples. ('name', type).
* **file_opt** - Optional file parameters. Returns the ApiFile object with helper functions data() and hash() Array/Tuple of names. ('name').
* **file_req** - Required file parameters. Returns the ApiFile object with helper functions data() and hash() Array/Tuple of names. ('name').
* **files** - 'name' which recieves an array of Apifile classes. Handy for uploading arrays of unnamed filess.
* **meta** - 'name' which recieves a CaterpillarMeta object. All of the Cocoon parameters are represented along with an 'args' dictionary which holds all data passed to this endpoint.

### @Cocoon Types

* str
* int
* float
* bool - Can take true/false strings or true/false values or ints, 0 !0
* dict - A dictionary of key value pairs. JSON
* list - An array of parameters. Can take a string of delenated elements.

### CaterpillarMeta class
* **name** - The name of the variable.
* **args** - dict of all posted data.
* **param_opt** - Contents of @Cocoon value for this param.
* **param_req** - Contents of @Cocoon value for this param.
* **sess_opt** - Contents of @Cocoon value for this param.
* **sess_req** - Contents of @Cocoon value for this param.
* **post_opt** - Contents of @Cocoon value for this param.
* **post_req** - Contents of @Cocoon value for this param.
* **get_opt** - Contents of @Cocoon value for this param.
* **get_req** - Contents of @Cocoon value for this param.
* **file_opt** - Contents of @Cocoon value for this param.
* **file_req** - Contents of @Cocoon value for this param.
* **files** - Contents of @Cocoon value for this param.


# monarch functions
Monarch functions provide handy success failed responses. If the standard response format isn't flexible enough, you can create your own using util.raw()

```python
from caterpillar_api import Cocoon, monarch
```

## monarch.succ
A successful response. 'successful' = true is added to the response and then an HttpResponse is generated.

* request - The request variable passed by Django.
* response - A dict key/value pair.

```python
return { 'key': 'value' } # Return success
return monarch.succ( request, { 'key': 'value' })
```

## monarch.fail
A fail response. 'successful' = false is added to the response and then an HttpResponse is generated.

* request - The request variable passed by Django.
* reason - A string "reason" why the error occurred.
* code="" - An optional error code.
* extra={} - A dict of any other information that should be passed.

```python
return "Invalid access" # Return error message
return monarch.fail( request, "Invalid access", code="ERR_CODE_A")
return monarch.fail( request, "Invalid access", extra={'info': 'data'})
```

## util.raw
util.raw provides HttpResponse logic monarch.succ and monarch.fail use to communicate with Django. This function should only be used in exceptional cases.

* objs - String of response.
* status - Status code
* content - content_type of response
* callback=None - Optional JSON-P support

```python
return util.raw( '{"key": 8}', 200, content='application/json' )
```

# JSON-P support?
Yes. Caterpillar provides JSON-P support out of the box by passing a GET variable callback=xxx. If the callback is passed as POST or cannot use the name 'callback' to pass the callback name, a custom resp/err function set should be created.

```python
# http://xxx.com/endpoint?callback=ham_eggs
# Yields a response with JSON-P
ham_eggs( {"key": 917 })
```

# Common errors
No one likes bugs in their code, but Caterpillars are bugs and sometimes it encounters other bugs.

## TypeError: xxx() got an unexpected keyword argument 'xxx'
Caterpillar works by injecting named variables directly into functions. If the variable name doesn't exist in the paramaters of the function, you'll see a TypeError.

```python
@Cocoon( post_req=(
            ('a', int),
            ('b', int),
))
def add( request, a ): # TypeError Missing variable 'b'
    return monarch.succ( request, { "c": a })
```

There are two possible solutions. Add all variables or add **kwargs at the end of your parameters.
```python
# Solution of adding all variables
@Cocoon( post_req=(
            ('a', int),
            ('b', int),
))
def add( request, a, b):
    return monarch.succ( request, { "c": a + b })

# Solution adding **kwargs
@Cocoon( post_req=(
            ('a', int),
            ('b', int),
))
def add( request, a, **kwargs ):
    return monarch.succ( request, { "c": a + kwargs['b'] })
```

### {"successful": false, "reason": "Missing required argument(s): GET[] POST['b'] SESS[] FILE[]", "code": ""}
If required parameters are missing, the endpoint will not be called. A message similar to the above will be sent instead. Caterpillar attempts to provide detailed information for any GET / POST / SESS / FILE data that is required and missing.

# Testing
Caterpillar has limited testing support. Please see the contribution section to get involved.

# Contribute
If you love Caterpillar as much as we do, there are lots of ways to get involved.

## Self documenting reports

Caterpiller could use reflections to generated API reports. If you're interested in giving Caterpillar it's documentation butterfly wings, please contact us.

## Extended type checking for dict arguments

When passing a 'dict' argument type to Cocoon, there needs to be the ability to enforce an expectation of structure.

## Client libraries for all the major libraries

Love Angular? Flutter? Vue? Bootstrap? Android? IOS? Caterpillar needs native client libraries for them all.

## Website or graphic design?

We'd love to have a real website. If you want to help give Caterpillar a personality, please contact us.

## Maybe it's something really cool we don't even know about

Do you have ideas for new awesome features? Please contact lukedupin about becoming a contributer.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lukedupin/caterpillar",
    "name": "caterpillar-api",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "DJANGO,API,REST,JSON,JSONP,JSON-P",
    "author": "Luke Dupin",
    "author_email": "lukedupin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/be/11/2bee1adac839338ad01ed85d11ba4c2d3a2d4b2c839a26992cfb4550390d/caterpillar_api-1.62.tar.gz",
    "platform": null,
    "description": "# Caterpillar\n\nA light-weight, fast and scalable api solution for Django. Uses a comfy set of functionality that isn't boilerplatey or opinionated.\n\nDon't disregard Caterpillar because it's cute, it's scrapy to; with built in type conversion, session management, dead simple file handling, self documenting reports and error management. Caterpillar makes writing APIs fun.\n\n# Install Caterpillar\n\n```bash\npip3 install caterpillar-api\n```\n\n### Define your API\n\nInside your django project, create a function with a *@Cocoon* wrapper that defines your paramaters.\n\n```python\nfrom caterpillar_api import Cocoon, monarch\n\n@Cocoon( param_req=(\n            ('a', int),\n            ('b', int),\n))\ndef add( request, a, b ):\n    return { \"c\": a + b }\n```\n\n### Add your endpoint to Django\n\nInside url.py.\n\n```python\nurlpatterns = [\n    path('add/', views.add),\n    ...\n]\n```\n\n### Test out your API\n\nNow using curl, you can post data to the API and get a JSON response.\n\n```bash\ncurl -d \"a=17&b=35\" -X POST http://127.0.0.1:8000/add/; echo\n{\"c\": 52, \"successful\": true}\n```\n\n# Why Caterpillar?\n\n* Minimum boiler-plate\n* Readable syntax\n* Crazy fast\n* Easy to use\n* Unopnionated\n\n# Client libraries\nCaterpillar doesn't leave you hanging. We have an ever growing list of client libraries to speed up your development efforts. Although you don't need a custom client side library, it sure does feel good using one.\n\n* React fetch_js\n* Qt C++/QML interface\n\n# Recipes\n\n## Required POST arguments\npost_req takes a tuple of tuples. The tuple entries define (variable name, python type). You can trust the parameter will be the expected type. If a parameter is missing from a post_req, Caterpillar will respond with an error before the endpoint is called.\n\n\n```python\n@Cocoon( post_req=(\n            ('name', str),\n            ('age', int),\n))\ndef add_user( request, name, age ):\n    usr = User.objects.create( name=name, age=age )\n    return { 'id': usr.id }\n```\n\n## Optional POST arguments\npost_opt uses the same format as post_req. Fields can exist or not. If a field isn't present, the default paramater value or None is used.\n\n```python\n@Cocoon(\n    post_req=(\n            ('uid', str),\n    ),\n    post_opt=(\n        ('name', str),\n        ('age', int),\n        ('type', str, 'ADMIN'),\n    )\n)\ndef modify_user( request, uid, name, age, type ):\n    usr = User.objects.get(uid=uid)\n    if name is not None:\n        usr.name = name\n    if age is not None:\n        usr.age = age\n    usr.type = type\n    usr.save()\n    \n    return monarch.succ( request, {})\n```\n\n## Optional POST using kwargs\npost_opt argument checking using if statements does work, but it's a little ugly. It also creates a lot of code. The same operation can be done with kwargs.\n\n```python\n@Cocoon(\n    post_req=(\n            ('uid', str),\n    ),\n    post_opt=(\n            ('name', str),\n            ('age', int),\n            ('type', str, 'ADMIN'),\n    )\n)\ndef modify_user( request, uid, **kwargs ):\n    usr = User.objects.get(uid=uid)\n\n    for key in ('name', 'age', 'type'):\n        if kwargs[key] is not None:\n            usr.__setattr__( key, kwargs[key] )\n    usr.save()\n\n    return monarch.succ( request, {})\n```\n\n## Meta data\n@Coccon can provide meta data as an argument. This is handy because it can further reduce duplicate logic. Parameters are defined in one place only. Take the above example, now using meta data.\n\n```python\n@Cocoon(\n    post_req=(\n            ('uid', str),\n    ),\n    post_opt=(\n            ('name', str),\n            ('age', int),\n            ('type', str),\n    ),\n    meta=\"meta\"\n)\ndef modify_user( request, uid, meta, **kwargs ):\n    usr = User.objects.get(uid=uid)\n\n    for key, _ in meta.post_opt:\n        if kwargs[key] is not None:\n            usr.__setattr__( key, kwargs[key] )\n    usr.save()\n\n    return monarch.succ( request, {})\n```\n\n## Authenticate user and check login status\nCaterpillar also helps you work with session information. Session data can be used to authenticate a user and confirm their login state.\n\n```python\nfrom django.forms import model_to_dict\n\n@Cocoon( param_req=(\n            ('uid', str),\n            ('password', str),\n))\ndef login( request, uid, password ):\n    if (usr := getByUid(User, uid)) is None:\n        return \"Couldn't find user\"\n\n    if usr.password != password:\n        return \"Invalid password\"\n\n    # Store the user's info into the session, this effectively logs the user in\n    request.session['usr'] = model_to_dict(usr)\n    return {}\n\n\n@Cocoon(\n    sess_req=[('usr', dict)]\n)\ndef logout( request, usr ):\n    del request.session['usr']\n    return monarch.succ( request, {})\n\n\n# sess_req['usr'] will only allow this endpoint to be called by users that are logged in\n@Cocoon(\n    sess_req=[('usr', dict)]\n)\ndef user_details( request, usr ):\n    usr = getByUid(User, usr['uid'])\n    return monarch.succ( request, model_to_dict(usr))\n```\n\nIf optional session checking is required, you can always use sess_opt\n\n```python\n@Cocoon(\n    sess_opt=[('usr', dict)]\n)\ndef is_online( request, usr ):\n    return monarch.succ( request, { 'online': usr is not None })\n```\n\n## GET data from the URL\nThe same way POST can have required and optional arguments, GET variables can be accessed with @Cocoon.\n\n```python\n@Cocoon(\n    get_req=[('video_code', str)]\n)\ndef get_video( request, usr, video_code ):\n    #http://server.com/?video_code=XXX\n    print(video_code) # Prints XXX\n    return monarch.succ( request, {'video_info': 'info'})\n```\n\n## Read a file\nCaterpillar seamlessly handles file uploads as parameters. Files, like GET/POST, can be required or optional. The contents of the uploaded file can be read by calling .data(). If a hash of the data is required .hash() will return a sha256 hash.\n\n```python\n@Cocoon(\n    sess_req=[('usr', dict)],\n    file_req=[\"logo\"]\n)\ndef upload_logo( request, usr, logo ):\n    if not s3.put_data(logo.data(), usr['uid']):\n        return monarch.fail( request, \"Couldn't upload to S3\")\n\n    return monarch.succ( request, {})\n```\n\n## Need to call an endpoint directly?\nNot a problem; Caterpillar will happily get out of your way. Passing None for the request parameter will tell Caterpillar you are using the functions directly. Instead of a HttpResponse, you'll get the dict of the response.\n\n```python\n@Cocoon(\n    post_req=(\n            ('a', int),\n            ('b', int),\n    )\n)\ndef add( request, a, b ):\n    return monarch.succ( request, { \"c\": a + b })\n\nadd( None, 4, 3) # Returns { \"c\": 12 }\nadd( None, \"cat\", \"fish\") # Returns { \"c\": \"catfish\" } # Type checking isn't done when calling directly\n```\n\n## Where are PUT and DELETE?\nThey didn't make the cut. PUT and DELETE don't add any new functionality over update and remove endpoints. PUT/DELETE aren't fundimental to Django and since Caterpillar aims to be as lightweight as possible, this feature is out of scope.\n\n# @Cocoon\n\nCocoon is a function decorator that defines endpoint arguments and data types. \n\n* **sess_opt** - Optional session parameters. Array/Tuple of tuples. ('name', type) or ('name', type, default)\n* **sess_req** - Required session parameters. Array/Tuple of tuples. ('name', type).\n* **param_opt** - Optional POST/GET parameters. Array/Tuple of tuples. ('name', type) or ('name', type, default).\n* **param_req** - Required POST/GET parameters. Array/Tuple of tuples. ('name', type).\n* **post_opt** - Optional POST parameters. Array/Tuple of tuples. ('name', type) or ('name', type, default).\n* **post_req** - Required POST parameters. Array/Tuple of tuples. ('name', type).\n* **get_opt** - Optional GET parameters. Array/Tuple of tuples. ('name', type) or ('name', type, default).\n* **get_req** - Required GET parameters. Array/Tuple of tuples. ('name', type).\n* **file_opt** - Optional file parameters. Returns the ApiFile object with helper functions data() and hash() Array/Tuple of names. ('name').\n* **file_req** - Required file parameters. Returns the ApiFile object with helper functions data() and hash() Array/Tuple of names. ('name').\n* **files** - 'name' which recieves an array of Apifile classes. Handy for uploading arrays of unnamed filess.\n* **meta** - 'name' which recieves a CaterpillarMeta object. All of the Cocoon parameters are represented along with an 'args' dictionary which holds all data passed to this endpoint.\n\n### @Cocoon Types\n\n* str\n* int\n* float\n* bool - Can take true/false strings or true/false values or ints, 0 !0\n* dict - A dictionary of key value pairs. JSON\n* list - An array of parameters. Can take a string of delenated elements.\n\n### CaterpillarMeta class\n* **name** - The name of the variable.\n* **args** - dict of all posted data.\n* **param_opt** - Contents of @Cocoon value for this param.\n* **param_req** - Contents of @Cocoon value for this param.\n* **sess_opt** - Contents of @Cocoon value for this param.\n* **sess_req** - Contents of @Cocoon value for this param.\n* **post_opt** - Contents of @Cocoon value for this param.\n* **post_req** - Contents of @Cocoon value for this param.\n* **get_opt** - Contents of @Cocoon value for this param.\n* **get_req** - Contents of @Cocoon value for this param.\n* **file_opt** - Contents of @Cocoon value for this param.\n* **file_req** - Contents of @Cocoon value for this param.\n* **files** - Contents of @Cocoon value for this param.\n\n\n# monarch functions\nMonarch functions provide handy success failed responses. If the standard response format isn't flexible enough, you can create your own using util.raw()\n\n```python\nfrom caterpillar_api import Cocoon, monarch\n```\n\n## monarch.succ\nA successful response. 'successful' = true is added to the response and then an HttpResponse is generated.\n\n* request - The request variable passed by Django.\n* response - A dict key/value pair.\n\n```python\nreturn { 'key': 'value' } # Return success\nreturn monarch.succ( request, { 'key': 'value' })\n```\n\n## monarch.fail\nA fail response. 'successful' = false is added to the response and then an HttpResponse is generated.\n\n* request - The request variable passed by Django.\n* reason - A string \"reason\" why the error occurred.\n* code=\"\" - An optional error code.\n* extra={} - A dict of any other information that should be passed.\n\n```python\nreturn \"Invalid access\" # Return error message\nreturn monarch.fail( request, \"Invalid access\", code=\"ERR_CODE_A\")\nreturn monarch.fail( request, \"Invalid access\", extra={'info': 'data'})\n```\n\n## util.raw\nutil.raw provides HttpResponse logic monarch.succ and monarch.fail use to communicate with Django. This function should only be used in exceptional cases.\n\n* objs - String of response.\n* status - Status code\n* content - content_type of response\n* callback=None - Optional JSON-P support\n\n```python\nreturn util.raw( '{\"key\": 8}', 200, content='application/json' )\n```\n\n# JSON-P support?\nYes. Caterpillar provides JSON-P support out of the box by passing a GET variable callback=xxx. If the callback is passed as POST or cannot use the name 'callback' to pass the callback name, a custom resp/err function set should be created.\n\n```python\n# http://xxx.com/endpoint?callback=ham_eggs\n# Yields a response with JSON-P\nham_eggs( {\"key\": 917 })\n```\n\n# Common errors\nNo one likes bugs in their code, but Caterpillars are bugs and sometimes it encounters other bugs.\n\n## TypeError: xxx() got an unexpected keyword argument 'xxx'\nCaterpillar works by injecting named variables directly into functions. If the variable name doesn't exist in the paramaters of the function, you'll see a TypeError.\n\n```python\n@Cocoon( post_req=(\n            ('a', int),\n            ('b', int),\n))\ndef add( request, a ): # TypeError Missing variable 'b'\n    return monarch.succ( request, { \"c\": a })\n```\n\nThere are two possible solutions. Add all variables or add **kwargs at the end of your parameters.\n```python\n# Solution of adding all variables\n@Cocoon( post_req=(\n            ('a', int),\n            ('b', int),\n))\ndef add( request, a, b):\n    return monarch.succ( request, { \"c\": a + b })\n\n# Solution adding **kwargs\n@Cocoon( post_req=(\n            ('a', int),\n            ('b', int),\n))\ndef add( request, a, **kwargs ):\n    return monarch.succ( request, { \"c\": a + kwargs['b'] })\n```\n\n### {\"successful\": false, \"reason\": \"Missing required argument(s): GET[] POST['b'] SESS[] FILE[]\", \"code\": \"\"}\nIf required parameters are missing, the endpoint will not be called. A message similar to the above will be sent instead. Caterpillar attempts to provide detailed information for any GET / POST / SESS / FILE data that is required and missing.\n\n# Testing\nCaterpillar has limited testing support. Please see the contribution section to get involved.\n\n# Contribute\nIf you love Caterpillar as much as we do, there are lots of ways to get involved.\n\n## Self documenting reports\n\nCaterpiller could use reflections to generated API reports. If you're interested in giving Caterpillar it's documentation butterfly wings, please contact us.\n\n## Extended type checking for dict arguments\n\nWhen passing a 'dict' argument type to Cocoon, there needs to be the ability to enforce an expectation of structure.\n\n## Client libraries for all the major libraries\n\nLove Angular? Flutter? Vue? Bootstrap? Android? IOS? Caterpillar needs native client libraries for them all.\n\n## Website or graphic design?\n\nWe'd love to have a real website. If you want to help give Caterpillar a personality, please contact us.\n\n## Maybe it's something really cool we don't even know about\n\nDo you have ideas for new awesome features? Please contact lukedupin about becoming a contributer.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\ud83d\udc1b Caterpillar Api, field management for Django without the boiler-plate.",
    "version": "1.62",
    "project_urls": {
        "Homepage": "https://github.com/lukedupin/caterpillar"
    },
    "split_keywords": [
        "django",
        "api",
        "rest",
        "json",
        "jsonp",
        "json-p"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d8f982f89a9e55e39f338dd8aa24936048a474b54a61de822c8da41f7adafbb4",
                "md5": "55b7ddb978f982e3ec43d2362730a64f",
                "sha256": "a155db699b671d5f4dade3320a2da3146961c666eff8b9932c2d9f87657c525a"
            },
            "downloads": -1,
            "filename": "caterpillar_api-1.62-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "55b7ddb978f982e3ec43d2362730a64f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11094,
            "upload_time": "2023-12-28T21:10:37",
            "upload_time_iso_8601": "2023-12-28T21:10:37.681306Z",
            "url": "https://files.pythonhosted.org/packages/d8/f9/82f89a9e55e39f338dd8aa24936048a474b54a61de822c8da41f7adafbb4/caterpillar_api-1.62-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be112bee1adac839338ad01ed85d11ba4c2d3a2d4b2c839a26992cfb4550390d",
                "md5": "4b88590750930f789d02b38090b9612f",
                "sha256": "f4d80be2f49cbe0afdbe956b3eff365d4aa4ae55282485f42f5fb87a6525ef1d"
            },
            "downloads": -1,
            "filename": "caterpillar_api-1.62.tar.gz",
            "has_sig": false,
            "md5_digest": "4b88590750930f789d02b38090b9612f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14814,
            "upload_time": "2023-12-28T21:10:40",
            "upload_time_iso_8601": "2023-12-28T21:10:40.087464Z",
            "url": "https://files.pythonhosted.org/packages/be/11/2bee1adac839338ad01ed85d11ba4c2d3a2d4b2c839a26992cfb4550390d/caterpillar_api-1.62.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-28 21:10:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lukedupin",
    "github_project": "caterpillar",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "caterpillar-api"
}
        
Elapsed time: 0.16238s