Skip to content

Add Python port of RestSharp (restsharp_py)#12

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1778686761-python-port
Open

Add Python port of RestSharp (restsharp_py)#12
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1778686761-python-port

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented May 13, 2026

Copy link
Copy Markdown

Summary

Adds a new Python package restsharp_py/ that mirrors the public API surface of the .NET RestSharp 2.0 library while using Pythonic idioms (dataclasses, enums, Protocols, type hints). The original .NET sources are untouched.

What's in the port:

  • Core typesRestClient, RestRequest, RestResponse[T], Parameter, FileParameter, RestResponseCookie
  • EnumsMethod, ParameterType, DataFormat, ResponseStatus, plus DateFormat ISO-8601 / round-trip constants
  • Sync + async dispatchRestClient.execute backed by requests.Session, RestClient.execute_async backed by httpx.AsyncClient, with typed variants and download_data
  • URL building — port of BuildUri / EncodeParameters covering URL-segment substitution, query-string encoding, base-URL slash normalization
  • SerializersJsonSerializer (stdlib json) and XmlSerializer (xml.etree.ElementTree), with a SerializeAs decorator / _field_options metadata for attribute-style and ordered fields
  • DeserializersJsonDeserializer and XmlDeserializer with fuzzy name matching (product_idProductId), namespace flattening, root-element support, optional/union unwrapping, dataclass-aware
  • AuthenticatorsHttpBasicAuthenticator, OAuth1Authenticator (requests_oauthlib), OAuth2Authenticator + Header/Query variants, NtlmAuthenticator (requests_ntlm), SimpleAuthenticator
  • Extensionsget_name_variants, to_pascal_case/to_camel_case, add_underscores/add_dashes, url_encode/url_decode, parse_json_date

Skipped intentionally (per task description): Compression/, platform-specific projects (Silverlight, WindowsPhone, MonoDroid, MonoTouch), T4Helper/, LinqBridge / System.Xml.Linq shims.

Tests

82 pytest tests, all passing locally (python -m pytest tests/):

File Source .cs test
tests/test_url_builder.py RestSharp.Tests/UrlBuilderTests.cs
tests/test_json.py RestSharp.Tests/JsonTests.cs
tests/test_xml.py RestSharp.Tests/XmlTests.cs
tests/test_serializers.py RestSharp.Tests/SerializerTests.cs
tests/test_enums.py / test_extensions.py / test_request.py / test_client.py new unit coverage
tests/test_integration/test_async.py RestSharp.IntegrationTests/AsyncTests.cs
tests/test_integration/test_auth.py RestSharp.IntegrationTests/AuthenticationTests.cs
tests/test_integration/test_files.py RestSharp.IntegrationTests/FileTests.cs
tests/test_integration/test_compression.py RestSharp.IntegrationTests/CompressionTests.cs
tests/test_integration/test_status_codes.py RestSharp.IntegrationTests/StatusCodeTests.cs

Integration tests mock HTTP via responses (sync) and httpx.MockTransport (async), so no network is required.

Dependencies

requirements.txt and pyproject.toml:

requests>=2.31.0
httpx>=0.25.0
requests-oauthlib>=1.3.0
requests-ntlm>=1.2.0
lxml>=4.9.0
pytest>=7.0.0
pytest-asyncio>=0.21.0
responses>=0.23.0

Review & Testing Checklist for Human

  • Run pip install -r requirements.txt then python -m pytest tests/ and confirm all 82 tests pass.
  • Spot-check restsharp_py/client.py — particularly build_uri, _build_payload, _dispatch, and execute_async — against the original RestSharp/RestClient*.cs to verify the parameter mapping (URL segment, query string, form body, multipart files, default parameters).
  • Confirm fuzzy name matching behaves as expected against your real APIs: the variants generated by get_name_variants are name, ToPascalCase(name), toCamelCase(name), name.lower(), name.upper(), Add_Underscores, add_underscores_lower, Add-Dashes, add-dashes-lower.
  • Try one real end-to-end call (e.g. against httpbin.org/get) using the snippet in README.python.md to validate that the package works against a live server.
  • If you intend to publish this as a Python package, decide on the package name (restsharp_py vs. restsharp) and whether to keep it co-located with the .NET sources or move to its own repo.

Notes

  • README.python.md contains a quick-start and module map for Python users.
  • JsonSerializer indents output (matches the .NET formatter's Formatting.Indented); if you want compact output, change to json.dumps(obj, cls=_RestSharpJsonEncoder).
  • The XML serializer/deserializer fuzzy-matches Python snake_case attribute names against PascalCase element/attribute names (so <ProductId> deserializes into product_id). The serializer keeps the Python attribute name as the element tag — use SerializeAs(name="ProductId") or the _field_options mapping for a different casing.

Link to Devin session: https://app.devin.ai/sessions/2742fba91f6940f6a76d80b9e9bc1e41
Requested by: @dillonvargo


Devin Review

Status Commit
⚪ Not started

Run Devin Review

💡 Connect your GitHub account to enable automatic code reviews.

Open in Devin Review (Staging)

Mirrors the public surface of the .NET library:
- RestClient (sync via requests.Session + async via httpx.AsyncClient)
- RestRequest with parameters, headers, cookies, URL segments, file uploads,
  and add_body delegating to JSON/XML serializers
- RestResponse (generic, with deserialized data attribute)
- ParameterType / DataFormat / Method / ResponseStatus enums
- JSON + XML serializers and deserializers with fuzzy name matching
- HttpBasic / OAuth1 / OAuth2 / NTLM / Simple authenticators
- String/case helpers (get_name_variants, url_encode, parse_json_date)

Includes 82 pytest tests covering URL building, JSON/XML deserialization,
serializer behavior, request construction, client plumbing, async dispatch,
file uploads, compression, status codes, and authenticators.

Co-Authored-By: Dillon Vargo <dillonvargo@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants