Trac RPC API client
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
$ pip install trac-rpc
Dependencies
Usage
>>> 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:
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:
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:
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 for integration tests.
Releases
To release a new version and publish it to PyPI:
- Bump version with
hatchand commithatch version minororhatch version patch
- Create GitHub release (and tag)
Metadata
Release files for trac-rpc 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| trac_rpc-0.1.3.tar.gz | 44.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| trac_rpc-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 53.5 kB
Release files / trac_rpc-0.1.3.tar.gz
| Download URL | trac_rpc-0.1.3.tar.gz |
|---|---|
| Size | 44.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7b685fc8355e9ad7de57d90cf0a9010eab457a04cf15b6d4aed7255f38f814b
|
|
BLAKE2b-256 checksum How to use checksums |
a6f1bc608f27aa85a64e858b608b7bdcd6e688d912672f42eec17a27c129aff0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.17
|
Release files / trac_rpc-0.1.3-py3-none-any.whl
| Download URL | trac_rpc-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb29cb25e13f15e0db21b24a0586969d0e077e94f2497b2fae42ce3d17a84e6c
|
|
BLAKE2b-256 checksum How to use checksums |
79fda8c48f39a0560993d6938dbe74a6a2ccf6ef219995e0552ce2a3fb2f0a00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.17
|
Security for trac-rpc 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.