A modern Python library for the Plurk API 2.0, providing an easy-to-use interface for both synchronous and asynchronous interactions.
- Effortless Plurk API access with OAuth. (Code example)
- Full support for both synchronous and asynchronous API calls.
- Complete coverage of all API endpoints listed in the official documentation.
- A convenient helper function for subscribing to timeline updates. (Code example)
- Python 3.8+
pip3 install plurk.pyFollow these steps to get started with plurk.py.
If you don't have a Plurk app, create one on the App Sign Up page to get your app key and secret.
Create a .env file in your project's root directory and add your Plurk app's key and secret:
APP_KEY=<your-plurk-app-key>
APP_SECRET=<your-plurk-app-secret>A .env.example file is provided as a template.
Install the required libraries, including python-dotenv for managing environment variables:
pip3 install -r requirements.txtThe following example demonstrates how to authenticate and access the Plurk API using plurk.py:
import os
from dotenv import load_dotenv
from plurk import Client
load_dotenv()
APP_KEY = os.getenv('APP_KEY')
APP_SECRET = os.getenv('APP_SECRET')
with Client(APP_KEY, APP_SECRET) as client:
# Get app user's access token
request_token = client.get_request_token()
auth_url = client.get_auth_url(request_token)
print('Plurk OAuth authorization URL (open it with browser): ', auth_url)
auth_code = input('Please input the authorization code retrieved from authorization URL: ')
client.fetch_access_token(request_token, auth_code)
# Access Plurk API
user_data = client.users.me()
print('Display name: ', user_data.display_name)
print('Plurks created: ', user_data.plurks_count)For an asynchronous example, check the async example.
git clone [email protected]:shc261392/plurk.py.git
cd plurk.py
make installmake install will create a virtual environment in the .venv folder.
To run the test suite:
make testplurk.py relies on these excellent libraries:
- Authlib for OAuth, using a forked version.
- httpx for both synchronous and asynchronous HTTP requests.
- pydantic for data models with robust typing and validation.
- python-dotenv for managing environment variables.