Grit requester client for Python
Project description
grit-requester
grit-requester-python is a python library to abstract requests to microservices built using Grit.
Features:
- 🔁 Automatic retry on
401 Unauthorized - 🔐 Per-service token cache with concurrency safety
- 💉 Config and HTTP client injection (perfect for testing)
- 📦 Full support for generics (
any) in request/response - 🧠 Context-aware: all requests support context.Context for cancellation, timeouts, and APM tracing
✨ Installation
pip install grit_requester
🚀 Usage Example
Configure and do a request
from grit_requester import GritService, GritConfig
# configure grit requester
config = GritConfig(
base_url=os.getenv("SERVICE_BASE_URL"),
auth_url=os.getenv("SERVICE_AUTH_URL"),
token=os.getenv("SERVICE_TOKEN"),
secret=os.getenv("SERVICE_SECRET"),
context=os.getenv("SERVICE_CONTEXT"),
)
ms = GritService(config)
# doing a request
resp = ms.request(
"GET",
"/user/list",
)
Make crud requests from a domain
Here you can call a domain passing the type and path to access the following base routers:
| Path | Description |
|---|---|
| add | Create a new record |
| bulk | Fetch specific records by IDs |
| bulk_add | Create up to 25 records in the same request |
| dead_detail | Get a deleted record by ID |
| dead_list | List deleted records (paginated) |
| delete | Soft-delete a record by ID |
| detail | Get an active record by ID |
| edit | Update specific fields |
| list | List active records (paginated) |
| list_one | List one record based on params |
| select_raw | Execute a predefined raw SQL query safely |
from grit_requester import GritService, GritConfig
# configure grit requester
config = GritConfig(
base_url=os.getenv("SERVICE_BASE_URL"),
auth_url=os.getenv("SERVICE_AUTH_URL"),
token=os.getenv("SERVICE_TOKEN"),
secret=os.getenv("SERVICE_SECRET"),
context=os.getenv("SERVICE_CONTEXT"),
)
ms = GritService(config)
# make a request from domain
users = ms.domain("user").list_all(
filters=[{ "field": "name", "type": "eql", "value": "Admin" }]
)
# you can save the domain context to reuse
user_ms = ms.domain("user")
user = user_ms.detail(users[0]["id"])
🔧 License
MIT © Not Empty
Not Empty Foundation - Free codes, full minds
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
grit_requester-1.0.0.tar.gz
(5.4 kB
view details)
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 grit_requester-1.0.0.tar.gz.
File metadata
- Download URL: grit_requester-1.0.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ace28e82e4728c3374a80a16542b9fc3961ff52f219a7b771a00303e0cf9f984
|
|
| MD5 |
e2e3b3ca3feb7ece7ae10d9a08898513
|
|
| BLAKE2b-256 |
39fa9aa11d9b077d6173fb1905778d9f31d0ea5d4467c4ee2583f74dfa5c10ee
|
File details
Details for the file grit_requester-1.0.0-py3-none-any.whl.
File metadata
- Download URL: grit_requester-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a4a97d6272542a18084e664b5246f35f28ee4689d8ba1603066a2a374d90cf1
|
|
| MD5 |
e085e209af40f83845b195180beab67b
|
|
| BLAKE2b-256 |
7b7c04c68f169847eea3b774d3a2af456e5f668e76fbbf312fb86e4fc8227f31
|