strawberry-django-phonenumber
Introduction
GraphQL types for Phone Numbers with Strawberry Django. If you use django, strawberry, and django-phonenumber-field, this library is for you.
Supported on:
- Python 3.10+
- Django 3+
- strawberry-graphql-django 0.17+
- django-phonenumber-field 7+
CI tests Python 3.10 (minimum supported) and 3.14 (latest).
Here's how it works. Automagically get this query:
query User {
phoneNumber {
...phoneNumberFragment
}
}
fragment phoneNumberFragment on PhoneNumber {
asInternational # +1 415-418-3420
asNational # (415) 418-3420
asE164
asRfc3966
countryCode # 1
nationalNumber
extension
rawInput
}
With this code:
# yourapp/models.py
from django.contrib.auth.models import AbstractUser
from phonenumber_field.modelfields import PhoneNumberField
class User(AbstractUser):
phone_number = PhoneNumberField(blank=True)
# yourapp/graphql/types.py
from typing import Optional, cast
import strawberry
import strawberry_django
from strawberry.types import Info
from strawberry_django_phonenumber import PhoneNumber
from yourapp import models
@strawberry_django.type(models.User, fields=["first_name", "last_name"])
class User(strawberry.relay.Node):
"""GraphQL type for the User model."""
@strawberry_django.field
async def phone_number(root, info: Info) -> Optional[PhoneNumber]:
if not root.phone_number:
return None
return cast(PhoneNumber, root.phone_number)
# yourapp/graphql/__init__.py
from typing import Optional
import strawberry
import strawberry_django
from asgiref.sync import sync_to_async
from strawberry.types import Info
from .types import User
@sync_to_async
def aget_user_from_request(request):
return request.user if request.user.is_authenticated else None
@strawberry.type
class Queries:
@strawberry_django.field
async def me(self, info: Info) -> Optional[User]:
user = await aget_user_from_request(info.context.request)
return user
schema = strawberry.Schema(query=Queries)
# yourapp/urls.py
from django.urls import path
from django.views.decorators.csrf import csrf_exempt
from strawberry.django.views import AsyncGraphQLView
from .graphql import schema
urlpatterns = [
path(
"graphql/",
csrf_exempt(
AsyncGraphQLView.as_view(
schema=schema,
graphql_ide="graphiql",
)
),
),
]
Installation
pip install strawberry-django-phonenumber
Changelog
0.2.2
- Replace Safety with pip-audit; refresh lockfile and dependency versions
- CI tests Python 3.10 and 3.14; consolidated lint job; updated GitHub Actions
- Dependabot with grouped minor/patch updates; optional pre-commit hook
- Docs: Python 3.10+; `graphql_ide` instead of deprecated `graphiql` on `AsyncGraphQLView`
0.2.1
- Remove deprecated strawberry-graphql debug-server extra
0.2.0
- Remove psycopg2-binary dependency, allow psycopg>=3
0.1.0
- Initial release
Contributing
Install dependencies and run tests (requires PostgreSQL; CI uses postgres / postgres on port 5432):
./poetry-install.sh
export PG_PASSWORD=postgres
poetry run pytest
Lint and security checks (same as CI):
./lint.sh --check
Format/fix locally:
./lint.sh
Optional pre-commit hook (runs ./lint.sh --check):
poetry run pre-commit install
Please open a pull request or issue.
Metadata
Release files for strawberry-django-phonenumber 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| strawberry_django_phonenumber-0.2.2.tar.gz | 3.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| strawberry_django_phonenumber-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.1 kB
Release files / strawberry_django_phonenumber-0.2.2.tar.gz
| Download URL | strawberry_django_phonenumber-0.2.2.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc63df0b59ccc78a800268653e362efd58d593f700414c346022faebb2149f94
|
|
BLAKE2b-256 checksum How to use checksums |
8ff4611feee78dcca6249f950a8637cb68a650ce6551c65bb0899317918ff208
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.
Transparency logRelease files / strawberry_django_phonenumber-0.2.2-py3-none-any.whl
| Download URL | strawberry_django_phonenumber-0.2.2-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c75a7b5f11cdf807fce5b22a030f9e7c84d9b440c5a88a34d53d6cc61ab479d1
|
|
BLAKE2b-256 checksum How to use checksums |
c04291a8d68674c62e4c602969cc845af9753880a3c8b1f032534338427b4100
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.
Transparency log