Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples to use inline dependencies; remove redundant examples #2778

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Features:

Documentation:

- Various documentation improvements (:pr:`2757`, :pr:`2759`, :pr:`2765`, :pr:`2774`).
- Various documentation improvements (:pr:`2757`, :pr:`2759`, :pr:`2765`, :pr:`2774`, :pr:`2778`).

Deprecations:

Expand Down
299 changes: 0 additions & 299 deletions docs/examples.rst

This file was deleted.

16 changes: 16 additions & 0 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
********
Examples
********

The below examples demonstrate how to use marshmallow in various contexts.
To run each example, you will need to have `uv <https://docs.astral.sh/uv/getting-started/installation/>`_ installed.
The examples use `PEP 723 inline metadata <https://peps.python.org/pep-0723/>`_
to declare the dependencies of each script. ``uv`` will install the
dependencies automatically when running these scripts.

.. toctree::
:maxdepth: 1

validating_package_json
quotes_api
inflection
19 changes: 19 additions & 0 deletions docs/examples/inflection.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*****************************
Inflection (camel-cased keys)
*****************************

HTTP APIs will often use camel-cased keys for their input and output representations. This example shows how you can use the
`Schema.on_bind_field <marshmallow.Schema.on_bind_field>` hook to automatically inflect keys.

.. literalinclude:: ../../examples/inflection_example.py
:language: python

To run the example:

.. code-block:: shell-session

$ uv run examples/inflection_example.py
Loaded data:
{'first_name': 'David', 'last_name': 'Bowie'}
Dumped data:
{'firstName': 'David', 'lastName': 'Bowie'}
Loading
Loading