PHPackages                             demografix/demografix - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. demografix/demografix

ActiveLibrary[API Development](/categories/api)

demografix/demografix
=====================

Official PHP client for the Demografix APIs: genderize.io, agify.io, and nationalize.io.

v0.1.0(today)10MITPHPPHP &gt;=8.2CI passing

Since Jun 26Pushed today1 watchersCompare

[ Source](https://github.com/DemografixGenderize/demografix-php)[ Packagist](https://packagist.org/packages/demografix/demografix)[ Docs](https://github.com/DemografixGenderize/demografix-php)[ RSS](/packages/demografix-demografix/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Demografix PHP SDK
==================

[](#demografix-php-sdk)

Run demographic analysis over names — predicted gender, age, and nationality — from one PHP client. The package covers [genderize.io](https://genderize.io), [agify.io](https://agify.io), and [nationalize.io](https://nationalize.io).

Install
-------

[](#install)

```
composer require demografix/demografix
```

Requires PHP 8.2 or later and the cURL extension. No runtime dependencies.

Quickstart
----------

[](#quickstart)

Construct a client, run a batch over a list of names, read the predictions, and read the remaining quota.

```
use Demografix\Client;

$client = new Client('YOUR_API_KEY');

$batch = $client->genderizeBatch(['peter', 'lois', 'meg', 'chris']);

$split = ['male' => 0, 'female' => 0, 'unknown' => 0];
foreach ($batch->results as $prediction) {
    $split[$prediction->gender ?? 'unknown']++;
}

// $split is the gender distribution of the list: ['male' => 2, 'female' => 2, 'unknown' => 0]
echo $batch->quota->remaining; // 24987
```

The client reads quota from the response. It is never cached on the client.

Construction
------------

[](#construction)

```
$client = new Client(
    apiKey: 'YOUR_API_KEY', // required
    timeout: 10.0,          // optional, seconds; default 10
);
```

The hosts and the User-Agent are hardcoded. They are not options. The API key is required: constructing the client with an empty or blank key raises `ValidationError`. One API key works across all three services.

genderize
---------

[](#genderize)

Single name returns a result with the prediction fields and a quota.

```
$result = $client->genderize('peter');
$result->gender;          // "male", "female", or null
$result->probability;     // 1.0
$result->count;           // 1352696
$result->quota->remaining; // 24987
```

Batch (up to 10 names) returns results in input order plus one quota. Aggregate the predictions into a distribution rather than labeling any one name.

```
$batch = $client->genderizeBatch(['peter', 'lois', 'meg']);

$female = array_filter($batch->results, fn ($p) => $p->gender === 'female');
$femaleShare = count($female) / count($batch->results); // share of the list predicted female
```

agify
-----

[](#agify)

```
$result = $client->agify('michael');
$result->age;   // 57 or null
$result->count; // 311558
```

Batch into an age distribution across a list.

```
$batch = $client->agifyBatch(['michael', 'matthew', 'jane']);

$ages = array_filter(array_map(fn ($p) => $p->age, $batch->results), fn ($a) => $a !== null);
$mean = $ages === [] ? null : array_sum($ages) / count($ages); // mean predicted age of the list
```

nationalize
-----------

[](#nationalize)

```
$result = $client->nationalize('nguyen');
$result->country[0]->countryId;    // "VN"
$result->country[0]->probability;  // 0.891132
```

Batch into a nationality mix across a list.

```
$batch = $client->nationalizeBatch(['nguyen', 'smith', 'garcia']);

$mix = [];
foreach ($batch->results as $prediction) {
    $top = $prediction->country[0] ?? null;
    if ($top !== null) {
        $mix[$top->countryId] = ($mix[$top->countryId] ?? 0) + 1;
    }
}
// $mix is the top-country breakdown of the list
```

country\_id
-----------

[](#country_id)

`genderize` and `agify` accept an optional ISO 3166-1 alpha-2 `country_id` to scope the prediction. `nationalize` does not take one. The API echoes the value back uppercase.

```
$result = $client->genderize('kim', 'US');
$result->countryId; // "US"

$batch = $client->agifyBatch(['kim', 'andrea'], 'US');
```

Quota
-----

[](#quota)

Every result and every raised error carries a `Quota` read from the response headers.

FieldMeaning`limit`names allowed in the current window`remaining`names left in the current window`reset`seconds until the window resets```
$batch->quota->limit;
$batch->quota->remaining;
$batch->quota->reset;
```

Errors
------

[](#errors)

Every error extends `Demografix\Exceptions\DemografixException`, which carries `status`, the passthrough `message`, and a nullable `quota`.

ExceptionStatusMeaning`AuthError`401API key missing or invalid`SubscriptionError`402subscription expired or inactive`ValidationError`422invalid parameter; also raised client-side when a batch exceeds 10 names`RateLimitError`429quota exhausted; `quota` is always populated`TransportError`—network failure, timeout, or non-JSON body`DemografixException`other non-2xxbase typeA batch of more than 10 names raises `ValidationError` before any HTTP call.

`RateLimitError` reports when the window resets. Read `quota->reset` to back off.

```
use Demografix\Exceptions\RateLimitError;

try {
    $batch = $client->agifyBatch($names);
} catch (RateLimitError $e) {
    sleep($e->quota->reset);
    $batch = $client->agifyBatch($names);
}
```

Methods
-------

[](#methods)

MethodReturnscountry\_id`genderize(string $name, ?string $countryId = null)``GenderizeResult`yes`genderizeBatch(array $names, ?string $countryId = null)``Batch` of `GenderizePrediction`yes`agify(string $name, ?string $countryId = null)``AgifyResult`yes`agifyBatch(array $names, ?string $countryId = null)``Batch` of `AgifyPrediction`yes`nationalize(string $name)``NationalizeResult`no`nationalizeBatch(array $names)``Batch` of `NationalizePrediction`noEach single result exposes the prediction fields directly and a `quota`. Each `Batch` exposes `results` and one `quota`.

API keys
--------

[](#api-keys)

An API key is required. Creating one is free and includes 2,500 requests per month. Generate a key in your dashboard at [genderize.io](https://genderize.io), [agify.io](https://agify.io), or [nationalize.io](https://nationalize.io). One key works across all three services. Full reference: .

Tests
-----

[](#tests)

```
composer install
composer test
```

Tests inject a fake `Transport`, so they run without network access.

License
-------

[](#license)

MIT. See [LICENSE](LICENSE).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2242472?v=4)[Casper Strømgren](/maintainers/Stroemgren)[@Stroemgren](https://github.com/Stroemgren)

---

Top Contributors

[![Stroemgren](https://avatars.githubusercontent.com/u/2242472?v=4)](https://github.com/Stroemgren "Stroemgren (3 commits)")

---

Tags

gendernamesgenderizeagenationalityagifynationalizedemografix

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/demografix-demografix/health.svg)

```
[![Health](https://phpackages.com/badges/demografix-demografix/health.svg)](https://phpackages.com/packages/demografix-demografix)
```

###  Alternatives

[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
