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
Built Distribution
File details
Details for the file tombulled_param-0.1.14.tar.gz
.
File metadata
- Download URL: tombulled_param-0.1.14.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.4.0-131-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e673165dd6514db2188cf71fa8ed016efc24148ab6ae943bd85d04177da1be9 |
|
MD5 | 7919bbbf7ffaeb675d27cab17201bfc2 |
|
BLAKE2b-256 | 2e378ee9c9d29dc00b11dd808ea5c1a7b74b4fb552f899e66359a3e81280e30f |
File details
Details for the file tombulled_param-0.1.14-py3-none-any.whl
.
File metadata
- Download URL: tombulled_param-0.1.14-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.10 Linux/5.4.0-131-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46d6abddc21304b9839ed4d034e67fac046eade78f7bbb789af99cd77f353e97 |
|
MD5 | 34060ce8b4dd0eb2501f4787f461373b |
|
BLAKE2b-256 | 96c417e9e2c5f0bfd482f2af5b4ffcaf76f821d9498342b466c755e200e3bc6b |