Metadata-Version: 2.4
Name: python-backlog
Version: 0.9.0
Summary: Backlog API v2 wrapper
Author-email: hassaku63 <hassaku63@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/hassaku63/pbl
Project-URL: Source, https://github.com/hassaku63/pbl
Project-URL: Issues, https://github.com/hassaku63/pbl/issues
Keywords: nulab,backlog
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Natural Language :: Japanese
Classifier: Natural Language :: English
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: flake8>=7; extra == "dev"
Requires-Dist: coverage>=7.6; extra == "dev"
Dynamic: license-file

# pbl

A Python package that wraps the [Backlog API v2](https://developer.nulab.com/docs/backlog/).

- Requires Python 3.10 or later.
- No runtime dependencies: only the Python standard library is used.

## Usage

Install

```bash
pip install python-backlog
```

Code snippet

```python
import base64
import json
from backlog.base import BacklogAPI


def main():
    """
    Initialize API Object
    """
    # The API key is sent in the "Backlog-API-Key" request header.
    # Requests time out after 30 seconds by default (configurable with `timeout=`).
    api = BacklogAPI("your-space", "your-api-key")

    # Categories
    # https://developer.nulab.com/docs/backlog/api/2/get-category-list/
    print(api.category.list("SampleProject"))

    """
    Project API
    """
    # list project users
    # https://developer.nulab.com/docs/backlog/api/2/get-project-list/
    print("# list project users")
    users = api.project.list_users("SampleProject")
    print(json.dumps(users, indent=2))


    """
    Wiki API
    """
    # list wikis
    # https://developer.nulab.com/docs/backlog/api/2/get-wiki-page-list/
    print("# list wikis")
    wikis = api.wiki.list("SampleProject")
    print(json.dumps(wikis[0], indent=2))

    # get attachment
    # https://developer.nulab.com/docs/backlog/api/2/get-issue-attachment/
    print("# get attachment")
    wiki = [w for w in api.wiki.list("SampleProject") if len(w["attachments"]) > 0][0]
    attachment = api.wiki.get_attachment(
        wikiId=wiki["id"],
        attachmentId=wiki["attachments"][0]["id"])
    attachment["data"] = base64.b64encode(attachment["data"]).decode()
    print(json.dumps(attachment, indent=2))


if __name__ == "__main__":
    main()
```

## Errors

- `backlog.base.BacklogError` is raised when the API returns a non-2xx response.
- `backlog.base.BacklogConnectionError` (a subclass of `BacklogError`) is raised when the request could not be sent or no response was received, for example on a timeout.

## TLS certificates

HTTPS certificates are verified against the system trust store (it also honors `SSL_CERT_FILE` and `SSL_CERT_DIR`). If `certifi` is installed, or `REQUESTS_CA_BUNDLE` or `CURL_CA_BUNDLE` is set, those CA certificates are trusted as well.

## Upgrading to 0.9

0.9.0 removed the dependency on `requests`:

- `BaseAPI.invoke_method()` returns a `backlog._http.Response` instead of a `requests.Response`. It provides `status_code`, `ok`, `headers`, `content`, `text` and `json()`.
- `invoke_method()` only accepts the `timeout` and `files` keyword arguments. Requests-specific options such as `verify` or `proxies` raise `TypeError`. Proxies are still read from the `HTTP(S)_PROXY` and `NO_PROXY` environment variables.
- Network errors raise `BacklogConnectionError` instead of `requests.exceptions.*`.
- Redirects are not followed, so the API key is never sent to another host.
- `Project.list_categories()`, `add_category()`, `update_category()` and `delete_category()` are deprecated. Use `BacklogAPI.category` instead.

## See also

Qiita https://qiita.com/hassaku_63/items/b9eb2a1c7ecd3c19507d

## Contact

Please open an issue on [GitHub](https://github.com/hassaku63/pbl/issues).

Twitter: [hassaku_63](https://twitter.com/hassaku_63)
