Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.5 #42

Merged
merged 40 commits into from
Oct 19, 2024
Merged

v0.5 #42

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d3224f0
implement #29
lubaskinc0de Dec 21, 2023
0f9ad40
fixes
lubaskinc0de Dec 21, 2023
a4bc4a4
remove isinstance str checking
lubaskinc0de Dec 21, 2023
a8c097d
remove isinstance str checking again
lubaskinc0de Dec 21, 2023
b589ed1
split parsing and execution logic, add support for kwonly args, fix s…
lubaskinc0de Dec 22, 2023
cf88226
remove unused getfullargspec call
lubaskinc0de Dec 22, 2023
6c68a08
remove unused method spec attrs
lubaskinc0de Dec 22, 2023
6f2b4b3
remove unused get_url_params func, add get_url_params_from_string fun…
lubaskinc0de Jan 6, 2024
5f4fcd7
some refactoring
lubaskinc0de Jan 6, 2024
bcb3da4
fix test
Tishka17 May 17, 2024
f951c3e
github actions
Tishka17 May 17, 2024
5540d77
Fix typo
KurosawaAngel May 17, 2024
7441163
test params and factory
Tishka17 May 17, 2024
baf55c9
fix reqs file name, remove travis
Tishka17 May 17, 2024
c313806
Merge pull request #36 from KuroKoka551/master
Tishka17 May 17, 2024
39b4851
more strict matching
Tishka17 May 17, 2024
ca0d325
Merge pull request #35 from reagento/feature/tests
Tishka17 May 17, 2024
87a6f0f
hints in readme
Tishka17 May 21, 2024
5962628
fix type hints
chessenjoyer17 Jul 6, 2024
e571d3e
3.6+ version support
chessenjoyer17 Jul 25, 2024
448746d
Merge pull request #37 from Dark04072006/develop
Tishka17 Jul 27, 2024
f18df29
pyproject.toml, ruff
Tishka17 Jul 27, 2024
ee5d277
py.typed
Tishka17 Jul 27, 2024
600fa86
Merge branch 'develop' into refactor/setup_ci
Tishka17 Jul 27, 2024
508ccf1
more strict ruff rules
Tishka17 Jul 27, 2024
92c7203
Merge pull request #38 from reagento/refactor/setup_ci
Tishka17 Jul 27, 2024
9ede5ad
Merge branch 'reagento:master' into master
lubaskinc0de Jul 28, 2024
98b2540
move to src
lubaskinc0de Jul 28, 2024
faffe2a
merging
lubaskinc0de Jul 28, 2024
d8ca305
refactoring
lubaskinc0de Jul 29, 2024
3e0be5f
inline
lubaskinc0de Jul 29, 2024
c9b6654
tests, docs
lubaskinc0de Jul 29, 2024
b3510bb
Merge pull request #30 from lubaskinc0de/master
Tishka17 Jul 29, 2024
cc151e3
Add headers to request model
Tishka17 Aug 2, 2024
9bb5665
Merge pull request #40 from reagento/feature/headers
Tishka17 Aug 5, 2024
0919273
fix kwonlyargs
KurosawaAngel Oct 8, 2024
14574eb
add test
KurosawaAngel Oct 8, 2024
9318492
Merge pull request #41 from KurosawaAngel/patch-1
Tishka17 Oct 10, 2024
78e98eb
Run ci on 3.13
Tishka17 Oct 19, 2024
692cc27
Merge pull request #43 from reagento/feature/3.13
Tishka17 Oct 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: CI

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

jobs:
cpython:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"

steps:
- uses: actions/checkout@v4
- name: Set up ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install '.' -r requirements_dev.txt

- name: Run ruff
run: |
ruff check .

- name: Run tests
run: |
pytest
42 changes: 42 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
line-length = 79
target-version="py38"
src = ["src"]

include = ["src/**.py", "tests/**.py"]
exclude = ["src/dishka/_adaptix/**"]

lint.select = [
"ALL"
]
lint.ignore = [
"ARG",
"ANN",
"D",
"EM101",
"EM102",
"PT001",
"PT023",
"SIM108",
"SIM114",
"TRY003",
"PLW2901",
"RET505",
"RET506",
"PLR0913",
"UP038",
"TCH001",
"FA100",
# tempraty disabled
"PGH005",
"PLR2004",
"N818", # compatibility issue
]

[lint.per-file-ignores]
"tests/**" = ["TID252", "PLR2004", "S101", "A002"]

[lint.isort]
no-lines-before = ["local-folder"]

[lint.flake8-tidy-imports]
ban-relative-imports = "parents"
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

64 changes: 63 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,32 @@ class RealClient(RequestsClient):

@post("todos")
def create_todo(self, body: Todo) -> Todo:
"""Создаем Todo"""
pass
```

You can use Callable ```(...) -> str``` as the url source,
all parameters passed to the client method can be obtained inside the Callable

```python
from requests import Session
from dataclass_rest import get
from dataclass_rest.http.requests import RequestsClient

def url_generator(todo_id: int) -> str:
return f"/todos/{todo_id}/"


class RealClient(RequestsClient):
def __init__(self):
super().__init__("https://dummyjson.com/", Session())

@get(url_generator)
def todo(self, todo_id: int) -> Todo:
pass


client = RealClient()
client.todo(5)
```

## Asyncio
Expand Down Expand Up @@ -102,3 +127,40 @@ To set same behavior for all methods inherit from BoundMethod class, override `_
### Other params

You can use different body argument name if you want. Just pass `body_name` to the decorator.


### Special cases

#### `None` in query params

By default, AioHTTP doesn't skip query params, you can customize that overriding `_pre_process_request` in Method class

```python
class NoneAwareAiohttpMethod(AiohttpMethod):
async def _pre_process_request(self, request: HttpRequest) -> HttpRequest:
request.query_params = {
k: v for k, v in request.query_params.items() if v is not None
}
return request


class Client(AiohttpClient):
method_class = NoneAwareAiohttpMethod
```

#### Handling `No content`

By default, en each method json response is expected. Sometime you expect no content from server. Especially for 204.
You can handle it by overriding `_response_body` method, e.g.:

```python
class NoneAwareRequestsMethod(RequestsMethod):
def _response_body(self, response: Response) -> Any:
if response.status_code == http.HTTPStatus.NO_CONTENT:
return None
return super()._response_body(response)


class Client(RequestsClient):
method_class = NoneAwareRequestsMethod
```
8 changes: 0 additions & 8 deletions dataclass_rest/__init__.py

This file was deleted.

39 changes: 0 additions & 39 deletions dataclass_rest/rest.py

This file was deleted.

4 changes: 2 additions & 2 deletions examples/async_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ async def delete_todo(self, id: int):

@post("todos")
async def create_todo(self, body: Todo) -> Todo:
"""Созадем Todo"""
"""Создаем Todo"""

@get("https://httpbin.org/get")
def get_httpbin(self) -> Any:
"""Используемый другой base_url"""
"""Используем другой base_url"""

@post("https://httpbin.org/post")
def upload_image(self, file: File):
Expand Down
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[build-system]
requires = ["setuptools>=66.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
where = ["src"]

[project]
name = "dataclass_rest"
version = "0.4"
readme = "README.md"
authors = [
{ name = "Andrey Tikhonov", email = "[email protected]" },
]
license = { text = "Apache-2.0" }
description = "An utility for writing simple clients for REST like APIs"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries",
"Typing :: Typed",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
]
dependencies = [
"adaptix",
]

[project.urls]
"Source" = "https://github.com/reagento/dataclass-rest"
"Homepage" = "https://github.com/reagento/dataclass-rest"
"Bug Tracker" = "https://github.com/reagento/dataclass-rest/issues"


6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

10 changes: 10 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
adaptix
typing_extensions
aiohttp
requests
requests-mock
mypy
pytest
pytest-asyncio

ruff==0.5.*
37 changes: 0 additions & 37 deletions setup.py

This file was deleted.

12 changes: 12 additions & 0 deletions src/dataclass_rest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
__all__ = [
"File",
"rest",
"get",
"put",
"post",
"patch",
"delete",
]

from .http_request import File
from .rest import delete, get, patch, post, put, rest
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from adaptix import Retort

from .client_protocol import (
ClientProtocol, FactoryProtocol,
ClientProtocol,
FactoryProtocol,
)


Expand Down
Loading