Skip to main content

Serialize API fields on demand to various levels of depth

Project description

gh codecov womm

Allows clients to control which fields will be sent in the API response, now in a multidimensional nest of levels! Fields are specified in the query and separated by points determining a given depth with no limit, e.g.

# You want a list of users but you're only interested in the fields "email" and "username":

GET /users/?fields=email,username

[
  {
    "email": "bruno@gmail.com",
    "username": "bruno"
  },
  {
    "email": "endzel@gmail.com",
    "username": "endzel"
  }
]


# You want to see every field except "id" for the specific user endzel:

GET /users/2/?fields!=id

{
    "username": "endzel",
    "email": "endzel@gmail.com",
    "drinks": "tea",
    "location": {
        "id": 1,
        "country_name": "Spain",
        "city": "Málaga"
    }
}


# And, you just want to filter "username" and "city" for the "location" attribute within the user endzel:

GET /users/2/?fields=username,location.city

{
    "username": "endzel",
    "location": {
        "city": "Málaga"
    }
}

Supported Django versions: 4.2 - 6.0+. Check the CI matrix for details.

Documentation is hosted on Read The Docs.

Developers, developers, developers!

Want to contribute to the project? This is how to run the test suite:

# Get the repo (hopefully with a ⭐)
git clone https://github.com/Endzel/drf-nestedqueryfields.git

# Create and activate your virtual environment
python -m venv .venv
source .venv/bin/activate

# Install the app
pip install --editable ".[dev]"
git checkout -b myfeature

# Do your thing, and then fire the tests with
python -m pytest

Many thanks to Wim Glenn, author of the original DRF QueryFields repository from which this one was forked, that inspired me to add my two cents!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drf_nestedqueryfields-1.0.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_nestedqueryfields-1.0.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file drf_nestedqueryfields-1.0.0.tar.gz.

File metadata

  • Download URL: drf_nestedqueryfields-1.0.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drf_nestedqueryfields-1.0.0.tar.gz
Algorithm Hash digest
SHA256 772e5ff5cb5131eef39efc99758ed245ec43f685246f8a5ba69b404df45f5567
MD5 93365d725fc08adacbb45b627abc7955
BLAKE2b-256 003a753703d2008f807e0a3f20829d221328ab8b58140ad46c75f297a1cfba3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_nestedqueryfields-1.0.0.tar.gz:

Publisher: python-publish.yml on Endzel/drf-nestedqueryfields

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_nestedqueryfields-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_nestedqueryfields-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a371e04c4de34e920289e7cb329ddaecba15deec52b9eaa30342a69e1bf6b50a
MD5 815e6d0ac111e0b50f939423efe348c7
BLAKE2b-256 55c3df0fa8ec2d50cf9c2a098ebc0555966412ce3dd727ae3675efb2b6d2476c

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_nestedqueryfields-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on Endzel/drf-nestedqueryfields

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page