Api reference
components.global_profile.public.api ¶
Address
dataclass
¶
Address(
street,
postal_code,
locality,
country,
unit=None,
administrative_area=None,
sublocality=None,
postal_town=None,
)
Represents a physical address with international support.
Attributes:
| Name | Type | Description |
|---|---|---|
street |
str
|
The street name and number (e.g., "123 Main Street") |
unit |
str | None
|
Additional address details like apartment number, suite, or floor (e.g., "Apt 4B", "Suite 200") |
locality |
str | None
|
The city or town name (e.g., "Paris", "London") |
administrative_area |
str | None
|
The state, province, region, or department (e.g., "Île-de-France", "California") |
postal_code |
str | None
|
The ZIP code or postal code (e.g., "75001", "90210") |
country |
str
|
The ISO 3166-1 alpha-2 for the country. |
sublocality |
str | None
|
A smaller division within a locality such as district, borough, or neighborhood (e.g., "Le Marais", "Brooklyn") |
postal_town |
str | None
|
The post town or postal locality, which may differ from the locality (particularly relevant in some countries like the UK) |
Example
Errors
ValueError: for invalid country code or invalid administrative area code AddressInvalidException: for country specific validation e.g. Canada location and postal codes
__post_init__ ¶
Enforce ISO 3166 code validation
Source code in components/global_profile/internal/domain/entities.py
ProfileService ¶
Entry point to interact with profiles
This service exposes use cases, it is not intended as a CRUD service. As a result, when updating this service you should make sure that: - You introduce a new use case that is not already covered by the existing methods - Your change do not impact subscribers to current events, meaning that they should not be interested by your new event and won't miss any data change they are interested in
Note: Adding events should be carefully considered as granularity of such events can be quite complex to get right.
Instantiates the ProfileService
Default values are provided for target production use, you may need to override them.
Source code in components/global_profile/public/api.py
change_address ¶
Change the address of a profile
Source code in components/global_profile/public/api.py
change_birthdate ¶
Change the birthdate of a profile
Source code in components/global_profile/public/api.py
change_contact_information ¶
Change the contact information (address, email) of a profile Doesn't change the value if None is provided. To delete, please check the specific delete methods.
Source code in components/global_profile/public/api.py
change_email ¶
Change the email address of a profile
change_first_name ¶
Change the first name of a profile
Source code in components/global_profile/public/api.py
change_gender ¶
Change the gender of a profile
Source code in components/global_profile/public/api.py
change_identity_information ¶
THIS METHOD IS FOR MIGRATION PURPOSE ONLY, DO NOT USE IT FOR OTHER PURPOSE
Change the identity information (first name, last name, birthdate) of a profile
⚠️ None means the information will be deleted. To use carefully
Source code in components/global_profile/public/api.py
change_last_name ¶
Change the last name of a profile
Source code in components/global_profile/public/api.py
change_phone_number ¶
Change the phone number of a profile
Source code in components/global_profile/public/api.py
change_preferred_language ¶
Change the preferred language of a profile
Source code in components/global_profile/public/api.py
complete_information ¶
Complete the information of a profile
Source code in components/global_profile/public/api.py
create
classmethod
¶
Creates a ProfileService instance with the default parameters for a given country: Currently implemented countries: ES, FR, BE
With global_instance, it will use a specific repository allowing cross-country access. It adds profile to the "main" repository given the current environment, update all repositories with the given profile id and reads the first value found given a lookup table.
Source code in components/global_profile/public/api.py
create_profile ¶
create_profile(
*,
profile_id=None,
email=None,
first_name=None,
last_name=None,
additional_first_names=None,
birth_date=None,
birth_name=None,
gender=None,
preferred_language=Language.ENGLISH
)
Create a new profile
Source code in components/global_profile/public/api.py
create_testing
classmethod
¶
Creates a ProfileService instance for the shared TestUser
Source code in components/global_profile/public/api.py
delete_address ¶
Delete the address of a profile
Source code in components/global_profile/public/api.py
delete_email ¶
Delete the email address of a profile
Source code in components/global_profile/public/api.py
delete_gender ¶
Delete the gender of a profile
delete_phone_number ¶
Delete the phone number of a profile
Source code in components/global_profile/public/api.py
edit_birth_information ¶
Updates the birth information of a profile after a manual edition (e.g. from the member, the admin...)
None means the information won't be updated: values cannot be unset using this method.
Source code in components/global_profile/public/api.py
edit_consents ¶
Updates the consents of a profile after a manual edition from the member
Source code in components/global_profile/public/api.py
edit_personal_information ¶
edit_personal_information(
profile_id,
*,
first_name=None,
last_name=None,
additional_first_names=None,
birth_date=None
)
Updates the personal information of a profile after a manual edition (e.g. from the member, the admin...)
None means the information won't be updated: values cannot be unset using this method.
birth_date is deprecated and will be removed in a future release.
Please use edit_birth_information instead.
Source code in components/global_profile/public/api.py
fill_missing_information ¶
fill_missing_information(
profile_id,
*,
first_name=None,
last_name=None,
additional_first_names=None,
birth_name=None,
birth_date=None,
place_of_birth=None,
gender=None
)
Fills missing information of a Profile.
It won't replace any existing values, only fills the one set to None.
Source code in components/global_profile/public/api.py
get_or_raise_profile ¶
Get a profile by its ID or raise an error if not found
Source code in components/global_profile/public/api.py
get_or_raise_profiles ¶
Get multiple profiles by their IDs or raise an error if not found
Source code in components/global_profile/public/api.py
get_profile ¶
get_profile_by_email ¶
Get a profile by its email address
get_profiles ¶
Get multiple profiles by their IDs
Source code in components/global_profile/public/api.py
merge_profile_into_another ¶
merge_profile_into_another(
*,
source_profile_id,
target_profile_id,
strategy=ProfileMergeStrategy.SOURCE_DELETED
)
Merges one profile into another.
Merging profile A (source) to B (target) will simply delete profile A and emit an event ProfileMergedEvent with the IDs of both profiles for models to be updated accordingly.
Source code in components/global_profile/public/api.py
message_bus
instance-attribute
¶
message_bus = message_bus or MessageBus(
unit_of_work,
injected_event_handlers,
injected_command_handlers,
)
search_by_age_greater_or_equal_to ¶
Search profiles by their age and using their birthday
Source code in components/global_profile/public/api.py
search_profiles_by_fullname ¶
Search profiles by their full name
Source code in components/global_profile/public/api.py
search_profiles_by_phone_number ¶
Search profiles by phone number
Source code in components/global_profile/public/api.py
components.global_profile.public.constants ¶
components.global_profile.public.entities ¶
Address
dataclass
¶
Address(
street,
postal_code,
locality,
country,
unit=None,
administrative_area=None,
sublocality=None,
postal_town=None,
)
Represents a physical address with international support.
Attributes:
| Name | Type | Description |
|---|---|---|
street |
str
|
The street name and number (e.g., "123 Main Street") |
unit |
str | None
|
Additional address details like apartment number, suite, or floor (e.g., "Apt 4B", "Suite 200") |
locality |
str | None
|
The city or town name (e.g., "Paris", "London") |
administrative_area |
str | None
|
The state, province, region, or department (e.g., "Île-de-France", "California") |
postal_code |
str | None
|
The ZIP code or postal code (e.g., "75001", "90210") |
country |
str
|
The ISO 3166-1 alpha-2 for the country. |
sublocality |
str | None
|
A smaller division within a locality such as district, borough, or neighborhood (e.g., "Le Marais", "Brooklyn") |
postal_town |
str | None
|
The post town or postal locality, which may differ from the locality (particularly relevant in some countries like the UK) |
Example
Errors
ValueError: for invalid country code or invalid administrative area code AddressInvalidException: for country specific validation e.g. Canada location and postal codes
__post_init__ ¶
Enforce ISO 3166 code validation
Source code in components/global_profile/internal/domain/entities.py
Gender ¶
Bases: StrEnum
Gender of a person.
Note: this is different from the biological sex.
Language ¶
Bases: StrEnum
Language spoken by a person.
Used to define the preferred language for communication. It is naturally constrained by the languages supported at Alan.
Must use ISO-639 nomenclature, see https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ⧉
PlaceIdentifierType ¶
Bases: StrEnum
Available types to identify a place.
Other types that could be used (not exhaustive): NUTS = "nuts" # EU Nomenclature of Territorial Units for Statistics - hierarchical regional codes UN_LOCODE = "unlocode" # UN Location Codes - international standard for cities and ports (5 chars) WIKIDATA = "wikidata" # Wikidata knowledge base - universal place identifiers (Q-numbers) GEONAMES = "geonames" # GeoNames geographical database - numeric place identifiers
PlaceOfBirth
dataclass
¶
Represents a geographical place with optional identifiers.
This class can represent any type of place from cities to countries to regions, with varying levels of precision and identification.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable place name (e.g., "Paris", "Normandy", "Unknown") |
country |
str | None
|
ISO 3166-1 alpha-2 country code (e.g., "FR", "DE") or None if unknown |
identifiers |
dict[PlaceIdentifierType, str] | None
|
Dictionary mapping identifier providers to their codes, or None if no identifiers available |
Examples:
>>> PlaceOfBirth("Paris", "FR").with_place_identifier(PlaceIdentifierType.INSEE, "75056")
PlaceOfBirth(name='Paris', country='FR', identifiers={<PlaceIdentifierType.INSEE: 'insee'>: '75056'})
>>> PlaceOfBirth("Somewhere in France", country="FR")
PlaceOfBirth(name='Somewhere in France', country='FR', identifiers=None)
__post_init__ ¶
Source code in components/global_profile/internal/domain/entities.py
get_place_identifier ¶
Returns the identifier code for the given identifier type, or None if not found.
Source code in components/global_profile/internal/domain/entities.py
with_place_identifier ¶
Returns a new instance, adding or replacing the identifier_type code.
Source code in components/global_profile/internal/domain/entities.py
ProfileConsents
dataclass
¶
Bases: DataClassJsonMixin
Collected consents
ProfileMergeStrategy ¶
Bases: StrEnum
Strategies to merge two profiles. - SOURCE_DELETED: the source profile is deleted and the target profile remains unchanged. - TARGET_WINS: the target profile's non-null fields take precedence over the source profile's fields. (target_profile.field = target_profile.field or source_profile.field). The source profile is then deleted.
components.global_profile.public.events ¶
BirthInformationChanged
dataclass
¶
ConsentsChanged
dataclass
¶
IdentityInformationChanged
dataclass
¶
IdentityInformationChanged(
profile_id,
first_name,
last_name,
additional_first_names=None,
birth_date=None,
)
Bases: Message
IdentityInformationChanged event
PreferredLanguageChanged
dataclass
¶
ProfileAddressChanged
dataclass
¶
ProfileEmailChanged
dataclass
¶
components.global_profile.public.exceptions ¶
components.global_profile.public.inject_profile_service ¶
inject_profile_service ¶
Inject a ProfileService in method parameters.
This injector mimics a DI injection of the ProfileService to keep the door opened for a DI framework if needed
Source code in components/global_profile/public/inject_profile_service.py
components.global_profile.public.mappers ¶
GenderMapper ¶
Bases: Mapper[UserGender | None, Gender | None]
Maps between UserGender|None<>Gender|None
to_entity
staticmethod
¶
Source code in components/global_profile/public/mappers.py
to_model
staticmethod
¶
Source code in components/global_profile/public/mappers.py
components.global_profile.public.profile_column_decorator ¶
global_profile_link ¶
Use this decorator to mark a UUID column as a global profile id following the example bellow.
If the id of the original were to be merged with another, the marked column would be migrated.
⚠️ always the decorator declared_attr on top of this decorator (and not the other way around).
⚠️ it does not work for columns with constraints.
@declared_attr
@global_profile_link
def profile_id(cls) -> Mapped[uuid.UUID]:
return mapped_column(PostgreSQLUUID(as_uuid=True))
Source code in components/global_profile/public/profile_column_decorator.py
components.global_profile.public.subscriptions ¶
subscribe_to_events ¶
All event subscriptions for the global profile component should be done here.
Source code in components/global_profile/public/subscriptions.py
components.global_profile.public.transformers ¶
GenderTransformer ¶
Transforms different gender representations to and from the domain model.
The domain model (Gender enum) represents gender biaised towards gender/biological sex distinction, while external representations might have different meanings.
to_domain
staticmethod
¶
Transforms UserGender or str representation to domain model.
If str input is used, must valid string representations of Gender or UserGender
Source code in components/global_profile/public/transformers.py
LanguageTransformer ¶
Transforms different language representations to domain Language.
to_domain
staticmethod
¶
Transforms Lang or str representation to domain model.
If str input is used, must be a ISO 639-2 code