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.1.tar.gz (11.4 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.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: drf_nestedqueryfields-1.0.1.tar.gz
  • Upload date:
  • Size: 11.4 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.1.tar.gz
Algorithm Hash digest
SHA256 6b1e2b5563626c5cc90ac7ff152cb5ee77947452c05899e6ea1da57672c22bcb
MD5 f8bdb0f038e2571f39bb02d515bd1895
BLAKE2b-256 21387f2cf12b03bc50b228b26a623cfd04c8ae1444f2d4ea019fd38a4cd45a3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_nestedqueryfields-1.0.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_nestedqueryfields-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4839616f05b79ab818d3a4864d192a234cf8d5266a77d7a5bc3aadcb237ca653
MD5 e32671eac2cfac627a17589f978d0214
BLAKE2b-256 422b2854f6a900fbd9f27bfb0e54d13af0ffbb720a41c32ea4a550d3f415da99

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_nestedqueryfields-1.0.1-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