How liluo/douban-client works
Project type and purpose
• This is a Python library (douban-client) that wraps the Douban API v2, providing:
• OAuth 2.0 authentication (code, password, token flows)
• A uniform interface over all resource endpoints (user, book, movie, music, album, photo, note, discussion, event, online, doumail, miniblog, etc.)
• Automatic JSON handling, error mapping, token refresh
• It is not a full‑stack application or microservice, but an SDK / client library designed for easy integration into other Python applications.
File structure
• Top‑level:
• douban_client/ – the library package
• client.py – main entrypoint (DoubanClient)
• api/ – one module per resource, plus:
• base.py – BaseAPI class for common HTTP logic
• error.py – exception definitions
• __init__.py – imports and version
• examples/ – three example scripts showing different auth flows
• tests/ – >90% coverage, exercising each API module via a test framework and mock server
• requirements.txt / setup.py – packaging and installation
• Architectural hints:
• Single‑process, pure‑Python
• Follows a “one resource = one module/class” pattern
• Delegates all HTTP communication and authentication management to client.py and base.py
Key insights from README
• The library’s purpose is to simplify calls to Douban REST endpoints under OAuth2
• Lists every supported endpoint by resource (user, note, album, etc.)
• Emphasizes JSON transport, standard paging (start/count), error handling via HTTP codes
• Examples focus on obtaining tokens and then calling client.<resource>.<action>(…)
Final Recommendations
1. authorize_url request/response
2. Token exchange & refresh
3. Resource method HTTP calls
4. Error/exception propagation
• Library internals
• External API
• Consumer code