Enhanced function parameters
Project description
param
Enhanced function parameters
Installation
pip install git+https://github.com/tombulled/param.git@main
Usage
Functions
The @params
annotation works seamlessly with functions:
from param import Param, params
@params
def get(url: str, params: dict = Param(default_factory=dict)):
print("GET", url, params)
>>> get("https://httpbin.com/get")
GET https://httpbin.com/get {}
Classes
The @params
annotation also works seamlessly with classes. Importantly, the @params
annotation should be specified before @staticmethod
or @classmethod
.
from param import Param, params
class MyClass:
@params
def get(self, url: str, params: dict = Param(default_factory=dict)):
print("GET", url, params)
@classmethod
@params
def post(cls, url: str, params: dict = Param(default_factory=dict)):
print("POST", url, params)
@staticmethod
@params
def put(url: str, params: dict = Param(default_factory=dict)):
print("PUT", url, params)
>>> obj = MyClass()
>>>
>>> obj.get("https://httpbin.com/get")
GET https://httpbin.com/get {}
>>>
>>> obj.post("https://httpbin.com/post")
POST https://httpbin.com/post {}
>>> MyClass.post("https://httpbin.com/post")
POST https://httpbin.com/post {}
>>>
>>> obj.put("https://httpbin.com/put")
PUT https://httpbin.com/put {}
>>> MyClass.put("https://httpbin.com/put")
PUT https://httpbin.com/put {}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tombulled-param-0.1.13.tar.gz
(7.8 kB
view hashes)
Built Distribution
Close
Hashes for tombulled_param-0.1.13-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c18f9e40a6d41a0ccb5db5600ed759f3a9fe3b3802b6722bf3ff3e73de3c25e |
|
MD5 | 18176cf50b2c4ac739fc0e24b67a25a8 |
|
BLAKE2b-256 | 1b8289e7b35e8990680d5d8a265ccde2239416478622c6900ef67c8b1a687506 |