Add Python port of RestSharp (restsharp_py)#12
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Add Python port of RestSharp (restsharp_py)#12devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
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>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
RestClient,RestRequest,RestResponse[T],Parameter,FileParameter,RestResponseCookieMethod,ParameterType,DataFormat,ResponseStatus, plusDateFormatISO-8601 / round-trip constantsRestClient.executebacked byrequests.Session,RestClient.execute_asyncbacked byhttpx.AsyncClient, with typed variants anddownload_dataBuildUri/EncodeParameterscovering URL-segment substitution, query-string encoding, base-URL slash normalizationJsonSerializer(stdlibjson) andXmlSerializer(xml.etree.ElementTree), with aSerializeAsdecorator /_field_optionsmetadata for attribute-style and ordered fieldsJsonDeserializerandXmlDeserializerwith fuzzy name matching (product_id↔ProductId), namespace flattening, root-element support, optional/union unwrapping, dataclass-awareHttpBasicAuthenticator,OAuth1Authenticator(requests_oauthlib),OAuth2Authenticator+ Header/Query variants,NtlmAuthenticator(requests_ntlm),SimpleAuthenticatorget_name_variants,to_pascal_case/to_camel_case,add_underscores/add_dashes,url_encode/url_decode,parse_json_dateSkipped intentionally (per task description):
Compression/, platform-specific projects (Silverlight, WindowsPhone, MonoDroid, MonoTouch),T4Helper/, LinqBridge /System.Xml.Linqshims.Tests
82 pytest tests, all passing locally (
python -m pytest tests/):.cstesttests/test_url_builder.pyRestSharp.Tests/UrlBuilderTests.cstests/test_json.pyRestSharp.Tests/JsonTests.cstests/test_xml.pyRestSharp.Tests/XmlTests.cstests/test_serializers.pyRestSharp.Tests/SerializerTests.cstests/test_enums.py/test_extensions.py/test_request.py/test_client.pytests/test_integration/test_async.pyRestSharp.IntegrationTests/AsyncTests.cstests/test_integration/test_auth.pyRestSharp.IntegrationTests/AuthenticationTests.cstests/test_integration/test_files.pyRestSharp.IntegrationTests/FileTests.cstests/test_integration/test_compression.pyRestSharp.IntegrationTests/CompressionTests.cstests/test_integration/test_status_codes.pyRestSharp.IntegrationTests/StatusCodeTests.csIntegration tests mock HTTP via
responses(sync) andhttpx.MockTransport(async), so no network is required.Dependencies
requirements.txtandpyproject.toml:Review & Testing Checklist for Human
pip install -r requirements.txtthenpython -m pytest tests/and confirm all 82 tests pass.restsharp_py/client.py— particularlybuild_uri,_build_payload,_dispatch, andexecute_async— against the originalRestSharp/RestClient*.csto verify the parameter mapping (URL segment, query string, form body, multipart files, default parameters).get_name_variantsarename, ToPascalCase(name), toCamelCase(name), name.lower(), name.upper(), Add_Underscores, add_underscores_lower, Add-Dashes, add-dashes-lower.httpbin.org/get) using the snippet inREADME.python.mdto validate that the package works against a live server.restsharp_pyvs.restsharp) and whether to keep it co-located with the .NET sources or move to its own repo.Notes
README.python.mdcontains a quick-start and module map for Python users.JsonSerializerindents output (matches the .NET formatter'sFormatting.Indented); if you want compact output, change tojson.dumps(obj, cls=_RestSharpJsonEncoder).snake_caseattribute names againstPascalCaseelement/attribute names (so<ProductId>deserializes intoproduct_id). The serializer keeps the Python attribute name as the element tag — useSerializeAs(name="ProductId")or the_field_optionsmapping for a different casing.Link to Devin session: https://app.devin.ai/sessions/2742fba91f6940f6a76d80b9e9bc1e41
Requested by: @dillonvargo
Devin Review