Skip to main content

cosplay2py

Unofficial typed sync and async client (plus an optional read-only MCP server) for the Cosplay2.ru API, built on httpx2 and Pydantic.

Installing

Requires Python 3.12 or newer. Install from PyPI with uv:

uv add cosplay2py

Or with pip:

pip install cosplay2py

To install a specific release directly from GitHub:

uv add "cosplay2py @ git+https://github.com/Arutemu64/cosplay2py" --tag v0.3.0

Versions follow SemVer. On 0.x, a minor bump (0.1 → 0.2) may break things and a patch bump never does. See CHANGELOG.md.

Optional MCP server

cosplay2py[mcp] provides cosplay2py-mcp, a read-only stdio MCP server exposing 15 tools across five workflows:

  • Event overview: cosplay2_get_event_settings, cosplay2_get_event_state, cosplay2_list_topic_deadlines, cosplay2_list_topic_statistics
  • Nominations: cosplay2_list_topics, cosplay2_get_topic_form
  • Applications: cosplay2_list_topic_requests, cosplay2_list_all_requests, cosplay2_search_requests, cosplay2_get_request, cosplay2_list_request_comments
  • Site pages: cosplay2_list_pages, cosplay2_get_page
  • Schedule & results: cosplay2_get_schedule, cosplay2_get_winners

Run it without a local clone using uvx (from PyPI or a pinned GitHub release tag):

uvx --from "cosplay2py[mcp]" cosplay2py-mcp
uvx --from "cosplay2py[mcp] @ git+https://github.com/Arutemu64/cosplay2py@v0.5.0" cosplay2py-mcp

Universal mcpServers configuration (Claude Desktop, Claude Code, Cursor, Antigravity, Windsurf):

{
  "mcpServers": {
    "cosplay2": {
      "command": "uvx",
      "args": ["--from", "cosplay2py[mcp]", "cosplay2py-mcp"],
      "env": {
        "COSPLAY2_BASE_URL": "https://example.cosplay2.ru",
        "COSPLAY2_API_KEY": "your-api-key",
        "COSPLAY2_API_SECRET": "your-api-secret"
      }
    }
  }
}

Never commit credentials to shared project files: in project-scoped configs (such as Claude Code's .mcp.json or VS Code's .vscode/mcp.json), reference environment variables (${COSPLAY2_API_KEY} in Claude Code, ${env:COSPLAY2_API_KEY} under "servers" in VS Code, or env_vars in Codex's config.toml). For a local checkout, use uv sync --extra mcp and uv run --extra mcp cosplay2py-mcp. See MCP setup, host configs, and tool catalog.

Authentication

API tokens are issued per event: on the event site open Орги → Настройка → API токены and create a token. You get an API key and an API secret (the secret is shown once; tokens expire after 30 days). The client sends them as X-API-Key / X-API-Secret.

Usage

from cosplay2py import Cosplay2
from cosplay2py.models import BlankId, RequestStatus

with Cosplay2(subdomain="ff26summer", api_key="...", api_secret="...") as c2:
    event = c2.events.get_settings()
    print(event.title, event.timezone)

    for topic in c2.topics.get_list():
        listing = c2.topics.get_requests(topic.url_code)
        approved = [r for r in listing.requests if r.status is RequestStatus.APPROVED]
        print(topic.title, len(approved))

    details = c2.requests.get(687475)
    print(details.values_by_field())

    jury_sheet = c2.events.get_blank(BlankId.JURY).html

Async (asyncio or trio):

from cosplay2py import AsyncCosplay2

async with AsyncCosplay2(subdomain="ff26summer") as c2:
    state = await c2.events.get_state()
    print(state.requests_total)

Events on a custom domain: Cosplay2(base_url="https://fancom.info", ...).

Any argument left out falls back to the environment: COSPLAY2_API_KEY, COSPLAY2_API_SECRET, COSPLAY2_BASE_URL.

Resources

Attribute Methods
events get_settings, save_setting, get_state, get_topics_state, get_topics_statistic, get_staff, add_org, delete_org, change_main_org, add_curator, delete_curator, get_winners, get_plan, save_plan, get_blank, get_reg_topics, get_reg_alphabet, search, set_deadline
topics get_list, get_requests, get_all_requests, get_requests_for_planner, get_form, get_with_groups, add_child_topic, delete_child_topic, create, delete, reorder, fill_from_template, fill_from_topic, add_section, save_section, delete_section, add_field, delete_field, save_field, save_topic, reorder_section, reorder_field, generate_card_titles, reorder_requests
requests get, get_comments, get_org_comments, get_user, generate_card_title, generate_card_announcement, generate_card_diplom, generate_voting_number, search, get_value_history, add_comment, delete_comment, save_field, upload_image, delete_image, upload_file, delete_file, save_data, set_status, create, create_section, delete_section, change_topic, add_org_comment, delete_org_comment, get_feedbacks, add_feedback, delete_feedback
users search, ratings_global, ratings_country, ratings_area, ratings_region, ratings_city
design get, get_images, save, upload_image, delete_image, delete_panel_logo, delete_header_logo, delete_site_background
pages get_list, get, create, save_field, save_fields, delete, reorder
media get_data, add_album, save_album_field, delete_album
cards get_topics_and_cards, get_card, get_topics_and_requests, get_request
etickets get_list, get_types, add_type, delete_type, reorder_type, save_type_field, save_field, delete, create, get, get_status, save_personal_data
tickets get_statistic, get_voting_statistics, create, clear_votes, add_prize, delete_prize, save_prize_field, save_prize_handed, get_ticket, check_for_voting, get_voting_data, get_cards, select_winner

Data conventions

  • Server timestamps become timezone-aware UTC datetimes, whether the API sent "YYYY-MM-DD HH:MM:SS", Unix seconds or Unix milliseconds.
  • Display strings like "22.08.26 03:00" (TopicState, Event.start_time) become naive datetimes, as the site shows them.
  • 0/1 flags become bool. JSON packed into strings (Event.design, the plan) is parsed.
  • requests.search() returns RequestSearchResult models with request, voting, author and card display fields.
  • Closed domain sets (RequestStatus, TopicFieldType, PageType, PlanNodeType, EventRole, EventStatus, EventTime, TopicCategory, PublicRequests, TopicTemplate, SectionTemplate, FieldTemplate, FeedbackMark, CardField, TicketKind, TicketCreateMode, VotingType, BlankId, Deadline) are validated strictly as StrEnum / IntEnum members (empty strings on optional fields normalize to None).
  • Unknown fields are kept rather than rejected. Read them via model.model_extra.

Talking to the API without this library? docs/api-notes.md documents HTTP methods, inputs, outputs, authentication, wire formats and quirks for wrapped and unwrapped frontend routes. The field reference lists observed response schemas and enum values.

Errors

Cosplay2Error
└── APIError
    ├── APIConnectionError
    │   └── APITimeoutError
    ├── APIResponseValidationError   # 2xx, but not the expected JSON
    └── APIStatusError               # non-2xx; .status_code, .body, .response
        ├── BadRequestError (400)
        ├── AuthenticationError (401)
        ├── PermissionDeniedError (403)
        ├── NotFoundError (404)
        ├── RateLimitError (429)
        └── InternalServerError (5xx)

Repeatable reads retry transport failures and 429/502/503/504 responses, with exponential backoff and jitter (2 retries by default, configurable with max_retries). Writes retry only connection failures (ConnectError), never HTTP responses or read/write timeouts. An ambiguous failure may mean a write succeeded; check the service before repeating it yourself.

Retry-After supports seconds and HTTP dates. If the server asks for more than 30 seconds, the error is returned immediately instead of retrying early. Error messages omit response bodies and validation inputs. Inspect .response or .body explicitly when debugging; these can contain personal data.

Customizing HTTP

Pass timeout= (seconds or httpx2.Timeout), extra headers=, or a fully configured http_client=httpx2.Client(...) / httpx2.AsyncClient(...) for proxies, custom transports or testing with httpx2.MockTransport. A client you pass in is not closed by the wrapper. Its timeout and default headers apply; wrapper headers override matching defaults, and redirects are always disabled. timeout= applies only to a client created by the wrapper. Timeouts limit network phases, not the total time across retries. Use HTTPS for event credentials; HTTP is supported for local testing. Base URLs cannot contain userinfo, query strings or fragments.

This client follows observed site behavior, which can change without notice. Enable logging.getLogger("cosplay2py") at DEBUG to see requests.

Development

See CONTRIBUTING.md for how to propose changes.

uv sync
uv run prek install           # install Git hooks once per clone
uv run pytest                 # offline unit tests (default)
uv run prek run --all-files    # lint, format, and type-check

Testing against the real site

tests/live holds read-only smoke tests that are deselected by default. They need a token for the event (PowerShell shown):

$env:COSPLAY2_API_KEY = "..."
$env:COSPLAY2_API_SECRET = "..."
$env:COSPLAY2_BASE_URL = "https://ff26summer.cosplay2.ru"
uv run pytest -m live -rw

-rw lists warnings: fields the API returns that the models don't declare yet show up as UnknownFieldsWarning, an early sign of API drift.

Participant showcase calls return typed models: cards.get_topics_and_cards() returns TopicsAndCards, and cards.get_card() returns CardDetails with request, form, badge and user data. Public request calls cards.get_topics_and_requests() and cards.get_request() return TopicsAndRequests and PublicRequestDetails; list rows use PublicRequest with typed status and visibility settings.

Topic group calls return typed models: topics.get_with_groups() returns TopicGroup; topics.add_child_topic() and topics.delete_child_topic() return lists of TopicGroupLink with group_topic_id and child_topic_id.

Metadata

Release files for cosplay2py 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cosplay2py 0.5.0
File Size Uploaded Provenance Actions
cosplay2py-0.5.0.tar.gz 42.2 kB Without provenance Details for cosplay2py-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cosplay2py 0.5.0
File Interpreter ABI Platform Actions
cosplay2py-0.5.0-py3-none-any.whl Python 3 none any Details for cosplay2py-0.5.0-py3-none-any.whl

Total release size: 91.8 kB

Release files / cosplay2py-0.5.0.tar.gz

Download URL cosplay2py-0.5.0.tar.gz
Size 42.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d2b740975398cd6001b03cfbf1f24d8eb101c82f1a50ef16db8ff54f0edd7ec6
BLAKE2b-256 checksum
How to use checksums
a8acb76da66e8d0ce59991d5089a6ccc4460c1239234222897c6b71d0bda7fca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / cosplay2py-0.5.0-py3-none-any.whl

Download URL cosplay2py-0.5.0-py3-none-any.whl
Size 49.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9fa87e130ec73d5e713e715991b81c8c741b512898c42802bf9e455893a4e677
BLAKE2b-256 checksum
How to use checksums
7d9f1de0ae36779ec75897ab685bf013c8cf0cff8a09585e0c9dba246a0b0f14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for cosplay2py 0.5.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page