Skip to main content

NexusPHP API Client - A Python client for interacting with NexusPHP forum API

Project description

NexusPHP API Client

NexusPHP API Client - A Python client for interacting with NexusPHP forum API.

PyPI Version Python Versions License

Project Structure

nexusphp_api/
├── api/                 # API data models
│   ├── bookmark/        # Bookmark related
│   ├── comment/         # Comment related
│   ├── section/         # Section related
│   ├── torrent/         # Torrent related
│   └── user/            # User related
├── api_client/          # API client implementation
├── config/              # Configuration management
├── utils/               # Utility functions
├── tests/               # Test code
├── doc/                 # API documentation
├── pyproject.toml       # PEP 517/518 build configuration
├── setup.cfg            # Package metadata and configuration
└── requirements.txt     # Project dependencies

Features

1. Bookmark Management

  • Add bookmark
  • Delete bookmark

2. Comment Management

  • Get comment list

3. Section Management

  • Get section information

4. Torrent Management

  • Get torrent list
  • Get torrent detail
  • Upload torrent

5. User Management

  • Get user profile

Installation

Install from PyPI (Recommended)

pip install nexusphp-api

Install from Source

git clone https://github.com/nexusphp/nexusphp-api.git
cd nexusphp-api
pip install -e .

Install Development Dependencies

pip install -r requirements.txt

Quick Start

Basic Usage

from nexusphp_api import NexusAPIClient

# Initialize client
client = NexusAPIClient(
    base_url="https://dev.nexusphp.org",
    token="your-api-token"
)

# Get current user profile
profile = client.profile.get_profile()
print(f"User: {profile.data.data.username}")

# Add bookmark
bookmark = client.bookmark.add_bookmark(torrent_id=123)
print(f"Bookmark status: {bookmark.msg}")

# Delete bookmark
result = client.bookmark.delete_bookmark(torrent_id=123)
print(f"Delete result: {result.msg}")

Dynamic Configuration Update

# Update token
client.set_token("new-token")

# Update base_url
client.set_base_url("https://api.example.com")

Configuration

The project supports configuration via environment variables:

Environment Variable Default Value Description
API_BASE_URL https://api.nexusphp.org API base URL
API_TIMEOUT 30 API request timeout (seconds)
API_TOKEN "" Authentication token
LOG_LEVEL INFO Log level
LOG_FILE api.log Log file
MAX_RETRIES 3 Maximum retry count
RETRY_INTERVAL 1.0 Retry interval (seconds)

API Reference

NexusAPIClient Main Class

from nexusphp_api import NexusAPIClient

# Initialize
client = NexusAPIClient(
    base_url="https://dev.nexusphp.org",  # Optional, default value
    token="your-token"                    # Optional
)

# Sub-clients
client.profile        # User profile
client.bookmark       # Bookmark management
client.comment        # Comment management
client.section        # Section management
client.torrent        # Torrent management

Available Client Methods

ProfileClient (User Profile)

  • get_profile(user_id=None, includes=None, include_fields=None)

BookmarkClient (Bookmark)

  • add_bookmark(torrent_id)
  • delete_bookmark(torrent_id)

CommentClient (Comment)

  • See code and documentation

SectionClient (Section)

  • See code and documentation

TorrentClient (Torrent)

  • See code and documentation

Running Tests

Run All Tests

pytest tests/

Run Specific Tests

pytest tests/test_api_client.py

Run Tests with Coverage

pytest tests/ --cov=nexusphp_api --cov-report=html

Run with unittest

python -m unittest discover tests

Code Quality

The project is configured with the following code quality tools:

Format Code

black .
isort .

Lint Code

flake8 .

Type Check

mypy .

Response Format

All API responses follow this format:

{
  "ret": 0,          // Result code, 0 means success, other means failure
  "msg": "success",  // Text message
  "data": {},        // Response data
  "rid": "uuid",     // Request ID
  "time": 0.123      // Response time (seconds)
}

Utility Functions

The project provides the following utility functions for data conversion and processing:

  • from_str - String conversion
  • from_int - Integer conversion
  • from_int_optional - Optional integer conversion
  • from_float - Float conversion
  • from_bool - Boolean conversion
  • from_none - None conversion
  • from_union - Union type conversion
  • from_list - List conversion
  • from_dict - Dict conversion
  • to_float - Float output conversion
  • to_class - Class instance conversion
  • to_enum - Enum conversion

Development and Contribution

Local Development

  1. Fork the project repository
  2. Clone to local
  3. Install development dependencies
  4. Create feature branch
  5. Commit changes
  6. Push to branch
  7. Create Pull Request

Build and Release

# Build package
python -m build

# Release to PyPI
twine upload dist/*

Notes

  1. Make sure you have a valid API token before use
  2. Respect API rate limits
  3. Check the ret field when processing API responses to confirm success
  4. Network requests will automatically retry (default 3 times)

License

MIT License

Support and Contact

For issues or suggestions, please:

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

nexusphp_api-0.1.2.tar.gz (42.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nexusphp_api-0.1.2-py3-none-any.whl (54.3 kB view details)

Uploaded Python 3

File details

Details for the file nexusphp_api-0.1.2.tar.gz.

File metadata

  • Download URL: nexusphp_api-0.1.2.tar.gz
  • Upload date:
  • Size: 42.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for nexusphp_api-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1106806f135e5656a1e2ca05f4e50dd069e96bbd031c9ff6e6a4876f0840b9ac
MD5 8f93f565324ac6c5fc24378c9be8fad2
BLAKE2b-256 153f8031e42885d0f8c7a7a14d3047854d8075098445e591110bcfc9a1dc8bfc

See more details on using hashes here.

File details

Details for the file nexusphp_api-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nexusphp_api-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 54.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for nexusphp_api-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dfcee4daaeba533b31550d7dcc1ea1367205d16f711256f57bc0fa332b20a717
MD5 b81ad6b7daacc6da3eccdce145cd6b39
BLAKE2b-256 bc1e09c380f1a3bb16b2814606b5dcb8aff17fc2621f8e7a206039aa14396c4a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page