Skip to content

Commit e6e28b1

Browse files
authored
Merge pull request #2 from birddevelper/docs
Docs
2 parents 03ab1e1 + 9e32291 commit e6e28b1

File tree

8 files changed

+97
-58
lines changed

8 files changed

+97
-58
lines changed

docs/source/API parameters.rst

-37
This file was deleted.

docs/source/API_parameters.rst

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
API Parameters
2+
===================
3+
4+
dequest provides `PathParameter`, `QueryParameter`, `FormParameter` and `JsonBody` to handle API parameters.
5+
6+
Path Parameters
7+
---------------
8+
9+
Use `PathParameter` to include values in the URL:
10+
11+
.. code-block:: python
12+
13+
from dequest import sync_client, PathParameter
14+
15+
@sync_client(url="https://api.example.com/users/{user_id}")
16+
def get_user(user_id: PathParameter[int]):
17+
pass
18+
19+
user = get_user(user_id=42)
20+
print(user)
21+
22+
Query Parameters
23+
----------------
24+
25+
Use `QueryParameter` to pass values as query parameters:
26+
27+
.. code-block:: python
28+
29+
from dequest import sync_client, QueryParameter
30+
31+
@sync_client(url="https://api.example.com/search")
32+
def search(keyword: QueryParameter[str, "q"]):
33+
pass
34+
35+
results = search(keyword="python")
36+
print(results)
37+
38+
39+
In endpoint function definitions, `QueryParameter`, `PathParameter`, `FormParameter`, and `JsonBody` parameters support two optional arguments:
40+
41+
1. **Type Hint (First Argument)**
42+
43+
You can provide a type hint (e.g., `str`, `int`, `bool`, etc.) as the first argument. This enables automatic type checking and validation before making the API call.
44+
45+
**Example:**
46+
47+
.. code-block:: python
48+
49+
keyword: QueryParameter[str]
50+
51+
This ensures that `keyword` must be a string when passed to the function.
52+
53+
2. **Mapping Name (Second Argument)**
54+
The second argument is an optional string that lets you map the Python parameter name to the actual API parameter name.
55+
56+
**Example:**
57+
58+
.. code-block:: python
59+
60+
keyword: QueryParameter[str, "q"]
61+
62+
This maps the `keyword` parameter in your function to the `q` query parameter in the API request.
63+
64+
These features help keep your code type-safe and aligned with external API schemas. Note that each of these arguments can be used alone.

docs/source/caching.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ To improve performance, `dequest` can cache responses.
99
def get_popular():
1010
pass
1111
12-
The response will be stored for 60 seconds, reducing API calls. It generates a cache_key by combining the URL, including the values of path parameters, with query parameters, ensuring that an API request with different query parameters is cached separately for each paramter set.
12+
The response will be stored for 60 seconds, reducing API calls. It generates a cache_key by combining the URL, including the values of path parameters, with query parameters, ensuring that an API request with different query parameters is cached separately for each paramter set.
13+
14+
15+
The cache featues supports `in_memory`, `redis`, and `django` cache that can be configured using `DequestConfig`.

docs/source/circuit_breaker.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ To use a circuit breaker with `dequest`, create an instance of `CircuitBreaker`
77

88
.. code-block:: python
99
10-
from dequest.clients import sync_client
11-
from dequest.circuit_breaker import CircuitBreaker
10+
from dequest import sync_client
11+
from dequest import CircuitBreaker
1212
1313
# Define a Circuit Breaker with failure threshold of 3 and recovery timeout of 10 seconds
1414
breaker = CircuitBreaker(failure_threshold=3, recovery_timeout=10)
@@ -22,8 +22,8 @@ Note The retry logic wraps the entire operation so that only if all attempts fai
2222

2323
.. code-block:: python
2424
25-
from dequest.clients import sync_client
26-
from dequest.circuit_breaker import CircuitBreaker
25+
from dequest import sync_client
26+
from dequest import CircuitBreaker
2727
2828
breaker = CircuitBreaker(failure_threshold=3, recovery_timeout=10)
2929
@@ -40,7 +40,7 @@ When the circuit breaker is open, calling the function will raise a `CircuitBrea
4040

4141
.. code-block:: python
4242
43-
from dequest.circuit_breaker import CircuitBreakerOpenError
43+
from dequest import CircuitBreakerOpenError
4444
4545
try:
4646
response = fetch_data()
@@ -57,7 +57,7 @@ For example, if the main API fails, we can return a cached response or default d
5757
.. code-block:: python
5858
5959
from dequest import sync_client
60-
from dequest.circuit_breaker import CircuitBreaker
60+
from dequest import CircuitBreaker
6161
6262
# Define a fallback function
6363
def fallback_response():

docs/source/conf.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
# -- Project information
44

5-
project = 'Lumache'
6-
copyright = '2021, Graziella'
7-
author = 'Graziella'
5+
project = 'Dequest'
6+
copyright = '2025, M.Shaeri'
7+
author = 'M.Shaeri'
88

9-
release = '0.1'
10-
version = '0.1.0'
9+
release = '0.2.0'
10+
version = '0.2.0'
1111

1212
# -- General configuration
1313

docs/source/config.rst

+14-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@ Cache Provider
88

99
.. code-block:: python
1010
11-
from dequest.config import DequestConfig
11+
from dequest import DequestConfig
1212
1313
DequestConfig.CACHE_PROVIDER = "redis" # Options: "in_memory", "redis" and "django"
1414
1515
Redis Configuration
1616
-------------------
1717
If you set "redis" as cache provider, you should set the redis server configuration also.
18+
1819
.. code-block:: python
1920
20-
DequestConfig.REDIS_HOST = "localhost"
21-
DequestConfig.REDIS_PORT = 6379
22-
DequestConfig.REDIS_PASSWORD = None
23-
DequestConfig.REDIS_SSL = False
21+
from dequest import DequestConfig
22+
23+
DequestConfig.config(
24+
cache_provider="redis", # defaults to "in_memory"
25+
redis_host="my-redis-server.com",
26+
redis_port=6380,
27+
redis_db=1,
28+
redis_password="securepassword",
29+
redis_ssl=True,
30+
)
31+
32+
Calling the `.config()` method is optional. You can use it during application initialization if you need to specify custom configurations instead of the defaults.

docs/source/index.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. Dequest Documentation
1+
Dequest Documentation
22
========================
33

44
Welcome to the documentation for `dequest`, a Python library for declarative HTTP requests. `dequest` provides powerful decorators for synchronous and asynchronous API calls, with built-in support for retries, caching, circuit breakers, and more.
@@ -7,12 +7,12 @@ Welcome to the documentation for `dequest`, a Python library for declarative HTT
77
:caption: Contents:
88

99
installation
10+
config
1011
sync_client
1112
async_client
1213
retry
13-
config
1414
caching
1515
circuit_breaker
16-
API parameters
16+
API_parameters
1717

1818

docs/source/retry.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Automatic Retries
1+
Retry
22
=================
33

44
If an API request fails due to network issues or server errors, `dequest` can automatically retry the request.

0 commit comments

Comments
 (0)