Name | trac-rpc JSON |
Version |
0.1.1
JSON |
| download |
home_page | None |
Summary | Modern, Pythonic and type-safe Trac RPC API client |
upload_time | 2025-03-01 08:06:11 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.12 |
license | None |
keywords |
api
httpx
pydantic
rpc
trac
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Trac RPC API client
[](https://github.com/zyv/trac-rpc-client/blob/main/LICENSE)
[](https://pypi.python.org/pypi/trac-rpc)

[](https://docs.pydantic.dev/latest/contributing/#badges)
[](https://github.com/astral-sh/ruff)
[](https://github.com/zyv/trac-rpc-client/actions)
Modern, Pythonic and type-safe Trac RPC API client.
> [!NOTE]
> This package was developed primarily to satisfy my personal migration needs and as such covers only the **read** interface of the API!
>
> Please feel free to contact me for complex migration projects from Trac and/or custom development needs. High quality contributions that follow the library structure and donations are also much appreciated.
## Installation
```shell
$ pip install trac-rpc
```
### Dependencies
* [Pydantic V2](https://pydantic.dev)
* [httpx](https://www.python-httpx.org)
## Usage
```pycon
>>> from trac_rpc.client import ApiClient, HttpClient
>>> api_client = ApiClient(
rpc_url="http://127.0.0.1:8000/login/rpc",
http_client=HttpClient(auth=("admin", "admin")),
)
>>> api_client.get_api_version()
TracApiVersion(epoch=1, major=2, minor=0)
>>> result = api_client.get_ticket_last_field_change(1, "status", "closed")
>>> result.timestamp
datetime.datetime(2025, 2, 27, 13, 37, 11, 171873, tzinfo=TzInfo(UTC))
```
> [!IMPORTANT]
> Trac APIs (e.g. `query_tickets`) do not return IDs and/or objects sorted in alphanumeric order!
>
> They can either be returned in a custom order (such as priority levels) or grouped by certain fields (such as ticket IDs). If you want to iterate on the objects in a particular order, always remember to sort them appropriately after you call the API.
### Customizing models
#### Changing default string type
Some models like `TracMilestone` can be parameterized with a string type such as `TracStrippedStr` instead of `str` to strip leading and trailing whitespace:
```python
from trac_rpc.client import ApiClient
from trac_rpc.models import TracMilestone
from trac_rpc.validators import TracStrippedStr
api_client = ApiClient(rpc_url="http://127.0.0.1:8000/rpc")
milestone = api_client.get_milestone(" milestone2 ", TracMilestone[TracStrippedStr])
```
This is especially useful for migrations to detect unnoticed whitespace problems. However, this can potentially cause calls to the Trac RPC API with string object names to fail, so it is not enabled by default.
#### Adjusting `TracTicket` model
Each Trac installation is configured in its own way. The default `TracTicket` model can be easily customized by subclassing:
```python
from trac_rpc.models import TracTicket as TracTicketBase
from trac_rpc.validators import TracSpaceOrCommaSeparated
class TracTicket(TracTicketBase):
keywords: TracSpaceOrCommaSeparated[str]
cc: TracSpaceOrCommaSeparated[str]
```
Usually Trac fields are separated by spaces (`TracSpaceSeparated`), but alternative types are provided for convenience (`TracCommaSeparated`, `TracSpaceOrCommaSeparated`).
Complex validation to ensure data consistency is possible with the `validate_in_set` validator:
```python
from functools import partial
from typing import Annotated
from pydantic import AfterValidator
from trac_rpc.models import TracTicket as TracTicketBase
from trac_rpc.validators import validate_in_set, TracOptionalField
VERSIONS = {"1.0", "2.0"}
class TracTicket(TracTicketBase):
validate_version = partial(validate_in_set, allowed=VERSIONS, optional=True)
...
version: Annotated[TracOptionalField[str], AfterValidator(validate_version)]
```
## Development
### Setting up test Trac server
See [GitHub Actions workflow](.github/workflows/ci.yml) for integration tests.
### Releases
To release a new version and publish it to PyPI:
* Bump version with `hatch` and commit
* `hatch version minor` or `hatch version patch`
* Create GitHub release (and tag)
Raw data
{
"_id": null,
"home_page": null,
"name": "trac-rpc",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "api, httpx, pydantic, rpc, trac",
"author": null,
"author_email": "\"Yury V. Zaytsev\" <yury@shurup.com>",
"download_url": "https://files.pythonhosted.org/packages/f3/22/6389f7a03e7ac23da39e8ab3419bce4dd14e6eaa4ac576fc3bd8f2435058/trac_rpc-0.1.1.tar.gz",
"platform": null,
"description": "# Trac RPC API client\n\n[](https://github.com/zyv/trac-rpc-client/blob/main/LICENSE)\n[](https://pypi.python.org/pypi/trac-rpc)\n\n[](https://docs.pydantic.dev/latest/contributing/#badges)\n[](https://github.com/astral-sh/ruff)\n[](https://github.com/zyv/trac-rpc-client/actions)\n\nModern, Pythonic and type-safe Trac RPC API client.\n\n> [!NOTE]\n> This package was developed primarily to satisfy my personal migration needs and as such covers only the **read** interface of the API!\n>\n> Please feel free to contact me for complex migration projects from Trac and/or custom development needs. High quality contributions that follow the library structure and donations are also much appreciated.\n\n## Installation\n\n```shell\n$ pip install trac-rpc\n```\n\n### Dependencies\n\n* [Pydantic V2](https://pydantic.dev)\n* [httpx](https://www.python-httpx.org)\n\n## Usage\n\n```pycon\n>>> from trac_rpc.client import ApiClient, HttpClient\n\n>>> api_client = ApiClient(\n rpc_url=\"http://127.0.0.1:8000/login/rpc\",\n http_client=HttpClient(auth=(\"admin\", \"admin\")),\n)\n\n>>> api_client.get_api_version()\nTracApiVersion(epoch=1, major=2, minor=0)\n\n>>> result = api_client.get_ticket_last_field_change(1, \"status\", \"closed\")\n>>> result.timestamp\ndatetime.datetime(2025, 2, 27, 13, 37, 11, 171873, tzinfo=TzInfo(UTC))\n```\n\n> [!IMPORTANT]\n> Trac APIs (e.g. `query_tickets`) do not return IDs and/or objects sorted in alphanumeric order!\n>\n> They can either be returned in a custom order (such as priority levels) or grouped by certain fields (such as ticket IDs). If you want to iterate on the objects in a particular order, always remember to sort them appropriately after you call the API.\n\n### Customizing models\n\n#### Changing default string type\n\nSome models like `TracMilestone` can be parameterized with a string type such as `TracStrippedStr` instead of `str` to strip leading and trailing whitespace:\n\n```python\nfrom trac_rpc.client import ApiClient\nfrom trac_rpc.models import TracMilestone\nfrom trac_rpc.validators import TracStrippedStr\n\napi_client = ApiClient(rpc_url=\"http://127.0.0.1:8000/rpc\")\nmilestone = api_client.get_milestone(\" milestone2 \", TracMilestone[TracStrippedStr])\n```\n\nThis is especially useful for migrations to detect unnoticed whitespace problems. However, this can potentially cause calls to the Trac RPC API with string object names to fail, so it is not enabled by default.\n\n#### Adjusting `TracTicket` model\n\nEach Trac installation is configured in its own way. The default `TracTicket` model can be easily customized by subclassing:\n\n```python\nfrom trac_rpc.models import TracTicket as TracTicketBase\nfrom trac_rpc.validators import TracSpaceOrCommaSeparated\n\nclass TracTicket(TracTicketBase):\n keywords: TracSpaceOrCommaSeparated[str]\n cc: TracSpaceOrCommaSeparated[str]\n```\n\nUsually Trac fields are separated by spaces (`TracSpaceSeparated`), but alternative types are provided for convenience (`TracCommaSeparated`, `TracSpaceOrCommaSeparated`).\n\nComplex validation to ensure data consistency is possible with the `validate_in_set` validator:\n\n```python\nfrom functools import partial\nfrom typing import Annotated\n\nfrom pydantic import AfterValidator\nfrom trac_rpc.models import TracTicket as TracTicketBase\nfrom trac_rpc.validators import validate_in_set, TracOptionalField\n\nVERSIONS = {\"1.0\", \"2.0\"}\n\n\nclass TracTicket(TracTicketBase):\n validate_version = partial(validate_in_set, allowed=VERSIONS, optional=True)\n ...\n version: Annotated[TracOptionalField[str], AfterValidator(validate_version)]\n```\n\n## Development\n\n### Setting up test Trac server\n\nSee [GitHub Actions workflow](.github/workflows/ci.yml) for integration tests.\n\n### Releases\n\nTo release a new version and publish it to PyPI:\n\n* Bump version with `hatch` and commit\n * `hatch version minor` or `hatch version patch`\n* Create GitHub release (and tag)\n",
"bugtrack_url": null,
"license": null,
"summary": "Modern, Pythonic and type-safe Trac RPC API client",
"version": "0.1.1",
"project_urls": null,
"split_keywords": [
"api",
" httpx",
" pydantic",
" rpc",
" trac"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "80bb4a0095e8120c5646e80212af0559185901ff4095792acc142ba1d76ec02d",
"md5": "340d501bd403f4fcc4ee2eb593812225",
"sha256": "cac8943b859f3905fc1a2ee73282fab3fc6dbcb2dbb1f8e90ba05269ba52594e"
},
"downloads": -1,
"filename": "trac_rpc-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "340d501bd403f4fcc4ee2eb593812225",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 8901,
"upload_time": "2025-03-01T08:06:10",
"upload_time_iso_8601": "2025-03-01T08:06:10.192935Z",
"url": "https://files.pythonhosted.org/packages/80/bb/4a0095e8120c5646e80212af0559185901ff4095792acc142ba1d76ec02d/trac_rpc-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "f3226389f7a03e7ac23da39e8ab3419bce4dd14e6eaa4ac576fc3bd8f2435058",
"md5": "dd42b01c03bb201e9fc87f9b05ffc469",
"sha256": "b7bbfa41891e5b28a2321fe793cf62bda02b68d1c16fe4d2fce795fd83c511dd"
},
"downloads": -1,
"filename": "trac_rpc-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "dd42b01c03bb201e9fc87f9b05ffc469",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 41408,
"upload_time": "2025-03-01T08:06:11",
"upload_time_iso_8601": "2025-03-01T08:06:11.745384Z",
"url": "https://files.pythonhosted.org/packages/f3/22/6389f7a03e7ac23da39e8ab3419bce4dd14e6eaa4ac576fc3bd8f2435058/trac_rpc-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-01 08:06:11",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "trac-rpc"
}