Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tombulled/param
Enhanced function parameters
https://github.com/tombulled/param
param python
Last synced: 23 days ago
JSON representation
Enhanced function parameters
- Host: GitHub
- URL: https://github.com/tombulled/param
- Owner: tombulled
- License: mit
- Created: 2022-08-17T18:15:37.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-02T17:41:46.000Z (10 months ago)
- Last Synced: 2024-08-09T06:55:28.236Z (5 months ago)
- Topics: param, python
- Language: Python
- Homepage: https://pypi.org/project/tombulled-param/
- Size: 178 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# param
Enhanced function parameters## Installation
### PyPI
```console
pip install tombulled-param
```
### GitHub
```console
pip install git+https://github.com/tombulled/param.git@main
```## Usage
### Functions
The `@params` annotation works seamlessly with functions:
```python
from param import Param, params@params
def get(url: str, params: dict = Param(default_factory=dict)):
print("GET", url, params)
```
```python
>>> 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`.
```python
from param import Param, paramsclass 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)
```
```python
>>> 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 {}
```