@@ -106,3 +106,83 @@ note that the user can still provide the parameters manually if needed.
106106 The ``load_from_eng_file `` method is a very useful tool for simulating motors \
107107 when the user does not have all the information required to build a ``SolidMotor `` yet.
108108
109+ The ``load_from_thrustcurve_api `` method
110+ ---------------------------------------
111+
112+ The ``GenericMotor `` class provides a convenience loader that downloads a temporary
113+ `.eng ` file from the ThrustCurve.org public API and builds a ``GenericMotor ``
114+ instance from it. This is useful when you know a motor designation (for example
115+ ``"M1670" ``) but do not want to manually download and
116+ save the `.eng ` file.
117+
118+ .. note ::
119+
120+ This method performs network requests to the ThrustCurve API. Use it only
121+ when you have network access. For automated testing or reproducible runs,
122+ prefer using local `.eng ` files.
123+ Signature
124+ ----------
125+
126+ ``GenericMotor.load_from_thrustcurve_api(name: str, **kwargs) -> GenericMotor ``
127+
128+ Parameters
129+ ----------
130+ name : str
131+ Motor name to search on ThrustCurve (example:
132+ ``"M1670" ``).Only shorthand names are accepted (e.g. ``"M1670" ``, not
133+ ``"Cesaroni M1670" ``).
134+ when multiple matches occur the first result returned by the API is used.
135+ **kwargs :
136+ Same optional arguments accepted by the :class:`GenericMotor` constructor
137+ (e.g. ``dry_mass``, ``nozzle_radius``, ``interpolation_method``). Any
138+ parameters provided here override values parsed from the downloaded file.
139+
140+ Returns
141+ ----------
142+ GenericMotor
143+ A new ``GenericMotor `` instance created from the .eng data downloaded from
144+ ThrustCurve.
145+
146+ Raises
147+ ----------
148+ ValueError
149+ If the API search returns no motor, or if the download endpoint returns no
150+ .eng file or empty/invalid data.
151+ requests.exceptions.RequestException
152+
153+ Behavior notes
154+ ---------------
155+ - The method first performs a search on ThrustCurve using the provided name.
156+ If no results are returned a :class: `ValueError ` is raised.
157+ - If a motor is found the method requests the .eng file in RASP format, decodes
158+ it and temporarily writes it to disk; a ``GenericMotor `` is then constructed
159+ using the existing .eng file loader. The temporary file is removed even if an
160+ error occurs.
161+ - The function emits a non-fatal informational warning when a motor is found
162+ (``warnings.warn(...) ``). This follows the repository convention for
163+ non-critical messages; callers can filter or suppress warnings as needed.
164+
165+ Example
166+ ---------------
167+
168+ .. jupyter-execute ::
169+
170+ from rocketpy.motors import GenericMotor
171+
172+ # Build a motor by name (requires network access)
173+ motor = GenericMotor.load_from_thrustcurve_api("M1670")
174+
175+ # Use the motor as usual
176+ motor.info()
177+
178+ Testing advice
179+ ---------------
180+ - ``pytest ``'s ``caplog `` or ``capfd `` to assert on log/warning output.
181+
182+ Security & reliability
183+ ----------------
184+ - The method makes outgoing HTTP requests and decodes base64-encoded content;
185+ validate inputs in upstream code if you accept motor names from untrusted
186+ sources.
187+ - Network failures, API rate limits, or changes to the ThrustCurve API may
188+ break loading; consider caching downloaded `.eng ` files for production use.
0 commit comments