Declarative Python HTTP Client, inspired by the OpenFeign java project
Project description
PyFeign - Declarative REST Client
Python implementation of Feign.
Installation
pip install pyfeign
# or
poetry install pyfeign
Usage
Decorate function with appropriate pyfeign.$method decorator:
@pyfeign.get(url='http://localhost/{id}')
def get_by_id(id: str = Path()) -> Dict[str, Any]:
"""
Get by ID
"""
obj_dict = get_by_id('id123')
Parameters
-
Path - Argument should be used as a path template variable. Reserved variable names can be used using the
nameparameter:@pyfeign.get(url='http://localhost/{id}') def get_by_id(id_val: str = Path(name='id')) -> Dict[str, Any]: """ Get by ID """
-
Query - Argument should be used as a query parameter, and can be optionally set with a default value if not provided
@pyfeign.get(url='http://localhost/{id}') def get_by_id(id_val: str = Path, summary: bool = Query(default=False, name='summary_details')) -> Dict[str, Any]: """ Get by ID get_byt_id('id1', False) == http://localhost/id1?summary_details=False """
-
Header - Argument will be used as an HTTP Header
-
Cookie - Argument will be used as an HTTP Cookie
-
Body - Argument will be sent as the request body (JSON serialized)
Classes
@pyfeign.Pyfeign(config=Config(base_url='https://postman-echo.com'))
class PostmanEcho:
@pyfeign.get('/get')
def get(self, foo1: str = Query(), foo2: str = Query(default='bar2')) -> Dict[str, Any]:
pass
Responses
If the response function / method is typed with Dict or List, then the response json will be parsed and returned.
If return type is str then the response text will be returned
For either of these responses, the return code is asserted via Response.raise_for_status(), and so an HTTPError will
be raised accordingly
Otherwise the full requests.Response object is returned.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfeign-0.1.2.tar.gz.
File metadata
- Download URL: pyfeign-0.1.2.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-58-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
518e1a4c0e162b29efe7541ce0d0439b2cfef58281535cc513df49cdc5eb1370
|
|
| MD5 |
ec6c3fcf25c6ce352117ec66094e4538
|
|
| BLAKE2b-256 |
2684959bc6cb888116dfe20ecc8d7400fedf5dc03cabbd9c302162324a7bdc68
|
File details
Details for the file pyfeign-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pyfeign-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-58-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03ff92a741c2171f7faab6ef9b48877833c895364c457fe24bbc5bfe32c1dbb1
|
|
| MD5 |
9eded3a7d4523d0ea980d99ea120ef6b
|
|
| BLAKE2b-256 |
5f1166363706be92e90e3f23fcbaaafc05341824297a6cd0c1a7955ee2ff2a33
|